mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
* Refactor spotdl.py; introduced classes * introduce CheckExists class * Move these classes to download.py * Fix refresh_token * Add a changelog entry
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from spotdl import __version__
|
|
from spotdl import const
|
|
from spotdl import handle
|
|
from spotdl import internals
|
|
from spotdl import spotify_tools
|
|
from spotdl import youtube_tools
|
|
from spotdl import downloader
|
|
from logzero import logger as log
|
|
import logzero
|
|
import sys
|
|
import platform
|
|
import pprint
|
|
|
|
|
|
def debug_sys_info():
|
|
log.debug("Python version: {}".format(sys.version))
|
|
log.debug("Platform: {}".format(platform.platform()))
|
|
log.debug(pprint.pformat(const.args.__dict__))
|
|
|
|
|
|
def match_args():
|
|
if const.args.song:
|
|
track_dl = downloader.Downloader(raw_song=const.args.song)
|
|
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 main():
|
|
const.args = handle.get_arguments()
|
|
|
|
if const.args.version:
|
|
print("spotdl {version}".format(version=__version__))
|
|
sys.exit()
|
|
|
|
internals.filter_path(const.args.folder)
|
|
youtube_tools.set_api_key()
|
|
|
|
logzero.setup_default_logger(formatter=const._formatter, level=const.args.log_level)
|
|
|
|
try:
|
|
match_args()
|
|
# actually we don't necessarily need this, but yeah...
|
|
# explicit is better than implicit!
|
|
sys.exit(0)
|
|
|
|
except KeyboardInterrupt as e:
|
|
log.exception(e)
|
|
sys.exit(3)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|