refactored
This commit is contained in:
		| @@ -26,34 +26,32 @@ class Download: | |||||||
|                 logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.") |                 logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.") | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             sucess = False |             success = False | ||||||
|             for src in AUDIO_SOURCES: |             for src in AUDIO_SOURCES: | ||||||
|                 res = Download.fetch_from_src(song, src) |                 res = Download.fetch_from_src(song, src) | ||||||
|                 if res is not None: |                 if res is not None: | ||||||
|                     sucess = True |                     success = True | ||||||
|                     Download.add_url(res, src, id_) |                     Download.add_url(res, src, id_) | ||||||
|  |  | ||||||
|             if not sucess: |             if not success: | ||||||
|                 logger.warning(f"Didn't find any sources for {song}") |                 logger.warning(f"Didn't find any sources for {song}") | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def fetch_sources(cls, songs: List[song_object], skip_existing_files: bool = False): |     def fetch_sources(cls, songs: List[song_object], skip_existing_files: bool = False): | ||||||
|         for song in songs: |         for song in songs: | ||||||
|             if song.target.is_set(): |             if song.target.exists_on_disc and skip_existing_files: | ||||||
|                 if os.path.exists(song.target.file) and skip_existing_files: |                 logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.") | ||||||
|                     logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.") |                 continue | ||||||
|                     continue |  | ||||||
|  |  | ||||||
|             sucess = False |             success = False | ||||||
|             for src in AUDIO_SOURCES: |             for src in AUDIO_SOURCES: | ||||||
|                 res = cls.fetch_from_src(song, src) |                 res = cls.fetch_from_src(song, src) | ||||||
|                 if res is not None: |                 if res is not None: | ||||||
|                     sucess = True |                     success = True | ||||||
|                     cls.add_url(res, src, song.id) |                     cls.add_url(res, src, song.id) | ||||||
|  |  | ||||||
|             if not sucess: |             if not success: | ||||||
|                 logger.warning(f"Didn't find any sources for {song}") |                 logger.warning(f"Didn't find any sources for {song}") | ||||||
|      |  | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def fetch_from_src(cls, song, src): |     def fetch_from_src(cls, song, src): | ||||||
|   | |||||||
| @@ -25,9 +25,21 @@ class Target: | |||||||
|         if self._path is None: |         if self._path is None: | ||||||
|             return None |             return None | ||||||
|         return os.path.join(MUSIC_DIR, self._path) |         return os.path.join(MUSIC_DIR, self._path) | ||||||
|  |  | ||||||
|  |     def get_exists_on_disc(self) -> bool: | ||||||
|  |         """ | ||||||
|  |         returns True when file can be found on disc | ||||||
|  |         returns False when file can't be found on disc or no filepath is set | ||||||
|  |         """ | ||||||
|  |         if not self.is_set(): | ||||||
|  |             return False | ||||||
|  |  | ||||||
|  |         return os.path.exists(self.file) | ||||||
|      |      | ||||||
|     def is_set(self) -> bool: |     def is_set(self) -> bool: | ||||||
|         return not (self._file is None or self._path is None) |         return not (self._file is None or self._path is None) | ||||||
|  |  | ||||||
|     file = property(fget=get_file, fset=set_file) |     file = property(fget=get_file, fset=set_file) | ||||||
|     path = property(fget=get_path, fset=set_path) |     path = property(fget=get_path, fset=set_path) | ||||||
|  |  | ||||||
|  |     exists_on_disc = property(fget=get_exists_on_disc) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user