diff options
author | Aaditya Dhruv <[email protected]> | 2025-05-02 00:02:47 -0500 |
---|---|---|
committer | Aaditya Dhruv <[email protected]> | 2025-05-02 00:02:47 -0500 |
commit | 2de88ab1a3222a2e3f35e64e227e302d58139471 (patch) | |
tree | 0c6d1225b48f8060b7f7f4b3e2fc0680cc6dc3e9 | |
parent | db772695aacbd09935ddc8b3f0ff9a8766e7f2cb (diff) |
Add appropriate error handling
-rw-r--r-- | yt_music_scraper/main.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/yt_music_scraper/main.py b/yt_music_scraper/main.py index f7a7d09..0a0ec72 100644 --- a/yt_music_scraper/main.py +++ b/yt_music_scraper/main.py @@ -26,6 +26,22 @@ def vid_info(data): logger.info(json.dumps(data['album'] if 'album' in data else "N/A", indent=4)) return data['album'] if 'album' in data else "N/A" +ydl_opts2 = { + 'format': 'bestaudio/best', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'flac', + 'preferredquality': 'best', + }, + {'key': 'FFmpegMetadata'}, + {'key': 'EmbedThumbnail'}], + 'writethumbnail': True, + 'embedthumbnail': True, + 'add_metadata': True, + 'logger': logger, + 'outtmpl': '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s', +} + ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ @@ -37,6 +53,7 @@ ydl_opts = { {'key': 'EmbedThumbnail'}], 'writethumbnail': True, 'embedthumbnail': True, + 'ignoreerrors': True, 'add_metadata': True, 'logger': logger, 'outtmpl': '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s', @@ -44,8 +61,13 @@ ydl_opts = { def download_album(album_id): - data = yt.download(album_id) - return data + yt = YoutubeDL(ydl_opts2) + try: + data = yt.download(album_id) + return data + except: + logger.info(f"Could not process {album_id}") + return {} if __name__ == "__main__": @@ -62,9 +84,10 @@ if __name__ == "__main__": if data: albums = set() for datum in data["entries"]: - logger.debug(json.dumps(datum, indent=4)) - albums.add(vid_info(datum)) - logger.info(f"ALBUM NAME: {vid_info(datum)}") + if datum: + logger.debug(json.dumps(datum, indent=4)) + albums.add(vid_info(datum)) + logger.info(f"ALBUM NAME: {vid_info(datum)}") logger.info(f"albums: {albums}") re = re.compile("OLAK.*") |