mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-26 09:53:17 +01:00
Replaced filename string sanitization
This commit is contained in:
parent
b991c29d6b
commit
0dd2802ba2
@ -2,7 +2,7 @@ from tqdm import tqdm
|
||||
|
||||
from const import ITEMS, ARTISTS, NAME, ID
|
||||
from track import download_track
|
||||
from utils import sanitize_data, fix_filename
|
||||
from utils import fix_filename
|
||||
from zspotify import ZSpotify
|
||||
|
||||
ALBUM_URL = 'https://api.spotify.com/v1/albums'
|
||||
@ -28,7 +28,7 @@ def get_album_tracks(album_id):
|
||||
def get_album_name(album_id):
|
||||
""" Returns album name """
|
||||
resp = ZSpotify.invoke_url(f'{ALBUM_URL}/{album_id}')
|
||||
return resp[ARTISTS][0][NAME], sanitize_data(resp[NAME])
|
||||
return resp[ARTISTS][0][NAME], fix_filename(resp[NAME])
|
||||
|
||||
|
||||
def get_artist_albums(artist_id):
|
||||
|
@ -7,7 +7,7 @@ from const import TRACK, NAME, ID, ARTIST, ARTISTS, ITEMS, TRACKS, EXPLICIT, ALB
|
||||
from playlist import get_playlist_songs, get_playlist_info, download_from_user_playlist, download_playlist
|
||||
from podcast import download_episode, get_show_episodes
|
||||
from track import download_track, get_saved_tracks
|
||||
from utils import sanitize_data, splash, split_input, regex_input_for_urls
|
||||
from utils import fix_filename, splash, split_input, regex_input_for_urls
|
||||
from zspotify import ZSpotify
|
||||
|
||||
SEARCH_URL = 'https://api.spotify.com/v1/search'
|
||||
@ -45,7 +45,7 @@ def client(args) -> None:
|
||||
name, _ = get_playlist_info(playlist_id)
|
||||
for song in playlist_songs:
|
||||
download_track(song[TRACK][ID],
|
||||
sanitize_data(name) + '/')
|
||||
fix_filename(name) + '/')
|
||||
print('\n')
|
||||
elif episode_id is not None:
|
||||
download_episode(episode_id)
|
||||
@ -83,7 +83,7 @@ def client(args) -> None:
|
||||
playlist_songs = get_playlist_songs(playlist_id)
|
||||
name, _ = get_playlist_info(playlist_id)
|
||||
for song in playlist_songs:
|
||||
download_track(song[TRACK][ID], sanitize_data(name) + '/')
|
||||
download_track(song[TRACK][ID], fix_filename(name) + '/')
|
||||
print('\n')
|
||||
elif episode_id is not None:
|
||||
download_episode(episode_id)
|
||||
|
@ -1,5 +1,3 @@
|
||||
SANITIZE = ('\\', '/', ':', '*', '?', '\'', '<', '>', '"')
|
||||
|
||||
SAVED_TRACKS_URL = 'https://api.spotify.com/v1/me/tracks'
|
||||
|
||||
TRACKS_URL = 'https://api.spotify.com/v1/tracks'
|
||||
|
@ -2,7 +2,7 @@ from tqdm import tqdm
|
||||
|
||||
from const import ITEMS, ID, TRACK, NAME
|
||||
from track import download_track
|
||||
from utils import sanitize_data
|
||||
from utils import fix_filename
|
||||
from zspotify import ZSpotify
|
||||
|
||||
MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists'
|
||||
@ -54,7 +54,7 @@ def download_playlist(playlist):
|
||||
p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True)
|
||||
enum = 1
|
||||
for song in p_bar:
|
||||
download_track(song[TRACK][ID], sanitize_data(playlist[NAME].strip()) + '/',
|
||||
download_track(song[TRACK][ID], fix_filename(playlist[NAME].strip()) + '/',
|
||||
prefix=True, prefix_value=str(enum) ,disable_progressbar=True)
|
||||
p_bar.set_description(song[TRACK][NAME])
|
||||
enum += 1
|
||||
|
@ -7,7 +7,7 @@ from tqdm import tqdm
|
||||
|
||||
from const import (CHUNK_SIZE, ERROR, ID, ITEMS, NAME, ROOT_PODCAST_PATH, SHOW,
|
||||
SKIP_EXISTING_FILES)
|
||||
from utils import create_download_directory, sanitize_data
|
||||
from utils import create_download_directory, fix_filename
|
||||
from zspotify import ZSpotify
|
||||
|
||||
EPISODE_INFO_URL = 'https://api.spotify.com/v1/episodes'
|
||||
@ -18,7 +18,7 @@ def get_episode_info(episode_id_str) -> Tuple[Optional[str], Optional[str]]:
|
||||
info = ZSpotify.invoke_url(f'{EPISODE_INFO_URL}/{episode_id_str}')
|
||||
if ERROR in info:
|
||||
return None, None
|
||||
return sanitize_data(info[SHOW][NAME]), sanitize_data(info[NAME])
|
||||
return fix_filename(info[SHOW][NAME]), fix_filename(info[NAME])
|
||||
|
||||
|
||||
def get_show_episodes(show_id_str) -> list:
|
||||
|
@ -11,7 +11,7 @@ from tqdm import tqdm
|
||||
from const import TRACKS, ALBUM, NAME, ITEMS, DISC_NUMBER, TRACK_NUMBER, IS_PLAYABLE, ARTISTS, IMAGES, URL, \
|
||||
RELEASE_DATE, ID, TRACKS_URL, SAVED_TRACKS_URL, SPLIT_ALBUM_DISCS, ROOT_PATH, DOWNLOAD_FORMAT, CHUNK_SIZE, \
|
||||
SKIP_EXISTING_FILES, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT, BITRATE, CODEC_MAP, EXT_MAP, DOWNLOAD_REAL_TIME
|
||||
from utils import sanitize_data, set_audio_tags, set_music_thumbnail, create_download_directory
|
||||
from utils import fix_filename, set_audio_tags, set_music_thumbnail, create_download_directory
|
||||
from zspotify import ZSpotify
|
||||
|
||||
|
||||
@ -38,9 +38,9 @@ def get_song_info(song_id) -> Tuple[List[str], str, str, Any, Any, Any, Any, Any
|
||||
|
||||
artists = []
|
||||
for data in info[TRACKS][0][ARTISTS]:
|
||||
artists.append(sanitize_data(data[NAME]))
|
||||
album_name = sanitize_data(info[TRACKS][0][ALBUM][NAME])
|
||||
name = sanitize_data(info[TRACKS][0][NAME])
|
||||
artists.append(data[NAME])
|
||||
album_name = info[TRACKS][0][ALBUM][NAME]
|
||||
name = info[TRACKS][0][NAME]
|
||||
image_url = info[TRACKS][0][ALBUM][IMAGES][0][URL]
|
||||
release_year = info[TRACKS][0][ALBUM][RELEASE_DATE].split('-')[0]
|
||||
disc_number = info[TRACKS][0][DISC_NUMBER]
|
||||
@ -66,7 +66,7 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
||||
download_directory = os.path.join(os.path.dirname(
|
||||
__file__), ZSpotify.get_config(ROOT_PATH), extra_paths)
|
||||
|
||||
song_name = artists[0] + ' - ' + name
|
||||
song_name = fix_filename(artists[0]) + ' - ' + fix_filename(name)
|
||||
if prefix:
|
||||
song_name = f'{prefix_value.zfill(2)} - {song_name}' if prefix_value.isdigit(
|
||||
) else f'{prefix_value} - {song_name}'
|
||||
|
@ -60,13 +60,6 @@ def clear() -> None:
|
||||
os.system('clear')
|
||||
|
||||
|
||||
def sanitize_data(value) -> str:
|
||||
""" Returns given string with problematic removed """
|
||||
for pattern in SANITIZE:
|
||||
value = value.replace(pattern, '')
|
||||
return value.replace('|', '-')
|
||||
|
||||
|
||||
def set_audio_tags(filename, artists, name, album_name, release_year, disc_number, track_number) -> None:
|
||||
""" sets music_tag metadata """
|
||||
tags = music_tag.load_file(filename)
|
||||
|
Loading…
Reference in New Issue
Block a user