From ed182d79f6c10e2def5611d6f2a007de074c890e Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Fri, 10 Sep 2021 22:55:15 -0700 Subject: [PATCH] main --- ytdl_subscribe/main.py | 14 ++++++++------ ytdl_subscribe/subscriptions.py | 17 ++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ytdl_subscribe/main.py b/ytdl_subscribe/main.py index d84d142e..475ca515 100644 --- a/ytdl_subscribe/main.py +++ b/ytdl_subscribe/main.py @@ -5,17 +5,19 @@ parser = argparse.ArgumentParser( description="YoutubeDL-Subscribe: Download and organize your favorite media easily." ) parser.add_argument( - "-c", "--config", - metavar='CONFIGPATH', + "-c", + "--config", + metavar="CONFIGPATH", type=str, help="path to the config yaml, uses subscriptions.yaml if not provided", default="subscriptions.yaml", ) parser.add_argument( - "-s", "--subscriptions", - metavar='SUB', - nargs='+', - help='specific subscriptions to download, downloads all if not provided' + "-s", + "--subscriptions", + metavar="SUB", + nargs="+", + help="specific subscriptions to download, downloads all if not provided", ) diff --git a/ytdl_subscribe/subscriptions.py b/ytdl_subscribe/subscriptions.py index 3da46004..84d778eb 100644 --- a/ytdl_subscribe/subscriptions.py +++ b/ytdl_subscribe/subscriptions.py @@ -199,15 +199,12 @@ class SoundcloudSubscription(Subscription): tracks = [] if self.options.get("download_strategy") == "albums_then_tracks": - track_ytdl_opts = { - "download_archive": self.WORKING_DIRECTORY - + "/ytdl-download-archive.txt", - } - # Get the album tracks first, but do not download. Unfortunately we cannot use download_archive for - # this be + # Get the album info first, but do not download. This tells us which track ids belong + # to an album. Unfortunately we cannot use download_archive or info.json for this with ytdl.YoutubeDL(self.ytdl_opts) as ytd: info = ytd.extract_info(base_url + "/albums", download=False) + # For each album, parse each entry in the album album_entries = [self.parse_album_entry(a) for a in info["entries"]] for album_entry in album_entries: tracks += [ @@ -216,9 +213,15 @@ class SoundcloudSubscription(Subscription): if not self.is_entry_skippable(e) ] + # Download the tracks now, and use download_archive to cache + track_ytdl_opts = { + "download_archive": self.WORKING_DIRECTORY + + "/ytdl-download-archive.txt", + } with ytdl.YoutubeDL(dict(self.ytdl_opts, **track_ytdl_opts)) as ytd: - # Get the rest of the tracks that are part of the album tracks info = ytd.extract_info(base_url + "/tracks") + + # Skip parsing entries that have already been parsed when parsing albums album_track_ids = [t["id"] for t in tracks] tracks += [ self.parse_entry(e)