From 67657723caa90bcabbbff7cf0187fd34de0107c6 Mon Sep 17 00:00:00 2001 From: Nicholas George Date: Tue, 22 Jun 2021 05:18:23 -0500 Subject: [PATCH 1/2] Add support for multiple -u arguments. --- streamrip/cli.py | 1 + streamrip/core.py | 67 ++++++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/streamrip/cli.py b/streamrip/cli.py index 1a3b907..51ca3cf 100644 --- a/streamrip/cli.py +++ b/streamrip/cli.py @@ -31,6 +31,7 @@ if not os.path.isdir(CACHE_DIR): "--urls", metavar="URLS", help="Url from Qobuz, Tidal, SoundCloud, or Deezer", + multiple=True, ) @click.option( "-q", diff --git a/streamrip/core.py b/streamrip/core.py index a3da94f..3c6cf80 100644 --- a/streamrip/core.py +++ b/streamrip/core.py @@ -111,44 +111,45 @@ class MusicDL(list): else: self.db = [] - def handle_urls(self, url: str): - """Download a url. + def handle_urls(self, urls): + for url in urls: + """Download a url. - :param url: - :type url: str - :raises InvalidSourceError - :raises ParsingError - """ - # youtube is handled by youtube-dl, so much of the - # processing is not necessary - youtube_urls = self.youtube_url_parse.findall(url) - if youtube_urls != []: - self.extend(YoutubeVideo(u) for u in youtube_urls) + :param url: + :type url: str + :raises InvalidSourceError + :raises ParsingError + """ + # youtube is handled by youtube-dl, so much of the + # processing is not necessary + youtube_urls = self.youtube_url_parse.findall(url) + if youtube_urls != []: + self.extend(YoutubeVideo(u) for u in youtube_urls) - parsed = self.parse_urls(url) - if not parsed and len(self) == 0: - if "last.fm" in url: - message = ( - f"For last.fm urls, use the {click.style('lastfm', fg='yellow')} " - f"command. See {click.style('rip lastfm --help', fg='yellow')}." - ) - else: - message = url + parsed = self.parse_urls(url) + if not parsed and len(self) == 0: + if "last.fm" in url: + message = ( + f"For last.fm urls, use the {click.style('lastfm', fg='yellow')} " + f"command. See {click.style('rip lastfm --help', fg='yellow')}." + ) + else: + message = url - raise ParsingError(message) + raise ParsingError(message) - for source, url_type, item_id in parsed: - if item_id in self.db: - logger.info( - f"ID {item_id} already downloaded, use --no-db to override." - ) - click.secho( - f"ID {item_id} already downloaded, use --no-db to override.", - fg="magenta", - ) - continue + for source, url_type, item_id in parsed: + if item_id in self.db: + logger.info( + f"ID {item_id} already downloaded, use --no-db to override." + ) + click.secho( + f"ID {item_id} already downloaded, use --no-db to override.", + fg="magenta", + ) + continue - self.handle_item(source, url_type, item_id) + self.handle_item(source, url_type, item_id) def handle_item(self, source: str, media_type: str, item_id: str): """Get info and parse into a Media object. From a40bfd8374168090fd5354cfad175db188be86f4 Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Tue, 22 Jun 2021 14:17:18 -0700 Subject: [PATCH 2/2] Join urls --- streamrip/core.py | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/streamrip/core.py b/streamrip/core.py index 3c6cf80..2a1ba9a 100644 --- a/streamrip/core.py +++ b/streamrip/core.py @@ -112,44 +112,44 @@ class MusicDL(list): self.db = [] def handle_urls(self, urls): - for url in urls: - """Download a url. + """Download a url. - :param url: - :type url: str - :raises InvalidSourceError - :raises ParsingError - """ - # youtube is handled by youtube-dl, so much of the - # processing is not necessary - youtube_urls = self.youtube_url_parse.findall(url) - if youtube_urls != []: - self.extend(YoutubeVideo(u) for u in youtube_urls) + :param url: + :type url: str + :raises InvalidSourceError + :raises ParsingError + """ + url = ' '.join(urls) + # youtube is handled by youtube-dl, so much of the + # processing is not necessary + youtube_urls = self.youtube_url_parse.findall(url) + if youtube_urls != []: + self.extend(YoutubeVideo(u) for u in youtube_urls) - parsed = self.parse_urls(url) - if not parsed and len(self) == 0: - if "last.fm" in url: - message = ( - f"For last.fm urls, use the {click.style('lastfm', fg='yellow')} " - f"command. See {click.style('rip lastfm --help', fg='yellow')}." - ) - else: - message = url + parsed = self.parse_urls(url) + if not parsed and len(self) == 0: + if "last.fm" in url: + message = ( + f"For last.fm urls, use the {click.style('lastfm', fg='yellow')} " + f"command. See {click.style('rip lastfm --help', fg='yellow')}." + ) + else: + message = url - raise ParsingError(message) + raise ParsingError(message) - for source, url_type, item_id in parsed: - if item_id in self.db: - logger.info( - f"ID {item_id} already downloaded, use --no-db to override." - ) - click.secho( - f"ID {item_id} already downloaded, use --no-db to override.", - fg="magenta", - ) - continue + for source, url_type, item_id in parsed: + if item_id in self.db: + logger.info( + f"ID {item_id} already downloaded, use --no-db to override." + ) + click.secho( + f"ID {item_id} already downloaded, use --no-db to override.", + fg="magenta", + ) + continue - self.handle_item(source, url_type, item_id) + self.handle_item(source, url_type, item_id) def handle_item(self, source: str, media_type: str, item_id: str): """Get info and parse into a Media object.