mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-12-02 04:23:57 +01:00
updated folder name
This commit is contained in:
parent
441da8eef0
commit
dab823d09e
@ -1,3 +1,4 @@
|
|||||||
|
"""It's provides functions for downloading the albums"""
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from const import ITEMS, ARTISTS, NAME, ID
|
from const import ITEMS, ARTISTS, NAME, ID
|
||||||
@ -16,7 +17,8 @@ def get_album_tracks(album_id):
|
|||||||
limit = 50
|
limit = 50
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
resp = ZSpotify.invoke_url_with_params(f'{ALBUM_URL}/{album_id}/tracks', limit=limit, offset=offset)
|
resp = ZSpotify.invoke_url_with_params(f'{ALBUM_URL}/{album_id}/tracks',
|
||||||
|
limit=limit, offset=offset)
|
||||||
offset += limit
|
offset += limit
|
||||||
songs.extend(resp[ITEMS])
|
songs.extend(resp[ITEMS])
|
||||||
if len(resp[ITEMS]) < limit:
|
if len(resp[ITEMS]) < limit:
|
||||||
@ -42,9 +44,10 @@ def download_album(album):
|
|||||||
""" Downloads songs from an album """
|
""" Downloads songs from an album """
|
||||||
artist, album_name = get_album_name(album)
|
artist, album_name = get_album_name(album)
|
||||||
tracks = get_album_tracks(album)
|
tracks = get_album_tracks(album)
|
||||||
for n, track in tqdm(enumerate(tracks, start=1), unit_scale=True, unit='Song', total=len(tracks)):
|
for album_number, track in tqdm(enumerate(tracks, start=1), unit_scale=True,
|
||||||
|
unit='Song', total=len(tracks)):
|
||||||
download_track(track[ID], f'{artist}/{album_name}',
|
download_track(track[ID], f'{artist}/{album_name}',
|
||||||
prefix=True, prefix_value=str(n), disable_progressbar=True)
|
prefix=True, prefix_value=str(album_number), disable_progressbar=True)
|
||||||
|
|
||||||
|
|
||||||
def download_artist_albums(artist):
|
def download_artist_albums(artist):
|
@ -1,3 +1,4 @@
|
|||||||
|
"""Entrypoint of ZSpotify app. It provides functions for searching"""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from librespot.audio.decoders import AudioQuality
|
from librespot.audio.decoders import AudioQuality
|
||||||
@ -5,7 +6,7 @@ from tabulate import tabulate
|
|||||||
|
|
||||||
from album import download_album, download_artist_albums
|
from album import download_album, download_artist_albums
|
||||||
from const import TRACK, NAME, ID, ARTISTS, ITEMS, TRACKS, EXPLICIT, ALBUMS, OWNER, \
|
from const import TRACK, NAME, ID, ARTISTS, ITEMS, TRACKS, EXPLICIT, ALBUMS, OWNER, \
|
||||||
PLAYLISTS, DISPLAY_NAME
|
PLAYLISTS, DISPLAY_NAME, LIMIT, OFFSET, TYPE, S_NO, ALBUM
|
||||||
from playlist import download_from_user_playlist, download_playlist, \
|
from playlist import download_from_user_playlist, download_playlist, \
|
||||||
download_playlist_with_id
|
download_playlist_with_id
|
||||||
from podcast import download_episode, get_show_episodes
|
from podcast import download_episode, get_show_episodes
|
||||||
@ -40,6 +41,9 @@ def client() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def process_args_input():
|
def process_args_input():
|
||||||
|
"""
|
||||||
|
process the sys args
|
||||||
|
"""
|
||||||
if sys.argv[1] == '-p' or sys.argv[1] == '--playlist':
|
if sys.argv[1] == '-p' or sys.argv[1] == '--playlist':
|
||||||
download_from_user_playlist()
|
download_from_user_playlist()
|
||||||
elif sys.argv[1] == '-ls' or sys.argv[1] == '--liked-songs':
|
elif sys.argv[1] == '-ls' or sys.argv[1] == '--liked-songs':
|
||||||
@ -54,6 +58,11 @@ def process_args_input():
|
|||||||
|
|
||||||
|
|
||||||
def process_url_input(url, call_search=False):
|
def process_url_input(url, call_search=False):
|
||||||
|
"""
|
||||||
|
process the input and calls appropriate download method
|
||||||
|
@param url: input url
|
||||||
|
@param call_search: boolean variable to notify calling search method
|
||||||
|
"""
|
||||||
track_id, album_id, playlist_id, episode_id, show_id, artist_id = regex_input_for_urls(url)
|
track_id, album_id, playlist_id, episode_id, show_id, artist_id = regex_input_for_urls(url)
|
||||||
|
|
||||||
if track_id:
|
if track_id:
|
||||||
@ -75,7 +84,7 @@ def process_url_input(url, call_search=False):
|
|||||||
|
|
||||||
def search(search_term):
|
def search(search_term):
|
||||||
""" Searches Spotify's API for relevant data """
|
""" Searches Spotify's API for relevant data """
|
||||||
params = {'limit': '10', 'offset': '0', 'q': search_term, 'type': 'track,album,artist,playlist'}
|
params = {LIMIT: '10', OFFSET: '0', 'q': search_term, TYPE: 'track,album,artist,playlist'}
|
||||||
resp = ZSpotify.invoke_url_with_params(SEARCH_URL, **params)
|
resp = ZSpotify.invoke_url_with_params(SEARCH_URL, **params)
|
||||||
|
|
||||||
total_tracks = total_albums = total_artists = 0
|
total_tracks = total_albums = total_artists = 0
|
||||||
@ -90,7 +99,8 @@ def search(search_term):
|
|||||||
','.join([artist[NAME] for artist in track[ARTISTS]])])
|
','.join([artist[NAME] for artist in track[ARTISTS]])])
|
||||||
counter += 1
|
counter += 1
|
||||||
total_tracks = counter - 1
|
total_tracks = counter - 1
|
||||||
print(tabulate(track_data, headers=['S.NO', 'Name', 'Artists'], tablefmt='pretty'))
|
print(tabulate(track_data, headers=[S_NO, NAME.title(), ARTISTS.title()],
|
||||||
|
tablefmt='pretty'))
|
||||||
print('\n')
|
print('\n')
|
||||||
|
|
||||||
albums = resp[ALBUMS][ITEMS]
|
albums = resp[ALBUMS][ITEMS]
|
||||||
@ -98,10 +108,12 @@ def search(search_term):
|
|||||||
print('### ALBUMS ###')
|
print('### ALBUMS ###')
|
||||||
album_data = []
|
album_data = []
|
||||||
for album in albums:
|
for album in albums:
|
||||||
album_data.append([counter, album[NAME], ','.join([artist[NAME] for artist in album[ARTISTS]])])
|
album_data.append([counter, album[NAME], ','.join([artist[NAME]
|
||||||
|
for artist in album[ARTISTS]])])
|
||||||
counter += 1
|
counter += 1
|
||||||
total_albums = counter - total_tracks - 1
|
total_albums = counter - total_tracks - 1
|
||||||
print(tabulate(album_data, headers=['S.NO', 'Album', 'Artists'], tablefmt='pretty'))
|
print(tabulate(album_data, headers=[S_NO, ALBUM.title(), ARTISTS.title()],
|
||||||
|
tablefmt='pretty'))
|
||||||
print('\n')
|
print('\n')
|
||||||
|
|
||||||
artists = resp[ARTISTS][ITEMS]
|
artists = resp[ARTISTS][ITEMS]
|
||||||
@ -112,7 +124,7 @@ def search(search_term):
|
|||||||
artist_data.append([counter, artist[NAME]])
|
artist_data.append([counter, artist[NAME]])
|
||||||
counter += 1
|
counter += 1
|
||||||
total_artists = counter - total_tracks - total_albums - 1
|
total_artists = counter - total_tracks - total_albums - 1
|
||||||
print(tabulate(artist_data, headers=['S.NO', 'Name'], tablefmt='pretty'))
|
print(tabulate(artist_data, headers=[S_NO, NAME.title()], tablefmt='pretty'))
|
||||||
print('\n')
|
print('\n')
|
||||||
|
|
||||||
playlists = resp[PLAYLISTS][ITEMS]
|
playlists = resp[PLAYLISTS][ITEMS]
|
||||||
@ -121,13 +133,16 @@ def search(search_term):
|
|||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
playlist_data.append([counter, playlist[NAME], playlist[OWNER][DISPLAY_NAME]])
|
playlist_data.append([counter, playlist[NAME], playlist[OWNER][DISPLAY_NAME]])
|
||||||
counter += 1
|
counter += 1
|
||||||
print(tabulate(playlist_data, headers=['S.NO', 'Name', 'Owner'], tablefmt='pretty'))
|
print(tabulate(playlist_data, headers=[S_NO, NAME.title(), OWNER.title()], tablefmt='pretty'))
|
||||||
print('\n')
|
print('\n')
|
||||||
perform_action(tracks, albums, playlists, artists, total_tracks, total_albums, total_artists)
|
perform_action(tracks, albums, playlists, artists, total_tracks, total_albums, total_artists)
|
||||||
|
|
||||||
|
|
||||||
def perform_action(tracks: list, albums: list, playlists: list, artists: list, total_tracks: int, total_albums: int,
|
def perform_action(tracks: list, albums: list, playlists: list, artists: list,
|
||||||
total_artists: int):
|
total_tracks: int, total_albums: int, total_artists: int):
|
||||||
|
"""
|
||||||
|
process and downloads the user selection
|
||||||
|
"""
|
||||||
if len(tracks) + len(albums) + len(playlists) == 0:
|
if len(tracks) + len(albums) + len(playlists) == 0:
|
||||||
print('NO RESULTS FOUND - EXITING...')
|
print('NO RESULTS FOUND - EXITING...')
|
||||||
else:
|
else:
|
@ -1,3 +1,4 @@
|
|||||||
|
""" provides commonly used string across different modules"""
|
||||||
SANITIZE = ('\\', '/', ':', '*', '?', '\'', '<', '>', '"')
|
SANITIZE = ('\\', '/', ':', '*', '?', '\'', '<', '>', '"')
|
||||||
|
|
||||||
SAVED_TRACKS_URL = 'https://api.spotify.com/v1/me/tracks'
|
SAVED_TRACKS_URL = 'https://api.spotify.com/v1/me/tracks'
|
||||||
@ -107,3 +108,5 @@ PLAYLIST_ID = 'PlaylistID'
|
|||||||
ALBUM_ID = 'AlbumID'
|
ALBUM_ID = 'AlbumID'
|
||||||
|
|
||||||
TRACK_ID = 'TrackID'
|
TRACK_ID = 'TrackID'
|
||||||
|
|
||||||
|
S_NO = 'S.NO'
|
@ -32,7 +32,8 @@ def get_playlist_songs(playlist_id):
|
|||||||
limit = 100
|
limit = 100
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
resp = ZSpotify.invoke_url_with_params(f'{PLAYLISTS_URL}/{playlist_id}/tracks', limit=limit, offset=offset)
|
resp = ZSpotify.invoke_url_with_params(f'{PLAYLISTS_URL}/{playlist_id}/tracks',
|
||||||
|
limit=limit, offset=offset)
|
||||||
offset += limit
|
offset += limit
|
||||||
songs.extend(resp[ITEMS])
|
songs.extend(resp[ITEMS])
|
||||||
if len(resp[ITEMS]) < limit:
|
if len(resp[ITEMS]) < limit:
|
||||||
@ -52,7 +53,8 @@ def download_playlist_with_id(playlist_id):
|
|||||||
playlist_songs = [song for song in get_playlist_songs(playlist_id) if song[TRACK][ID]]
|
playlist_songs = [song for song in get_playlist_songs(playlist_id) if song[TRACK][ID]]
|
||||||
p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True)
|
p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True)
|
||||||
for song in p_bar:
|
for song in p_bar:
|
||||||
download_track(song[TRACK][ID], sanitize_data(name.strip()) + '/', disable_progressbar=True, create_m3u_file=True)
|
download_track(song[TRACK][ID], sanitize_data(name.strip()) + '/', disable_progressbar=True,
|
||||||
|
create_m3u_file=True)
|
||||||
p_bar.set_description(song[TRACK][NAME])
|
p_bar.set_description(song[TRACK][NAME])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user