diff options
author | Aaditya Dhruv <[email protected]> | 2025-04-30 20:53:45 -0500 |
---|---|---|
committer | Aaditya Dhruv <[email protected]> | 2025-04-30 20:53:45 -0500 |
commit | a022d8a61ba9e51f39f57627f940098d1a4df968 (patch) | |
tree | c789249b5a05fb9c8e69fb14bcc8cfa8618a36d2 | |
parent | 902e319af901416cd06a53c29b881b64a112bc0c (diff) |
add main.py
-rw-r--r-- | yt_music_scraper/main.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/yt_music_scraper/main.py b/yt_music_scraper/main.py new file mode 100644 index 0000000..52e344f --- /dev/null +++ b/yt_music_scraper/main.py @@ -0,0 +1,49 @@ +from yt_dlp import YoutubeDL +import json +import argparse +import sys +import os +import logging +logging.basicConfig(stream=sys.stdout) +logger = logging.getLogger() +LOGLEVEL = os.environ.get('LOG_LEVEL', 'INFO').upper() +logger.setLevel(LOGLEVEL) +logger.debug("Starting...") + +def vid_info(data): + + logger.info(json.dumps(data['title'] if 'title' in data else "N/A", indent=4)) + logger.info(json.dumps(data['album'] if 'album' in data else "N/A", indent=4)) + logger.info(json.dumps(data['artists'] if 'artists' in data else "N/A", indent=4)) + return (data['album'] if 'album' in data else "N/A", data['artists'] if 'artists' in data else "N/A") + +ydl_opts = { + 'format': 'bestaudio/best', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'flac', + 'preferredquality': 'best', + }], + 'logger': logger, +} + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(prog="YT DLP Music downloader", description="Download all albums corresponding to songs in a playlist") + parser.add_argument("playlist") + + args = parser.parse_args() + + logger.debug("Create YT object...") + yt = YoutubeDL(ydl_opts) + data = yt.extract_info(args.playlist, download=False) + with open("data.json", "w") as f: + f.write(json.dumps(data, indent=4)) + i = 0 + if data: + albums = [] + for datum in data["entries"]: + logger.debug(json.dumps(datum, indent=4)) + logger.info(f"ALBUM NAME: {vid_info(datum)}") + |