Merge pull request #91 from reduxionist/fix/use-absolute-path-to-download-dirs

Use absolute paths for download directories
This commit is contained in:
Logykk 2021-10-24 21:44:01 +13:00 committed by GitHub
commit 3c094e6436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -1,3 +1,4 @@
import os
from typing import Optional from typing import Optional
from librespot.audio.decoders import VorbisOnlyAudioQuality from librespot.audio.decoders import VorbisOnlyAudioQuality
@ -49,10 +50,11 @@ def download_episode(episode_id) -> None:
episode_id = EpisodeId.from_base62(episode_id) episode_id = EpisodeId.from_base62(episode_id)
stream = ZSpotify.get_content_stream(episode_id, ZSpotify.DOWNLOAD_QUALITY) stream = ZSpotify.get_content_stream(episode_id, ZSpotify.DOWNLOAD_QUALITY)
create_download_directory(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths) download_directory = os.path.dirname(__file__) + ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths
create_download_directory(download_directory)
total_size = stream.input_stream.size total_size = stream.input_stream.size
with open(ZSpotify.get_config(ROOT_PODCAST_PATH) + extra_paths + filename + MusicFormat.OGG.value, with open(download_directory + filename + MusicFormat.OGG.value,
'wb') as file, tqdm( 'wb') as file, tqdm(
desc=filename, desc=filename,
total=total_size, total=total_size,
@ -65,6 +67,4 @@ 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 + '.ogg') # extra_paths + filename + '.ogg')
# related functions that do stuff with the spotify API

View File

@ -53,6 +53,7 @@ def get_song_info(song_id) -> tuple[list[str], str, str, Any, Any, Any, Any, Any
# noinspection PyBroadException # noinspection PyBroadException
def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='', disable_progressbar=False) -> None: def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='', disable_progressbar=False) -> None:
""" Downloads raw song audio from Spotify """ """ Downloads raw song audio from Spotify """
download_directory = os.path.join(os.path.dirname(__file__), ZSpotify.get_config(ROOT_PATH), extra_paths)
try: try:
(artists, album_name, name, image_url, release_year, disc_number, (artists, album_name, name, image_url, release_year, disc_number,
track_number, scraped_song_id, is_playable) = get_song_info(track_id) track_number, scraped_song_id, is_playable) = get_song_info(track_id)
@ -63,11 +64,11 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
) else f'{prefix_value} - {song_name}' ) else f'{prefix_value} - {song_name}'
if ZSpotify.get_config(SPLIT_ALBUM_DISCS): if ZSpotify.get_config(SPLIT_ALBUM_DISCS):
filename = os.path.join(ZSpotify.get_config(ROOT_PATH), extra_paths, 'Disc ' + str( filename = os.path.join(download_directory, f'Disc {disc_number}',
disc_number) + '/' + song_name + '.' + ZSpotify.get_config(DOWNLOAD_FORMAT)) f'{song_name}.{ZSpotify.get_config(DOWNLOAD_FORMAT)}')
else: else:
filename = os.path.join(ZSpotify.get_config(ROOT_PATH), extra_paths, filename = os.path.join(download_directory,
song_name + '.' + ZSpotify.get_config(DOWNLOAD_FORMAT)) f'{song_name}.{ZSpotify.get_config(DOWNLOAD_FORMAT)}')
except Exception: except Exception:
print('### SKIPPING SONG - FAILED TO QUERY METADATA ###') print('### SKIPPING SONG - FAILED TO QUERY METADATA ###')
else: else:
@ -84,7 +85,7 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
track_id = scraped_song_id track_id = scraped_song_id
track_id = TrackId.from_base62(track_id) track_id = TrackId.from_base62(track_id)
stream = ZSpotify.get_content_stream(track_id, ZSpotify.DOWNLOAD_QUALITY) stream = ZSpotify.get_content_stream(track_id, ZSpotify.DOWNLOAD_QUALITY)
create_download_directory(ZSpotify.get_config(ROOT_PATH) + extra_paths) create_download_directory(download_directory)
total_size = stream.input_stream.size total_size = stream.input_stream.size
with open(filename, 'wb') as file, tqdm( with open(filename, 'wb') as file, tqdm(
@ -102,7 +103,7 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
if ZSpotify.get_config(DOWNLOAD_FORMAT) == 'mp3': 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)
set_music_thumbnail(filename, image_url) set_music_thumbnail(filename, image_url)
if not ZSpotify.get_config(OVERRIDE_AUTO_WAIT): if not ZSpotify.get_config(OVERRIDE_AUTO_WAIT):