2025-09-17 07:03:06 +09:00

75 lines
2.1 KiB
Python

# pip install requests requests-oauthlib
import sys
import os
import requests
from requests_oauthlib import OAuth1
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from dotenv import load_dotenv
load_dotenv(".env")
from lib.custom_logger import get_logger
logger = get_logger(level=10)
from providers.sns.api_sns_x import ApiSnsX
# from providers.sns.api_youtube import ApiYoutube
from providers.sns.api_youtube_downloader import ApiYoutubeDownloader
def example_get_tweet():
items = ApiSnsX.search_recent_tweets(
query="OpenAI lang:ja -is:retweet",
max_results=10
)
logger.info(f"Found {len(items.get('data', []))} tweets")
for tweet in items.get("data", []):
logger.info(f"- {tweet['id']}: {tweet['text']}")
# example_get_tweet()
# def example_get_youtube():
# client = ApiYoutube()
# カテゴリ一覧 の取得
# items = client.get_categories()
# logger.info(f"Found {len(items)} categories")
# for item in items:
# logger.info(f"- {item['id']}: {item['title']}")
# 人気動画の取得
# items = client.get_most_popular(
# region_code="JP",
# video_category_id="25",
# max_results=10,
# )
# logger.info(f"Found {len(items)} popular videos.")
# for item in items:
# logger.info(f"- {item['id']}: {item['snippet']['title']}")
# 動画の詳細情報を取得
# items = client.get_videos_by_ids(
# video_ids=["zXJ31wzT3Vo"],
# )
# for item in items:
# logger.info(f"- {item['id']}: {item['snippet']['title']}")
# 人気カテゴリを取得する
# items = client.rank_popular_categories(
# region_code="JP",
# )
# for item in items:
# logger.info(f"- {item}")
# example_get_youtube()
def example_youtube_downloader():
video_url = "https://www.youtube.com/watch?v=mnNwcWzc510"
client = ApiYoutubeDownloader()
info = client.download_audio(
video_url=video_url,
)
logger.info(f"Downloaded video info: {info}")
example_youtube_downloader()