mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-26 09:53:17 +01:00
simplified audio formats
This commit is contained in:
parent
c41fc10bc2
commit
27a2ecfb03
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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,7 +99,7 @@ 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)
|
||||
@ -107,15 +107,16 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
||||
|
||||
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)
|
||||
|
@ -14,7 +14,6 @@ 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:
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user