From c65b85631b6e5d292cefcf58d51fb8321c70b840 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 30 Jul 2020 19:23:54 +0200 Subject: [PATCH] Added 'b' option for overwriteFile It will keep both files and add a number at the end of the filename --- deemix/__init__.py | 2 +- deemix/app/downloader.py | 15 ++++++++++++--- setup.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/deemix/__init__.py b/deemix/__init__.py index f4b8d2b..4336d29 100644 --- a/deemix/__init__.py +++ b/deemix/__init__.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -__version__ = "1.1.24" +__version__ = "1.1.25" diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 064160c..bcb4311 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -101,7 +101,7 @@ def trackRemovePercentage(trackAPI, queueItem, interface): def downloadImage(url, path, overwrite="n"): - if not os.path.isfile(path) or overwrite in ['y', 't']: + if not os.path.isfile(path) or overwrite in ['y', 't', 'b']: try: image = get(url, headers={'User-Agent': USER_AGENT_HEADER}, timeout=30) image.raise_for_status() @@ -177,7 +177,7 @@ def getPreferredBitrate(dz, track, bitrate, fallback=True): continue else: return error_num - + return error_num # fallback is enabled and loop went through all formats @@ -790,6 +790,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None result['artistPath'] = os.path.join(artistPath, f"{settingsRegexArtist(settings['artistImageTemplate'], track['album']['mainArtist'], settings)}") + trackAlreadyDownloaded = os.path.isfile(writepath) + if trackAlreadyDownloaded and settings['overwriteFile'] == 'b': + baseFilename = os.path.join(filepath, filename) + i = 1 + currentFilename = baseFilename+' ('+str(i)+')'+ extensions[track['selectedFormat']] + while os.path.isfile(currentFilename): + i += 1 + currentFilename = baseFilename+' ('+str(i)+')'+ extensions[track['selectedFormat']] + trackAlreadyDownloaded = False + writepath = currentFilename # Data for m3u file if extrasPath: result['extrasPath'] = extrasPath @@ -815,7 +825,6 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'], track['selectedFormat']) - trackAlreadyDownloaded = os.path.isfile(writepath) if not trackAlreadyDownloaded or settings['overwriteFile'] == 'y': logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Downloading the track") def downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings): diff --git a/setup.py b/setup.py index e137f21..a9dceef 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text() setup( name="deemix", - version="1.1.24", + version="1.1.25", description="A barebone deezer downloader library", long_description=README, long_description_content_type="text/markdown",