mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2025-07-01 15:23:15 +00:00
Merge pull request #190 from yiannisha/file_download
Added argument to download from file with urls fixes#172
This commit is contained in:
commit
d80dff2faf
@ -28,6 +28,9 @@ if __name__ == '__main__':
|
|||||||
dest='search_spotify',
|
dest='search_spotify',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Loads search prompt to find then download a specific track, album or playlist')
|
help='Loads search prompt to find then download a specific track, album or playlist')
|
||||||
|
group.add_argument('-d', '--download',
|
||||||
|
type=str,
|
||||||
|
help='Downloads tracks, playlists and albums from the URLs written in the file passed.')
|
||||||
|
|
||||||
parser.set_defaults(func=client)
|
parser.set_defaults(func=client)
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from librespot.audio.decoders import AudioQuality
|
from librespot.audio.decoders import AudioQuality
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
import os
|
||||||
|
|
||||||
from album import download_album, download_artist_albums
|
from album import download_album, download_artist_albums
|
||||||
from const import TRACK, NAME, ID, ARTIST, ARTISTS, ITEMS, TRACKS, EXPLICIT, ALBUM, ALBUMS, \
|
from const import TRACK, NAME, ID, ARTIST, ARTISTS, ITEMS, TRACKS, EXPLICIT, ALBUM, ALBUMS, \
|
||||||
@ -29,29 +30,20 @@ def client(args) -> None:
|
|||||||
print('[ DETECTED FREE ACCOUNT - USING HIGH QUALITY ]\n\n')
|
print('[ DETECTED FREE ACCOUNT - USING HIGH QUALITY ]\n\n')
|
||||||
ZSpotify.DOWNLOAD_QUALITY = AudioQuality.HIGH
|
ZSpotify.DOWNLOAD_QUALITY = AudioQuality.HIGH
|
||||||
|
|
||||||
if args.urls:
|
if args.download:
|
||||||
for spotify_url in args.urls:
|
urls = []
|
||||||
track_id, album_id, playlist_id, episode_id, show_id, artist_id = regex_input_for_urls(
|
filename = args.download
|
||||||
spotify_url)
|
if os.path.exists(filename):
|
||||||
|
with open(filename, 'r', encoding='utf-8') as file:
|
||||||
|
urls.extend([line.strip() for line in file.readlines()])
|
||||||
|
|
||||||
if track_id is not None:
|
download_from_urls(urls)
|
||||||
download_track(track_id)
|
|
||||||
elif artist_id is not None:
|
else:
|
||||||
download_artist_albums(artist_id)
|
print(f'File {filename} not found.\n')
|
||||||
elif album_id is not None:
|
|
||||||
download_album(album_id)
|
if args.urls:
|
||||||
elif playlist_id is not None:
|
download_from_urls(args.urls)
|
||||||
playlist_songs = get_playlist_songs(playlist_id)
|
|
||||||
name, _ = get_playlist_info(playlist_id)
|
|
||||||
for song in playlist_songs:
|
|
||||||
download_track(song[TRACK][ID],
|
|
||||||
fix_filename(name) + '/')
|
|
||||||
print('\n')
|
|
||||||
elif episode_id is not None:
|
|
||||||
download_episode(episode_id)
|
|
||||||
elif show_id is not None:
|
|
||||||
for episode in get_show_episodes(show_id):
|
|
||||||
download_episode(episode)
|
|
||||||
|
|
||||||
if args.playlist:
|
if args.playlist:
|
||||||
download_from_user_playlist()
|
download_from_user_playlist()
|
||||||
@ -70,28 +62,43 @@ def client(args) -> None:
|
|||||||
while len(search_text) == 0:
|
while len(search_text) == 0:
|
||||||
search_text = input('Enter search or URL: ')
|
search_text = input('Enter search or URL: ')
|
||||||
|
|
||||||
|
if not download_from_urls([search_text]):
|
||||||
|
search(search_text)
|
||||||
|
|
||||||
|
def download_from_urls(urls: list[str]) -> bool:
|
||||||
|
""" Downloads from a list of spotify urls """
|
||||||
|
download = False
|
||||||
|
|
||||||
|
for spotify_url in urls:
|
||||||
track_id, album_id, playlist_id, episode_id, show_id, artist_id = regex_input_for_urls(
|
track_id, album_id, playlist_id, episode_id, show_id, artist_id = regex_input_for_urls(
|
||||||
search_text)
|
spotify_url)
|
||||||
|
|
||||||
if track_id is not None:
|
if track_id is not None:
|
||||||
|
download = True
|
||||||
download_track(track_id)
|
download_track(track_id)
|
||||||
elif artist_id is not None:
|
elif artist_id is not None:
|
||||||
|
download = True
|
||||||
download_artist_albums(artist_id)
|
download_artist_albums(artist_id)
|
||||||
elif album_id is not None:
|
elif album_id is not None:
|
||||||
|
download = True
|
||||||
download_album(album_id)
|
download_album(album_id)
|
||||||
elif playlist_id is not None:
|
elif playlist_id is not None:
|
||||||
|
download = True
|
||||||
playlist_songs = get_playlist_songs(playlist_id)
|
playlist_songs = get_playlist_songs(playlist_id)
|
||||||
name, _ = get_playlist_info(playlist_id)
|
name, _ = get_playlist_info(playlist_id)
|
||||||
for song in playlist_songs:
|
for song in playlist_songs:
|
||||||
download_track(song[TRACK][ID], fix_filename(name) + '/')
|
download_track(song[TRACK][ID],
|
||||||
|
fix_filename(name) + '/')
|
||||||
print('\n')
|
print('\n')
|
||||||
elif episode_id is not None:
|
elif episode_id is not None:
|
||||||
|
download = True
|
||||||
download_episode(episode_id)
|
download_episode(episode_id)
|
||||||
elif show_id is not None:
|
elif show_id is not None:
|
||||||
|
download = True
|
||||||
for episode in get_show_episodes(show_id):
|
for episode in get_show_episodes(show_id):
|
||||||
download_episode(episode)
|
download_episode(episode)
|
||||||
else:
|
|
||||||
search(search_text)
|
return download
|
||||||
|
|
||||||
|
|
||||||
def search(search_term):
|
def search(search_term):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user