simplified audio formats

This commit is contained in:
logykk 2021-10-24 18:24:54 +13:00
parent c41fc10bc2
commit 27a2ecfb03
6 changed files with 10 additions and 19 deletions

View File

@ -84,8 +84,6 @@ SKIP_EXISTING_FILES = 'SKIP_EXISTING_FILES'
DOWNLOAD_FORMAT = 'DOWNLOAD_FORMAT' DOWNLOAD_FORMAT = 'DOWNLOAD_FORMAT'
RAW_AUDIO_AS_IS = 'RAW_AUDIO_AS_IS'
FORCE_PREMIUM = 'FORCE_PREMIUM' FORCE_PREMIUM = 'FORCE_PREMIUM'
ANTI_BAN_WAIT_TIME = 'ANTI_BAN_WAIT_TIME' ANTI_BAN_WAIT_TIME = 'ANTI_BAN_WAIT_TIME'

View File

@ -52,7 +52,7 @@ def download_episode(episode_id) -> None:
create_download_directory(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths) create_download_directory(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths)
total_size = stream.input_stream.size 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( 'wb') as file, tqdm(
desc=filename, desc=filename,
total=total_size, total=total_size,
@ -65,6 +65,6 @@ def download_episode(episode_id) -> None:
stream.input_stream.stream().read(ZSpotify.get_config(CHUNK_SIZE)))) stream.input_stream.stream().read(ZSpotify.get_config(CHUNK_SIZE))))
# convert_audio_format(ROOT_PODCAST_PATH + # convert_audio_format(ROOT_PODCAST_PATH +
# extra_paths + filename + '.wav') # extra_paths + filename + '.ogg')
# related functions that do stuff with the spotify API # related functions that do stuff with the spotify API

View File

@ -9,7 +9,7 @@ from tqdm import tqdm
from const import TRACKS, ALBUM, NAME, ITEMS, DISC_NUMBER, TRACK_NUMBER, IS_PLAYABLE, ARTISTS, IMAGES, URL, \ 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, \ 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, \ from utils import sanitize_data, set_audio_tags, set_music_thumbnail, create_download_directory, \
MusicFormat MusicFormat
from zspotify import ZSpotify from zspotify import ZSpotify
@ -99,7 +99,7 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
p_bar.update(file.write( p_bar.update(file.write(
stream.input_stream.stream().read(ZSpotify.get_config(CHUNK_SIZE)))) 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) convert_audio_format(filename)
set_audio_tags(filename, artists, name, album_name, set_audio_tags(filename, artists, name, album_name,
release_year, disc_number, track_number) release_year, disc_number, track_number)
@ -107,15 +107,16 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
if not ZSpotify.get_config(OVERRIDE_AUTO_WAIT): if not ZSpotify.get_config(OVERRIDE_AUTO_WAIT):
time.sleep(ZSpotify.get_config(ANTI_BAN_WAIT_TIME)) time.sleep(ZSpotify.get_config(ANTI_BAN_WAIT_TIME))
except Exception: except Exception as e:
print('### SKIPPING:', song_name, print('### SKIPPING:', song_name,
'(GENERAL DOWNLOAD ERROR) ###') '(GENERAL DOWNLOAD ERROR) ###')
print(e)
if os.path.exists(filename): if os.path.exists(filename):
os.remove(filename) os.remove(filename)
def convert_audio_format(filename) -> None: 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() + ' ###') # print('### CONVERTING TO ' + MUSIC_FORMAT.upper() + ' ###')
raw_audio = AudioSegment.from_file(filename, format=MusicFormat.OGG.value, raw_audio = AudioSegment.from_file(filename, format=MusicFormat.OGG.value,
frame_rate=44100, channels=2, sample_width=2) frame_rate=44100, channels=2, sample_width=2)

View File

@ -14,7 +14,6 @@ from const import SANITIZE, ARTIST, TRACKTITLE, ALBUM, YEAR, DISCNUMBER, TRACKNU
class MusicFormat(str, Enum): class MusicFormat(str, Enum):
MP3 = 'mp3', MP3 = 'mp3',
OGG = 'ogg', OGG = 'ogg',
WAV = 'wav'
def create_download_directory(download_path: str) -> None: def create_download_directory(download_path: str) -> None:

View File

@ -17,7 +17,7 @@ from librespot.audio.decoders import VorbisOnlyAudioQuality
from librespot.core import Session from librespot.core import Session
from const import CREDENTIALS_JSON, TYPE, \ 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 PLAYLIST_READ_PRIVATE
from utils import MusicFormat from utils import MusicFormat
@ -29,7 +29,6 @@ class ZSpotify:
def __init__(self): def __init__(self):
ZSpotify.load_config() ZSpotify.load_config()
ZSpotify.check_raw()
ZSpotify.login() ZSpotify.login()
@classmethod @classmethod
@ -62,11 +61,6 @@ class ZSpotify:
def get_config(cls, key) -> Any: def get_config(cls, key) -> Any:
return cls.CONFIG.get(key) 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 @classmethod
def get_content_stream(cls, content_id, quality): def get_content_stream(cls, content_id, quality):
return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None) return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None)

View File

@ -3,7 +3,6 @@
"ROOT_PODCAST_PATH": "../ZSpotify Podcasts/", "ROOT_PODCAST_PATH": "../ZSpotify Podcasts/",
"SKIP_EXISTING_FILES": true, "SKIP_EXISTING_FILES": true,
"DOWNLOAD_FORMAT": "mp3", "DOWNLOAD_FORMAT": "mp3",
"RAW_AUDIO_AS_IS": false,
"FORCE_PREMIUM": false, "FORCE_PREMIUM": false,
"ANTI_BAN_WAIT_TIME": 1, "ANTI_BAN_WAIT_TIME": 1,
"OVERRIDE_AUTO_WAIT": false, "OVERRIDE_AUTO_WAIT": false,