From 2825f6c593fc9f1864ab91d7efcb2263668e02f5 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Wed, 27 Feb 2019 10:45:05 -0800 Subject: [PATCH] Fix prompt when using '/' to create sub-directories (#503) * Fix prompt when using '/' to create sub-directories * Fix and update CHANGES.md --- CHANGES.md | 10 +++++----- spotdl/downloader.py | 18 +++++++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f644b83..d87d747 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,12 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added -- +- Set custom Spotify Client ID and Client Secret via config.yml ([@ManveerBasra](https://github.com/ManveerBasra)) (#502) +- Use YouTube as fallback metadata if track not found on Spotify. Also added `--no-fallback-metadata` + to preserve old behaviour ([@ritiek](https://github.com/ritiek)) (#457) ### Changed - ### Fixed +- Fix already downloaded prompt when using "/" in `--file-format` to create sub-directories ([@ritiek](https://github.com/ritiek)) (#503) - Fix writing playlist tracks to file ([@ritiek](https://github.com/ritiek)) (#506) ## [1.1.2] - 2019-02-10 @@ -27,14 +30,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.1.1] - 2019-01-03 ### Added -- Use YouTube as fallback metadata if track not found on Spotify. Also added `--no-fallback-metadata` - to preserve old behaviour ([@ritiek](https://github.com/ritiek)) (#457) - Output informative message in case of no result found in YouTube search ([@Amit-L](https://github.com/Amit-L)) (#452) - Ability to pass multiple tracks with `-s` option ([@ritiek](https://github.com/ritiek)) (#442) ### Changed -- Allowed to fetch metadata from Spotify upon searching Spotify-URL and `--no-metadata` to gather YouTube - custom-search fields ([@Amit-L](https://github.com/Amit-L)) (#452) +- Allowed to fetch metadata from Spotify upon searching Spotify-URL and `--no-metadata` to gather YouTube custom-search fields ([@Amit-L](https://github.com/Amit-L)) (#452) - Change FFmpeg to use the built-in encoder `aac` instead of 3rd party `libfdk-aac` which does not ship with the apt package ([@ritiek](https://github.com/ritiek)) (#448) - Monkeypatch ever-changing network-relying tests ([@ritiek](https://github.com/ritiek)) (#448) diff --git a/spotdl/downloader.py b/spotdl/downloader.py index bbbe024..d91cb29 100644 --- a/spotdl/downloader.py +++ b/spotdl/downloader.py @@ -14,16 +14,20 @@ from spotdl import youtube_tools class CheckExists: def __init__(self, music_file, meta_tags=None): - self.music_file = music_file self.meta_tags = meta_tags + basepath, filename = os.path.split(music_file) + filepath = os.path.join(const.args.folder, basepath) + os.makedirs(filepath, exist_ok=True) + self.filepath = filepath + self.filename = filename def already_exists(self, raw_song): """ Check if the input song already exists in the given folder. """ log.debug( "Cleaning any temp files and checking " - 'if "{}" already exists'.format(self.music_file) + 'if "{}" already exists'.format(self.filename) ) - songs = os.listdir(const.args.folder) + songs = os.listdir(self.filepath) self._remove_temp_files(songs) for song in songs: @@ -45,17 +49,17 @@ class CheckExists: def _remove_temp_files(self, songs): for song in songs: if song.endswith(".temp"): - os.remove(os.path.join(const.args.folder, song)) + os.remove(os.path.join(self.filepath, song)) def _has_metadata(self, song): # check if the already downloaded song has correct metadata # if not, remove it and download again without prompt already_tagged = metadata.compare( - os.path.join(const.args.folder, song), self.meta_tags + os.path.join(self.filepath, song), self.meta_tags ) log.debug("Checking if it is already tagged correctly? {}", already_tagged) if not already_tagged: - os.remove(os.path.join(const.args.folder, song)) + os.remove(os.path.join(self.filepath, song)) return False return True @@ -80,7 +84,7 @@ class CheckExists: return True def _match_filenames(self, song): - if os.path.splitext(song)[0] == self.music_file: + if os.path.splitext(song)[0] == self.filename: log.debug('Found an already existing song: "{}"'.format(song)) return True