mirror of https://github.com/afkcodes/zspotify.git
Added SONG_ARCHIVE config value
This commit is contained in:
parent
a35d46e6ae
commit
0adaa20d59
|
@ -18,6 +18,7 @@ SPLIT_ALBUM_DISCS = 'SPLIT_ALBUM_DISCS'
|
|||
DOWNLOAD_REAL_TIME = 'DOWNLOAD_REAL_TIME'
|
||||
LANGUAGE = 'LANGUAGE'
|
||||
BITRATE = 'BITRATE'
|
||||
SONG_ARCHIVE = 'SONG_ARCHIVE'
|
||||
|
||||
CONFIG_VALUES = {
|
||||
ROOT_PATH: { 'default': '../ZSpotify Music/', 'type': str, 'arg': '--root-path' },
|
||||
|
@ -33,6 +34,7 @@ CONFIG_VALUES = {
|
|||
DOWNLOAD_REAL_TIME: { 'default': 'False', 'type': bool, 'arg': '--download-real-time' },
|
||||
LANGUAGE: { 'default': 'en', 'type': str, 'arg': '--language' },
|
||||
BITRATE: { 'default': '', 'type': str, 'arg': '--bitrate' },
|
||||
SONG_ARCHIVE: { 'default': '.song_archive', 'type': str, 'arg': '--song-archive' },
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,7 +87,7 @@ class Config:
|
|||
return r
|
||||
|
||||
@classmethod
|
||||
def parse_arg_value(cls, key, value) -> Any:
|
||||
def parse_arg_value(cls, key: str, value: Any) -> Any:
|
||||
if type(value) == CONFIG_VALUES[key]['type']:
|
||||
return value
|
||||
if CONFIG_VALUES[key]['type'] == str:
|
||||
|
@ -101,7 +103,7 @@ class Config:
|
|||
raise ValueError("Unknown Type: " + value)
|
||||
|
||||
@classmethod
|
||||
def get(cls, key) -> Any:
|
||||
def get(cls, key: str) -> Any:
|
||||
return cls.Values.get(key)
|
||||
|
||||
@classmethod
|
||||
|
@ -155,3 +157,7 @@ class Config:
|
|||
@classmethod
|
||||
def get_bitrate(cls) -> str:
|
||||
return cls.get(BITRATE)
|
||||
|
||||
@classmethod
|
||||
def get_song_archive(cls) -> str:
|
||||
return cls.get(SONG_ARCHIVE)
|
||||
|
|
|
@ -91,10 +91,9 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
|||
filename = os.path.join(
|
||||
download_directory, f'{song_name}.{EXT_MAP.get(ZSpotify.CONFIG.get_download_format().lower())}')
|
||||
|
||||
archive_directory = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path())
|
||||
check_name = os.path.isfile(filename) and os.path.getsize(filename)
|
||||
check_id = scraped_song_id in get_directory_song_ids(download_directory)
|
||||
check_all_time = scraped_song_id in get_previously_downloaded(scraped_song_id, archive_directory)
|
||||
check_all_time = scraped_song_id in get_previously_downloaded()
|
||||
|
||||
# a song with the same name is installed
|
||||
if not check_id and check_name:
|
||||
|
@ -153,7 +152,7 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
|||
|
||||
# add song id to archive file
|
||||
if ZSpotify.CONFIG.get_skip_previously_downloaded():
|
||||
add_to_archive(scraped_song_id, archive_directory)
|
||||
add_to_archive(scraped_song_id, artists[0], name)
|
||||
# add song id to download directory's .song_ids file
|
||||
if not check_id:
|
||||
add_to_directory_song_ids(download_directory, scraped_song_id)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import datetime
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
|
@ -11,6 +12,8 @@ import requests
|
|||
|
||||
from const import ARTIST, TRACKTITLE, ALBUM, YEAR, DISCNUMBER, TRACKNUMBER, ARTWORK, \
|
||||
WINDOWS_SYSTEM, ALBUMARTIST
|
||||
from zspotify import ZSpotify
|
||||
|
||||
|
||||
class MusicFormat(str, Enum):
|
||||
MP3 = 'mp3',
|
||||
|
@ -27,29 +30,29 @@ def create_download_directory(download_path: str) -> None:
|
|||
with open(hidden_file_path, 'w', encoding='utf-8') as f:
|
||||
pass
|
||||
|
||||
def get_previously_downloaded(song_id: str, archive_directory: str) -> List[str]:
|
||||
def get_previously_downloaded() -> List[str]:
|
||||
""" Returns list of all time downloaded songs """
|
||||
|
||||
ids = []
|
||||
archive_path = os.path.join(archive_directory, '.song_archive')
|
||||
archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive())
|
||||
|
||||
if os.path.exists(archive_path):
|
||||
with open(archive_path, 'r', encoding='utf-8') as f:
|
||||
ids = [line.strip() for line in f.readlines()]
|
||||
ids = [line.strip().split('\t')[0] for line in f.readlines()]
|
||||
|
||||
return ids
|
||||
|
||||
def add_to_archive(song_id: str, archive_directory: str) -> None:
|
||||
def add_to_archive(song_id: str, author_name: str, song_name: str) -> None:
|
||||
""" Adds song id to all time installed songs archive """
|
||||
|
||||
archive_path = os.path.join(archive_directory, '.song_archive')
|
||||
archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive())
|
||||
|
||||
if os.path.exists(archive_path):
|
||||
with open(archive_path, 'a', encoding='utf-8') as f:
|
||||
f.write(f'{song_id}\n')
|
||||
f.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\n')
|
||||
else:
|
||||
with open(archive_path, 'w', encoding='utf-8') as f:
|
||||
f.write(f'{song_id}\n')
|
||||
f.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\n')
|
||||
|
||||
def get_directory_song_ids(download_path: str) -> List[str]:
|
||||
""" Gets song ids of songs in directory """
|
||||
|
|
Loading…
Reference in New Issue