mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Merge options -f and -ff into -f
This commit is contained in:
@@ -8,7 +8,10 @@ def match_arguments(arguments):
|
||||
for track in arguments.tracks:
|
||||
if track == "-":
|
||||
for line in sys.stdin:
|
||||
command_line.helpers.download_track(line, arguments)
|
||||
command_line.helpers.download_track(
|
||||
line,
|
||||
arguments
|
||||
)
|
||||
else:
|
||||
command_line.helpers.download_track(track, arguments)
|
||||
elif arguments.list:
|
||||
|
||||
@@ -136,12 +136,6 @@ def get_arguments(argv=None, to_merge=True):
|
||||
choices={"ffmpeg", "avconv", "null"},
|
||||
help="use this encoder for conversion",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--directory",
|
||||
default=os.path.abspath(config["directory"]),
|
||||
help="path to directory where downloaded tracks will be stored in",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--overwrite",
|
||||
default=config["overwrite"],
|
||||
@@ -175,11 +169,11 @@ def get_arguments(argv=None, to_merge=True):
|
||||
help="write tracks from Spotify playlist, album, etc. to this file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-ff",
|
||||
"--file-format",
|
||||
default=config["file-format"],
|
||||
help="file format to save the downloaded track with, each tag "
|
||||
"is surrounded by curly braces. Possible formats: "
|
||||
"-f",
|
||||
"--output-file",
|
||||
default=config["output-file"],
|
||||
help="path where to write the downloaded track to, special tags "
|
||||
"are to be surrounded by curly braces. Possible tags: "
|
||||
# "{}".format([spotdl.util.formats[x] for x in spotdl.util.formats]),
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -192,8 +186,8 @@ def get_arguments(argv=None, to_merge=True):
|
||||
"-sf",
|
||||
"--search-format",
|
||||
default=config["search-format"],
|
||||
help="search format to search for on YouTube, each tag "
|
||||
"is surrounded by curly braces. Possible formats: "
|
||||
help="search format to search for on YouTube, special tags "
|
||||
"are to be surrounded by curly braces. Possible tags: "
|
||||
# "{}".format([spotdl.util.formats[x] for x in spotdl.util.formats]),
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -289,10 +283,10 @@ def get_arguments(argv=None, to_merge=True):
|
||||
if parsed.config is not None and to_merge:
|
||||
parsed = override_config(parsed.config, parser)
|
||||
|
||||
return run_errands(parser, parsed)
|
||||
return run_errands(parser, parsed, config)
|
||||
|
||||
|
||||
def run_errands(parser, parsed):
|
||||
def run_errands(parser, parsed, config):
|
||||
if (parsed.list
|
||||
and not mimetypes.MimeTypes().guess_type(parsed.list)[0] == "text/plain"
|
||||
):
|
||||
@@ -334,12 +328,23 @@ def run_errands(parser, parsed):
|
||||
setattr(parsed, "tracks", parsed.song)
|
||||
del parsed.song
|
||||
|
||||
if parsed.file_format == "-" and parsed.no_metadata is False:
|
||||
if parsed.output_file == "-" and parsed.no_metadata is False:
|
||||
# log.warn(
|
||||
# "Cannot write metadata when target file is STDOUT. Pass "
|
||||
# "--no-metadata explicitly to hide this warning."
|
||||
# )
|
||||
parsed.no_metadata = True
|
||||
elif os.path.isdir(parsed.output_file):
|
||||
adjusted_output_file = os.path.join(
|
||||
parsed.output_file,
|
||||
config["output-file"]
|
||||
)
|
||||
# log.warn(
|
||||
# "Specified output file is a directory. Will write the filename as in
|
||||
# "default file format. Pass --output-file={} to hide this warning".format(
|
||||
# adjusted_output_file
|
||||
# )
|
||||
parsed.output_file = adjusted_output_file
|
||||
|
||||
parsed.log_level = log_leveller(parsed.log_level)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from spotdl.metadata.providers import ProviderYouTube
|
||||
from spotdl.metadata.providers import YouTubeSearch
|
||||
from spotdl.metadata.embedders import EmbedderDefault
|
||||
from spotdl.metadata.exceptions import SpotifyMetadataNotFoundError
|
||||
import spotdl.metadata
|
||||
|
||||
from spotdl.encode.encoders import EncoderFFmpeg
|
||||
from spotdl.encode.encoders import EncoderAvconv
|
||||
@@ -46,17 +47,16 @@ def search_metadata(track, search_format="{artist} - {track-name} lyrics", manua
|
||||
if spotdl.util.is_spotify(track):
|
||||
spotify = ProviderSpotify()
|
||||
spotify_metadata = spotify.from_url(track)
|
||||
lyric_query = spotdl.util.format_string(
|
||||
lyric_query = spotdl.metadata.format_string(
|
||||
"{artist} - {track-name}",
|
||||
spotify_metadata,
|
||||
)
|
||||
search_query = spotdl.util.format_string(search_format, spotify_metadata)
|
||||
search_query = spotdl.metadata.format_string(search_format, spotify_metadata)
|
||||
youtube_urls = youtube_searcher.search(search_query)
|
||||
if not youtube_urls:
|
||||
# raise NoYouTubeVideoError(
|
||||
# 'No videos found for the search query: "{}"'.format(search_query)
|
||||
# )
|
||||
return
|
||||
raise NoYouTubeVideoError(
|
||||
'No videos found for the search query: "{}"'.format(search_query)
|
||||
)
|
||||
if manual:
|
||||
pass
|
||||
else:
|
||||
@@ -69,7 +69,7 @@ def search_metadata(track, search_format="{artist} - {track-name} lyrics", manua
|
||||
|
||||
elif spotdl.util.is_youtube(track):
|
||||
metadata = youtube.from_url(track)
|
||||
lyric_query = spotdl.util.format_string(
|
||||
lyric_query = spotdl.metadata.format_string(
|
||||
"{artist} - {track-name}",
|
||||
metadata,
|
||||
)
|
||||
@@ -107,11 +107,14 @@ def search_metadata(track, search_format="{artist} - {track-name} lyrics", manua
|
||||
|
||||
|
||||
def download_track(track, arguments):
|
||||
track_splits = track.split(":")
|
||||
if len(track_splits) == 2:
|
||||
youtube_track, spotify_track = track_splits
|
||||
metadata = search_metadata(track, search_format=arguments.search_format)
|
||||
log_fmt = spotdl.util.format_string(
|
||||
arguments.file_format,
|
||||
log_fmt = spotdl.metadata.format_string(
|
||||
arguments.output_file,
|
||||
metadata,
|
||||
output_extension=arguments.output_ext
|
||||
output_extension=arguments.output_ext,
|
||||
)
|
||||
# log.info(log_fmt)
|
||||
download_track_from_metadata(metadata, arguments)
|
||||
@@ -119,7 +122,6 @@ def download_track(track, arguments):
|
||||
|
||||
def download_track_from_metadata(metadata, arguments):
|
||||
# TODO: Add `-m` flag
|
||||
|
||||
track = Track(metadata, cache_albumart=(not arguments.no_metadata))
|
||||
print(metadata["name"])
|
||||
|
||||
@@ -139,11 +141,15 @@ def download_track_from_metadata(metadata, arguments):
|
||||
else:
|
||||
output_extension = arguments.output_ext
|
||||
|
||||
filename = spotdl.util.format_string(
|
||||
arguments.file_format,
|
||||
filename = spotdl.metadata.format_string(
|
||||
arguments.output_file,
|
||||
metadata,
|
||||
output_extension=output_extension
|
||||
output_extension=output_extension,
|
||||
sanitizer=lambda s: spotdl.util.sanitize(
|
||||
s, spaces_to_underscores=arguments.no_spaces
|
||||
)
|
||||
)
|
||||
print(filename)
|
||||
# log.info(filename)
|
||||
|
||||
to_skip = arguments.dry_run
|
||||
|
||||
Reference in New Issue
Block a user