From 7f1ece803487b8bd341bafb2e51ef9be113eaa51 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Tue, 12 Dec 2023 15:33:16 +0100 Subject: [PATCH] Podcast Import Script: Re-enable YouTube API --- .../workflows/publish-podcast-episodes.yml | 1 + scripts/podcast_feed_to_content.py | 21 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-podcast-episodes.yml b/.github/workflows/publish-podcast-episodes.yml index 661c73bf..a822b389 100644 --- a/.github/workflows/publish-podcast-episodes.yml +++ b/.github/workflows/publish-podcast-episodes.yml @@ -25,6 +25,7 @@ jobs: env: SPOTIFY_APP_CLIENT_ID: ${{ secrets.SPOTIFY_APP_CLIENT_ID }} SPOTIFY_APP_CLIENT_SECRET: ${{ secrets.SPOTIFY_APP_CLIENT_SECRET }} + YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }} - name: Run make update-redirects run: make update-redirects diff --git a/scripts/podcast_feed_to_content.py b/scripts/podcast_feed_to_content.py index c5903fb0..c34f4976 100644 --- a/scripts/podcast_feed_to_content.py +++ b/scripts/podcast_feed_to_content.py @@ -211,7 +211,6 @@ def sync_podcast_episodes(rss_feed, path_md_files, path_img_files, no_api_calls= feed_response.encoding = 'utf-8' # Check if we should run the API calls to external podcast platforms - #apple_podcast_content = {"results": []} apple_podcast_content = {} spotify_episodes = [] google_podcast_content = "" @@ -225,8 +224,8 @@ def sync_podcast_episodes(rss_feed, path_md_files, path_img_files, no_api_calls= apple_podcast_content = get_json_content_from_url(PODCAST_APPLE_URL) spotify_episodes = spotify_client.show_episodes(SPOTIFY_SHOW_ID, limit=50, offset=0, market="DE") google_podcast_content = get_raw_content_from_url(PODCAST_GOOGLE_URL) - #youtube_playlist_response = youtube_client.playlistItems.list(parts="snippet", maxResults=50, playlist_id=YOUTUBE_PLAYLIST_ID) - #youtube_playlist_items = youtube_playlist_response.items + youtube_playlist_response = youtube_client.playlistItems.list(parts="snippet", maxResults=50, playlist_id=YOUTUBE_PLAYLIST_ID) + youtube_playlist_items = youtube_playlist_response.items # Pagination and auth not respected. # Right now it works, because a) we don't make that much requests and @@ -709,13 +708,13 @@ def get_episode_link_from_google(content, title: str) -> str: spotify_client = create_spotify_client(SPOTIFY_APP_CLIENT_ID, SPOTIFY_APP_CLIENT_SECRET) # YouTube - #YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY') - #if not YOUTUBE_API_KEY: - # logging.error("Env var YOUTUBE_API_KEY is not set properly.") - # logging.error("Please double check and restart.") - # sys.exit(1) - #youtube_client = YoutubeClient(api_key=YOUTUBE_API_KEY) - - sync_podcast_episodes(PODCAST_RSS_FEED, f"{folder_prefix}{PATH_MARKDOWN_FILES}", f"{folder_prefix}{PATH_IMAGE_FILES}", no_api_calls=args.no_api_calls, spotify_client=spotify_client, youtube_client=None) + YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY') + if not YOUTUBE_API_KEY: + logging.error("Env var YOUTUBE_API_KEY is not set properly.") + logging.error("Please double check and restart.") + sys.exit(1) + youtube_client = YoutubeClient(api_key=YOUTUBE_API_KEY) + + sync_podcast_episodes(PODCAST_RSS_FEED, f"{folder_prefix}{PATH_MARKDOWN_FILES}", f"{folder_prefix}{PATH_IMAGE_FILES}", no_api_calls=args.no_api_calls, spotify_client=spotify_client, youtube_client=youtube_client) case "redirect": create_redirects(TOML_FILE, PATH_MARKDOWN_FILES, REDIRECT_PREFIX)