Merge pull request #209 from Mikescher/master-pr-006

return resolved paths from config.py
This commit is contained in:
Logykk 2021-11-26 19:54:12 +13:00 committed by GitHub
commit 7725cb01b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 14 deletions

View File

@ -131,11 +131,11 @@ class Config:
@classmethod @classmethod
def get_root_path(cls) -> str: def get_root_path(cls) -> str:
return cls.get(ROOT_PATH) return os.path.join(os.path.dirname(__file__), cls.get(ROOT_PATH))
@classmethod @classmethod
def get_root_podcast_path(cls) -> str: def get_root_podcast_path(cls) -> str:
return cls.get(ROOT_PODCAST_PATH) return os.path.join(os.path.dirname(__file__), cls.get(ROOT_PODCAST_PATH))
@classmethod @classmethod
def get_skip_existing_files(cls) -> bool: def get_skip_existing_files(cls) -> bool:
@ -183,11 +183,11 @@ class Config:
@classmethod @classmethod
def get_song_archive(cls) -> str: def get_song_archive(cls) -> str:
return cls.get(SONG_ARCHIVE) return os.path.join(ZSpotify.CONFIG.get_root_path(), cls.get(SONG_ARCHIVE))
@classmethod @classmethod
def get_credentials_location(cls) -> str: def get_credentials_location(cls) -> str:
return cls.get(CREDENTIALS_LOCATION) return os.path.join(os.getcwd(), cls.get(CREDENTIALS_LOCATION))
@classmethod @classmethod
def get_temp_download_dir(cls) -> str: def get_temp_download_dir(cls) -> str:

View File

@ -77,11 +77,7 @@ def download_episode(episode_id) -> None:
direct_download_url = ZSpotify.invoke_url( direct_download_url = ZSpotify.invoke_url(
'https://api-partner.spotify.com/pathfinder/v1/query?operationName=getEpisode&variables={"uri":"spotify:episode:' + episode_id + '"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"224ba0fd89fcfdfb3a15fa2d82a6112d3f4e2ac88fba5c6713de04d1b72cf482"}}')["data"]["episode"]["audio"]["items"][-1]["url"] 'https://api-partner.spotify.com/pathfinder/v1/query?operationName=getEpisode&variables={"uri":"spotify:episode:' + episode_id + '"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"224ba0fd89fcfdfb3a15fa2d82a6112d3f4e2ac88fba5c6713de04d1b72cf482"}}')["data"]["episode"]["audio"]["items"][-1]["url"]
download_directory = os.path.join( download_directory = os.path.join(ZSpotify.CONFIG.get_root_podcast_path(), extra_paths)
os.path.dirname(__file__),
ZSpotify.CONFIG.get_root_podcast_path(),
extra_paths,
)
download_directory = os.path.realpath(download_directory) download_directory = os.path.realpath(download_directory)
create_download_directory(download_directory) create_download_directory(download_directory)

View File

@ -103,7 +103,7 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=
output_template = output_template.replace("{track_id}", fix_filename(track_id)) output_template = output_template.replace("{track_id}", fix_filename(track_id))
output_template = output_template.replace("{ext}", ext) output_template = output_template.replace("{ext}", ext)
filename = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), output_template) filename = os.path.join(ZSpotify.CONFIG.get_root_path(), output_template)
filedir = os.path.dirname(filename) filedir = os.path.dirname(filename)
filename_temp = filename filename_temp = filename
@ -178,7 +178,7 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=
time_finished = time.time() time_finished = time.time()
Printer.print(PrintChannel.DOWNLOADS, f'### Downloaded "{song_name}" to "{os.path.relpath(filename, os.path.dirname(__file__))}" in {fmt_seconds(time_downloaded - time_start)} (plus {fmt_seconds(time_finished - time_downloaded)} converting) ###' + "\n") Printer.print(PrintChannel.DOWNLOADS, f'### Downloaded "{song_name}" to "{os.path.relpath(filename, ZSpotify.CONFIG.get_root_path())}" in {fmt_seconds(time_downloaded - time_start)} (plus {fmt_seconds(time_finished - time_downloaded)} converting) ###' + "\n")
# add song id to archive file # add song id to archive file
if ZSpotify.CONFIG.get_skip_previously_downloaded(): if ZSpotify.CONFIG.get_skip_previously_downloaded():

View File

@ -36,7 +36,7 @@ def get_previously_downloaded() -> List[str]:
""" Returns list of all time downloaded songs """ """ Returns list of all time downloaded songs """
ids = [] ids = []
archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive()) archive_path = ZSpotify.CONFIG.get_song_archive()
if os.path.exists(archive_path): if os.path.exists(archive_path):
with open(archive_path, 'r', encoding='utf-8') as f: with open(archive_path, 'r', encoding='utf-8') as f:
@ -48,7 +48,7 @@ def get_previously_downloaded() -> List[str]:
def add_to_archive(song_id: str, filename: str, author_name: str, song_name: str) -> None: def add_to_archive(song_id: str, filename: str, author_name: str, song_name: str) -> None:
""" Adds song id to all time installed songs archive """ """ Adds song id to all time installed songs archive """
archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive()) archive_path = ZSpotify.CONFIG.get_song_archive()
if os.path.exists(archive_path): if os.path.exists(archive_path):
with open(archive_path, 'a', encoding='utf-8') as file: with open(archive_path, 'a', encoding='utf-8') as file:

View File

@ -35,7 +35,7 @@ class ZSpotify:
def login(cls): def login(cls):
""" Authenticates with Spotify and saves credentials to a file """ """ Authenticates with Spotify and saves credentials to a file """
cred_location = os.path.join(os.getcwd(), Config.get_credentials_location()) cred_location = Config.get_credentials_location()
if os.path.isfile(cred_location): if os.path.isfile(cred_location):
try: try: