mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-17 16:45:13 -04:00
Added support for txt files as input
This commit is contained in:
parent
3182660338
commit
b3eb914e60
3 changed files with 18 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ secrets.py
|
||||||
dist
|
dist
|
||||||
build
|
build
|
||||||
test.py
|
test.py
|
||||||
|
/urls.txt
|
||||||
|
|
|
@ -21,6 +21,7 @@ if not os.path.isdir(CACHE_DIR):
|
||||||
@click.group(invoke_without_command=True)
|
@click.group(invoke_without_command=True)
|
||||||
@click.option("-c", "--convert", metavar="CODEC")
|
@click.option("-c", "--convert", metavar="CODEC")
|
||||||
@click.option("-u", "--urls", metavar="URLS")
|
@click.option("-u", "--urls", metavar="URLS")
|
||||||
|
@click.option("-t", "--text", metavar='PATH')
|
||||||
@click.option("-nd", "--no-db", is_flag=True)
|
@click.option("-nd", "--no-db", is_flag=True)
|
||||||
@click.option("--debug", is_flag=True)
|
@click.option("--debug", is_flag=True)
|
||||||
@click.option("--reset-config", is_flag=True)
|
@click.option("--reset-config", is_flag=True)
|
||||||
|
@ -52,6 +53,12 @@ def cli(ctx, **kwargs):
|
||||||
logger.debug(f"handling {kwargs['urls']}")
|
logger.debug(f"handling {kwargs['urls']}")
|
||||||
core.handle_urls(kwargs["urls"])
|
core.handle_urls(kwargs["urls"])
|
||||||
|
|
||||||
|
if os.path.isfile(kwargs['text']):
|
||||||
|
logger.debug(f"Handling {kwargs['text']}")
|
||||||
|
core.handle_txt(kwargs['text'])
|
||||||
|
elif kwargs['txt'] is not None:
|
||||||
|
click.secho(f"Text file {kwargs['text']} does not exist.")
|
||||||
|
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
core.download()
|
core.download()
|
||||||
|
|
||||||
|
|
|
@ -96,13 +96,13 @@ class MusicDL(list):
|
||||||
:raises InvalidSourceError
|
:raises InvalidSourceError
|
||||||
:raises ParsingError
|
:raises ParsingError
|
||||||
"""
|
"""
|
||||||
source, url_type, item_id = self.parse_urls(url)[0]
|
for source, url_type, item_id in self.parse_urls(url):
|
||||||
if item_id in self.db:
|
if item_id in self.db:
|
||||||
logger.info(f"{url} already downloaded, use --no-db to override.")
|
logger.info(f"{url} already downloaded, use --no-db to override.")
|
||||||
click.secho(f"{url} already downloaded, use --no-db to override.", fg='magenta')
|
click.secho(f"{url} already downloaded, use --no-db to override.", fg='magenta')
|
||||||
return
|
break
|
||||||
|
|
||||||
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):
|
def handle_item(self, source: str, media_type: str, item_id: str):
|
||||||
self.assert_creds(source)
|
self.assert_creds(source)
|
||||||
|
@ -138,6 +138,7 @@ class MusicDL(list):
|
||||||
else:
|
else:
|
||||||
item.download(**arguments)
|
item.download(**arguments)
|
||||||
|
|
||||||
|
self.db.add(item.id)
|
||||||
if self.config.session["conversion"]["enabled"]:
|
if self.config.session["conversion"]["enabled"]:
|
||||||
click.secho(
|
click.secho(
|
||||||
f"Converting {item!s} to {self.config.session['conversion']['codec']}",
|
f"Converting {item!s} to {self.config.session['conversion']['codec']}",
|
||||||
|
@ -193,13 +194,14 @@ class MusicDL(list):
|
||||||
:raises exceptions.ParsingError
|
:raises exceptions.ParsingError
|
||||||
"""
|
"""
|
||||||
parsed = self.url_parse.findall(url)
|
parsed = self.url_parse.findall(url)
|
||||||
|
logger.debug(f"Parsed urls: {parsed}")
|
||||||
|
|
||||||
if parsed != []:
|
if parsed != []:
|
||||||
return parsed
|
return parsed
|
||||||
|
|
||||||
raise ParsingError(f"Error parsing URL: `{url}`")
|
raise ParsingError(f"Error parsing URL: `{url}`")
|
||||||
|
|
||||||
def from_txt(self, filepath: Union[str, os.PathLike]):
|
def handle_txt(self, filepath: Union[str, os.PathLike]):
|
||||||
"""
|
"""
|
||||||
Handle a text file containing URLs. Lines starting with `#` are ignored.
|
Handle a text file containing URLs. Lines starting with `#` are ignored.
|
||||||
|
|
||||||
|
@ -209,11 +211,7 @@ class MusicDL(list):
|
||||||
:raises exceptions.ParsingError
|
:raises exceptions.ParsingError
|
||||||
"""
|
"""
|
||||||
with open(filepath) as txt:
|
with open(filepath) as txt:
|
||||||
lines = " ".join(
|
self.handle_urls(txt.read())
|
||||||
line for line in txt.readlines() if not line.strip().startswith("#")
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.parse_urls(lines)
|
|
||||||
|
|
||||||
def search(
|
def search(
|
||||||
self, source: str, query: str, media_type: str = "album", limit: int = 200
|
self, source: str, query: str, media_type: str = "album", limit: int = 200
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue