Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_single_download_with_youtube_api(self, title_fixture):
const.args.youtube_api_key = YT_API_KEY
youtube_tools.set_api_key()
assert title_fixture == EXPECTED_TITLE
def test_check_exists(metadata_fixture, filename_fixture, tmpdir):
expect_check = False
const.args.folder = str(tmpdir)
# prerequisites for determining filename
track_existence = downloader.CheckExists(filename_fixture, metadata_fixture)
check = track_existence.already_exists(TRACK_SEARCH)
assert check == expect_check
def test_check_exists(metadata_fixture, filename_fixture, tmpdir):
expect_check = False
const.args.folder = str(tmpdir)
# prerequisites for determining filename
track_existence = downloader.CheckExists(filename_fixture, metadata_fixture)
check = track_existence.already_exists(TRACK_SEARCH)
assert check == expect_check
def match_args():
if const.args.song:
for track in const.args.song:
track_dl = downloader.Downloader(raw_song=track)
track_dl.download_single()
elif const.args.list:
if const.args.write_m3u:
youtube_tools.generate_m3u(track_file=const.args.list)
else:
list_dl = downloader.ListDownloader(
tracks_file=const.args.list,
skip_file=const.args.skip,
write_successful_file=const.args.write_successful,
)
list_dl.download_list()
elif const.args.playlist:
spotify_tools.write_playlist(playlist_url=const.args.playlist)
elif const.args.album:
spotify_tools.write_album(album_url=const.args.album)
elif const.args.all_albums:
spotify_tools.write_all_albums_from_artist(artist_url=const.args.all_albums)
elif const.args.username:
spotify_tools.write_user_playlist(username=const.args.username)
def unconverted_filename(songname):
const.args.output_ext = const.args.input_ext
output_song = songname + const.args.output_ext
return output_song
def generate_token():
""" Generate the token. """
credentials = oauth2.SpotifyClientCredentials(
client_id=const.args.spotify_client_id,
client_secret=const.args.spotify_client_secret,
)
token = credentials.get_access_token()
return token
""" Check if the input song already exists in the given folder. """
log.debug(
"Cleaning any temp files and checking "
'if "{}" already exists'.format(self.filename)
)
songs = os.listdir(self.filepath)
self._remove_temp_files(songs)
for song in songs:
# check if a song with the same name is already present in the given folder
if self._match_filenames(song):
if internals.is_spotify(raw_song) and not self._has_metadata(song):
return False
log.warning('"{}" already exists'.format(song))
if const.args.overwrite == "prompt":
return self._prompt_song(song)
elif const.args.overwrite == "force":
return self._force_overwrite_song(song)
elif const.args.overwrite == "skip":
return self._skip_song(song)
return False
def debug_sys_info():
log.debug("Python version: {}".format(sys.version))
log.debug("Platform: {}".format(platform.platform()))
log.debug(pprint.pformat(const.args.__dict__))
k: sanitize_title(str(v), ok="'-_()[]{}") if slugification else str(v)
for k, v in format_tags.items()
}
# calculating total digits presnet in total_songs to prepare a zfill.
total_digits = 0 if total_songs == 0 else int(math.log10(total_songs)) + 1
for x in formats:
format_tag = "{" + formats[x] + "}"
# Making consistent track number by prepending zero
# on it according to number of digits in total songs
if format_tag == "{track_number}":
format_tags_sanitized[x] = format_tags_sanitized[x].zfill(total_digits)
string_format = string_format.replace(format_tag, format_tags_sanitized[x])
if const.args.no_spaces and not force_spaces:
string_format = string_format.replace(" ", "_")
return string_format