From 27a2ecfb032a770e76845e87205e37d891054358 Mon Sep 17 00:00:00 2001 From: logykk Date: Sun, 24 Oct 2021 18:24:54 +1300 Subject: [PATCH] simplified audio formats --- src/const.py | 2 -- src/podcast.py | 4 ++-- src/track.py | 11 ++++++----- src/utils.py | 3 +-- src/zspotify.py | 8 +------- zs_config.json | 1 - 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/const.py b/src/const.py index 8671d95e..0c9a8545 100644 --- a/src/const.py +++ b/src/const.py @@ -84,8 +84,6 @@ SKIP_EXISTING_FILES = 'SKIP_EXISTING_FILES' DOWNLOAD_FORMAT = 'DOWNLOAD_FORMAT' -RAW_AUDIO_AS_IS = 'RAW_AUDIO_AS_IS' - FORCE_PREMIUM = 'FORCE_PREMIUM' ANTI_BAN_WAIT_TIME = 'ANTI_BAN_WAIT_TIME' diff --git a/src/podcast.py b/src/podcast.py index 2b7b264e..ccd8a694 100644 --- a/src/podcast.py +++ b/src/podcast.py @@ -52,7 +52,7 @@ def download_episode(episode_id) -> None: create_download_directory(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths) total_size = stream.input_stream.size - with open(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths + filename + MusicFormat.WAV.value, + with open(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths + filename + MusicFormat.OGG.value, 'wb') as file, tqdm( desc=filename, total=total_size, @@ -65,6 +65,6 @@ def download_episode(episode_id) -> None: stream.input_stream.stream().read(ZSpotify.get_config(CHUNK_SIZE)))) # convert_audio_format(ROOT_PODCAST_PATH + - # extra_paths + filename + '.wav') + # extra_paths + filename + '.ogg') # related functions that do stuff with the spotify API diff --git a/src/track.py b/src/track.py index d9109b6d..dc148b0d 100644 --- a/src/track.py +++ b/src/track.py @@ -9,7 +9,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, RAW_AUDIO_AS_IS, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT + SKIP_EXISTING_FILES, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT from utils import sanitize_data, set_audio_tags, set_music_thumbnail, create_download_directory, \ MusicFormat from zspotify import ZSpotify @@ -99,23 +99,24 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='', p_bar.update(file.write( stream.input_stream.stream().read(ZSpotify.get_config(CHUNK_SIZE)))) - if not ZSpotify.get_config(RAW_AUDIO_AS_IS): + if ZSpotify.get_config(DOWNLOAD_FORMAT) == 'mp3': convert_audio_format(filename) set_audio_tags(filename, artists, name, album_name, - release_year, disc_number, track_number) + release_year, disc_number, track_number) set_music_thumbnail(filename, image_url) if not ZSpotify.get_config(OVERRIDE_AUTO_WAIT): time.sleep(ZSpotify.get_config(ANTI_BAN_WAIT_TIME)) - except Exception: + except Exception as e: print('### SKIPPING:', song_name, '(GENERAL DOWNLOAD ERROR) ###') + print(e) if os.path.exists(filename): os.remove(filename) def convert_audio_format(filename) -> None: - """ Converts raw audio into playable mp3 or ogg vorbis """ + """ Converts raw audio into playable mp3 """ # print('### CONVERTING TO ' + MUSIC_FORMAT.upper() + ' ###') raw_audio = AudioSegment.from_file(filename, format=MusicFormat.OGG.value, frame_rate=44100, channels=2, sample_width=2) diff --git a/src/utils.py b/src/utils.py index c601e525..3fd91612 100644 --- a/src/utils.py +++ b/src/utils.py @@ -14,8 +14,7 @@ from const import SANITIZE, ARTIST, TRACKTITLE, ALBUM, YEAR, DISCNUMBER, TRACKNU class MusicFormat(str, Enum): MP3 = 'mp3', OGG = 'ogg', - WAV = 'wav' - + def create_download_directory(download_path: str) -> None: os.makedirs(download_path, exist_ok=True) diff --git a/src/zspotify.py b/src/zspotify.py index 98aaa6fe..b692ff6c 100644 --- a/src/zspotify.py +++ b/src/zspotify.py @@ -17,7 +17,7 @@ from librespot.audio.decoders import VorbisOnlyAudioQuality from librespot.core import Session from const import CREDENTIALS_JSON, TYPE, \ - PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, CONFIG_FILE_PATH, FORCE_PREMIUM, RAW_AUDIO_AS_IS, \ + PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, CONFIG_FILE_PATH, FORCE_PREMIUM, \ PLAYLIST_READ_PRIVATE from utils import MusicFormat @@ -29,7 +29,6 @@ class ZSpotify: def __init__(self): ZSpotify.load_config() - ZSpotify.check_raw() ZSpotify.login() @classmethod @@ -62,11 +61,6 @@ class ZSpotify: def get_config(cls, key) -> Any: return cls.CONFIG.get(key) - @classmethod - def check_raw(cls) -> None: - if cls.get_config(RAW_AUDIO_AS_IS): - cls.DOWNLOAD_FORMAT = MusicFormat.WAV - @classmethod def get_content_stream(cls, content_id, quality): return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None) diff --git a/zs_config.json b/zs_config.json index 7daf8b54..b5dbb919 100644 --- a/zs_config.json +++ b/zs_config.json @@ -3,7 +3,6 @@ "ROOT_PODCAST_PATH": "../ZSpotify Podcasts/", "SKIP_EXISTING_FILES": true, "DOWNLOAD_FORMAT": "mp3", - "RAW_AUDIO_AS_IS": false, "FORCE_PREMIUM": false, "ANTI_BAN_WAIT_TIME": 1, "OVERRIDE_AUTO_WAIT": false,