mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-29 19:24:34 +01:00
Merge pull request #186 from yiannisha/fixes#161
Added global song archive fixes#161
This commit is contained in:
commit
4c9b9c2caa
@ -88,6 +88,8 @@ ROOT_PODCAST_PATH = 'ROOT_PODCAST_PATH'
|
|||||||
|
|
||||||
SKIP_EXISTING_FILES = 'SKIP_EXISTING_FILES'
|
SKIP_EXISTING_FILES = 'SKIP_EXISTING_FILES'
|
||||||
|
|
||||||
|
SKIP_PREVIOUSLY_DOWNLOADED = 'SKIP_PREVIOUSLY_DOWNLOADED'
|
||||||
|
|
||||||
DOWNLOAD_FORMAT = 'DOWNLOAD_FORMAT'
|
DOWNLOAD_FORMAT = 'DOWNLOAD_FORMAT'
|
||||||
|
|
||||||
FORCE_PREMIUM = 'FORCE_PREMIUM'
|
FORCE_PREMIUM = 'FORCE_PREMIUM'
|
||||||
@ -128,6 +130,7 @@ CONFIG_DEFAULT_SETTINGS = {
|
|||||||
'ROOT_PATH': '../ZSpotify Music/',
|
'ROOT_PATH': '../ZSpotify Music/',
|
||||||
'ROOT_PODCAST_PATH': '../ZSpotify Podcasts/',
|
'ROOT_PODCAST_PATH': '../ZSpotify Podcasts/',
|
||||||
'SKIP_EXISTING_FILES': True,
|
'SKIP_EXISTING_FILES': True,
|
||||||
|
'SKIP_PREVIOUSLY_DOWNLOADED': False,
|
||||||
'DOWNLOAD_FORMAT': 'ogg',
|
'DOWNLOAD_FORMAT': 'ogg',
|
||||||
'FORCE_PREMIUM': False,
|
'FORCE_PREMIUM': False,
|
||||||
'ANTI_BAN_WAIT_TIME': 1,
|
'ANTI_BAN_WAIT_TIME': 1,
|
||||||
|
@ -11,9 +11,10 @@ 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, TRACK_STATS_URL, SPLIT_ALBUM_DISCS, ROOT_PATH, DOWNLOAD_FORMAT, \
|
RELEASE_DATE, ID, TRACKS_URL, SAVED_TRACKS_URL, TRACK_STATS_URL, SPLIT_ALBUM_DISCS, ROOT_PATH, DOWNLOAD_FORMAT, \
|
||||||
CHUNK_SIZE, SKIP_EXISTING_FILES, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT, BITRATE, CODEC_MAP, EXT_MAP, DOWNLOAD_REAL_TIME
|
CHUNK_SIZE, SKIP_EXISTING_FILES, ANTI_BAN_WAIT_TIME, OVERRIDE_AUTO_WAIT, BITRATE, CODEC_MAP, EXT_MAP, DOWNLOAD_REAL_TIME, \
|
||||||
|
SKIP_PREVIOUSLY_DOWNLOADED
|
||||||
from utils import fix_filename, set_audio_tags, set_music_thumbnail, create_download_directory, \
|
from utils import fix_filename, set_audio_tags, set_music_thumbnail, create_download_directory, \
|
||||||
get_directory_song_ids, add_to_directory_song_ids
|
get_directory_song_ids, add_to_directory_song_ids, get_previously_downloaded, add_to_archive
|
||||||
from zspotify import ZSpotify
|
from zspotify import ZSpotify
|
||||||
|
|
||||||
|
|
||||||
@ -91,8 +92,10 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
|||||||
filename = os.path.join(
|
filename = os.path.join(
|
||||||
download_directory, f'{song_name}.{EXT_MAP.get(ZSpotify.get_config(DOWNLOAD_FORMAT).lower())}')
|
download_directory, f'{song_name}.{EXT_MAP.get(ZSpotify.get_config(DOWNLOAD_FORMAT).lower())}')
|
||||||
|
|
||||||
|
archive_directory = os.path.join(os.path.dirname(__file__), ZSpotify.get_config(ROOT_PATH))
|
||||||
check_name = os.path.isfile(filename) and os.path.getsize(filename)
|
check_name = os.path.isfile(filename) and os.path.getsize(filename)
|
||||||
check_id = scraped_song_id in get_directory_song_ids(download_directory)
|
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)
|
||||||
|
|
||||||
# a song with the same name is installed
|
# a song with the same name is installed
|
||||||
if not check_id and check_name:
|
if not check_id and check_name:
|
||||||
@ -115,6 +118,11 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
|||||||
if check_id and check_name and ZSpotify.get_config(SKIP_EXISTING_FILES):
|
if check_id and check_name and ZSpotify.get_config(SKIP_EXISTING_FILES):
|
||||||
print('\n### SKIPPING:', song_name,
|
print('\n### SKIPPING:', song_name,
|
||||||
'(SONG ALREADY EXISTS) ###')
|
'(SONG ALREADY EXISTS) ###')
|
||||||
|
|
||||||
|
elif check_all_time and ZSpotify.get_config(SKIP_PREVIOUSLY_DOWNLOADED):
|
||||||
|
print('\n### SKIPPING:', song_name,
|
||||||
|
'(SONG ALREADY DOWNLOADED ONCE) ###')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if track_id != scraped_song_id:
|
if track_id != scraped_song_id:
|
||||||
track_id = scraped_song_id
|
track_id = scraped_song_id
|
||||||
@ -146,6 +154,9 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
|||||||
release_year, disc_number, track_number)
|
release_year, disc_number, track_number)
|
||||||
set_music_thumbnail(filename, image_url)
|
set_music_thumbnail(filename, image_url)
|
||||||
|
|
||||||
|
# add song id to archive file
|
||||||
|
if ZSpotify.get_config(SKIP_PREVIOUSLY_DOWNLOADED):
|
||||||
|
add_to_archive(scraped_song_id, archive_directory)
|
||||||
# add song id to download directory's .song_ids file
|
# add song id to download directory's .song_ids file
|
||||||
if not check_id:
|
if not check_id:
|
||||||
add_to_directory_song_ids(download_directory, scraped_song_id)
|
add_to_directory_song_ids(download_directory, scraped_song_id)
|
||||||
|
@ -12,7 +12,6 @@ import requests
|
|||||||
from const import ARTIST, TRACKTITLE, ALBUM, YEAR, DISCNUMBER, TRACKNUMBER, ARTWORK, \
|
from const import ARTIST, TRACKTITLE, ALBUM, YEAR, DISCNUMBER, TRACKNUMBER, ARTWORK, \
|
||||||
WINDOWS_SYSTEM, ALBUMARTIST
|
WINDOWS_SYSTEM, ALBUMARTIST
|
||||||
|
|
||||||
|
|
||||||
class MusicFormat(str, Enum):
|
class MusicFormat(str, Enum):
|
||||||
MP3 = 'mp3',
|
MP3 = 'mp3',
|
||||||
OGG = 'ogg',
|
OGG = 'ogg',
|
||||||
@ -28,6 +27,30 @@ def create_download_directory(download_path: str) -> None:
|
|||||||
with open(hidden_file_path, 'w', encoding='utf-8') as f:
|
with open(hidden_file_path, 'w', encoding='utf-8') as f:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_previously_downloaded(song_id: str, archive_directory: str) -> List[str]:
|
||||||
|
""" Returns list of all time downloaded songs """
|
||||||
|
|
||||||
|
ids = []
|
||||||
|
archive_path = os.path.join(archive_directory, '.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()]
|
||||||
|
|
||||||
|
return ids
|
||||||
|
|
||||||
|
def add_to_archive(song_id: str, archive_directory: str) -> None:
|
||||||
|
""" Adds song id to all time installed songs archive """
|
||||||
|
|
||||||
|
archive_path = os.path.join(archive_directory, '.song_archive')
|
||||||
|
|
||||||
|
if os.path.exists(archive_path):
|
||||||
|
with open(archive_path, 'a', encoding='utf-8') as f:
|
||||||
|
f.write(f'{song_id}\n')
|
||||||
|
else:
|
||||||
|
with open(archive_path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(f'{song_id}\n')
|
||||||
|
|
||||||
def get_directory_song_ids(download_path: str) -> List[str]:
|
def get_directory_song_ids(download_path: str) -> List[str]:
|
||||||
""" Gets song ids of songs in directory """
|
""" Gets song ids of songs in directory """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user