fix: downloads
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | from pathlib import Path | ||||||
| from typing import List, Tuple | from typing import List, Tuple | ||||||
| from tqdm import tqdm | from tqdm import tqdm | ||||||
| from ffmpeg_progress_yield import FfmpegProgress | from ffmpeg_progress_yield import FfmpegProgress | ||||||
| @@ -19,8 +20,7 @@ def correct_codec(target: Target, bitrate_kb: int = main_settings["bitrate"], au | |||||||
|     bitrate_b = int(bitrate_kb / 1024) |     bitrate_b = int(bitrate_kb / 1024) | ||||||
|  |  | ||||||
|     output_target = Target( |     output_target = Target( | ||||||
|         path=target._path, |         file_path=Path(str(target.file_path) + "." + audio_format) | ||||||
|         file=str(target._file) + "." + audio_format |  | ||||||
|     ) |     ) | ||||||
|      |      | ||||||
|     # get the select thingie |     # get the select thingie | ||||||
|   | |||||||
| @@ -229,6 +229,7 @@ class Collection(Generic[T]): | |||||||
|  |  | ||||||
|         if existing_object is None: |         if existing_object is None: | ||||||
|             # append |             # append | ||||||
|  |             # print("appending", existing_object, __object) | ||||||
|             append_to._data.append(__object) |             append_to._data.append(__object) | ||||||
|         else: |         else: | ||||||
|             # merge |             # merge | ||||||
|   | |||||||
| @@ -68,7 +68,7 @@ class Song(Base): | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     def __init__(self, title: str = None, unified_title: str = None, isrc: str = None, length: int = None, |     def __init__(self, title: str = None, unified_title: str = None, isrc: str = None, length: int = None, | ||||||
|                  genre: str = None, note: FormattedText = None, source_list: SourceCollection = None, |                  genre: str = None, note: FormattedText = None, source_list: List[Source] = None, | ||||||
|                  target_list: List[Target] = None, lyrics_list: List[Lyrics] = None, |                  target_list: List[Target] = None, lyrics_list: List[Lyrics] = None, | ||||||
|                  main_artist_list: List[Artist] = None, feature_artist_list: List[Artist] = None, |                  main_artist_list: List[Artist] = None, feature_artist_list: List[Artist] = None, | ||||||
|                  album_list: List[Album] = None, **kwargs) -> None: |                  album_list: List[Album] = None, **kwargs) -> None: | ||||||
| @@ -214,7 +214,7 @@ class Album(Base): | |||||||
|     def __init__(self, title: str = None, unified_title: str = None, album_status: AlbumStatus = None, |     def __init__(self, title: str = None, unified_title: str = None, album_status: AlbumStatus = None, | ||||||
|                  album_type: AlbumType = None, language: Language = None, date: ID3Timestamp = None, |                  album_type: AlbumType = None, language: Language = None, date: ID3Timestamp = None, | ||||||
|                  barcode: str = None, albumsort: int = None, notes: FormattedText = None, |                  barcode: str = None, albumsort: int = None, notes: FormattedText = None, | ||||||
|                  source_list: SourceCollection = None, artist_list: List[Artist] = None, song_list: List[Song] = None, |                  source_list: List[Source] = None, artist_list: List[Artist] = None, song_list: List[Song] = None, | ||||||
|                  label_list: List[Label] = None, **kwargs) -> None: |                  label_list: List[Label] = None, **kwargs) -> None: | ||||||
|         super().__init__(title=title, unified_title=unified_title, album_status=album_status, album_type=album_type, |         super().__init__(title=title, unified_title=unified_title, album_status=album_status, album_type=album_type, | ||||||
|                          language=language, date=date, barcode=barcode, albumsort=albumsort, notes=notes, |                          language=language, date=date, barcode=barcode, albumsort=albumsort, notes=notes, | ||||||
| @@ -410,7 +410,7 @@ class Artist(Base): | |||||||
|     # This is automatically generated |     # This is automatically generated | ||||||
|     def __init__(self, name: str = None, unified_name: str = None, country: Country = None, |     def __init__(self, name: str = None, unified_name: str = None, country: Country = None, | ||||||
|                  formed_in: ID3Timestamp = None, notes: FormattedText = None, lyrical_themes: List[str] = None, |                  formed_in: ID3Timestamp = None, notes: FormattedText = None, lyrical_themes: List[str] = None, | ||||||
|                  general_genre: str = None, unformated_location: str = None, source_list: SourceCollection = None, |                  general_genre: str = None, unformated_location: str = None, source_list: List[Source] = None, | ||||||
|                  contact_list: List[Contact] = None, feature_song_list: List[Song] = None, |                  contact_list: List[Contact] = None, feature_song_list: List[Song] = None, | ||||||
|                  main_album_list: List[Album] = None, label_list: List[Label] = None, **kwargs) -> None: |                  main_album_list: List[Album] = None, label_list: List[Label] = None, **kwargs) -> None: | ||||||
|  |  | ||||||
| @@ -604,7 +604,7 @@ class Label(Base): | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     def __init__(self, name: str = None, unified_name: str = None, notes: FormattedText = None, |     def __init__(self, name: str = None, unified_name: str = None, notes: FormattedText = None, | ||||||
|                  source_list: SourceCollection = None, contact_list: List[Contact] = None, |                  source_list: List[Source] = None, contact_list: List[Contact] = None, | ||||||
|                  album_list: List[Album] = None, current_artist_list: List[Artist] = None, **kwargs) -> None: |                  album_list: List[Album] = None, current_artist_list: List[Artist] = None, **kwargs) -> None: | ||||||
|         super().__init__(name=name, unified_name=unified_name, notes=notes, source_list=source_list, |         super().__init__(name=name, unified_name=unified_name, notes=notes, source_list=source_list, | ||||||
|                          contact_list=contact_list, album_list=album_list, current_artist_list=current_artist_list, |                          contact_list=contact_list, album_list=album_list, current_artist_list=current_artist_list, | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ class Target(OuterProxy): | |||||||
|         return self.file_path.stat().st_size |         return self.file_path.stat().st_size | ||||||
|  |  | ||||||
|     def create_path(self): |     def create_path(self): | ||||||
|         self._path.mkdir(parents=True, exist_ok=True) |         self.file_path.parent.mkdir(parents=True, exist_ok=True) | ||||||
|  |  | ||||||
|     def copy_content(self, copy_to: Target): |     def copy_content(self, copy_to: Target): | ||||||
|         if not self.exists: |         if not self.exists: | ||||||
|   | |||||||
| @@ -24,6 +24,7 @@ from ..connection import Connection | |||||||
| from ..utils.support_classes.download_result import DownloadResult | from ..utils.support_classes.download_result import DownloadResult | ||||||
| from ..utils.config import main_settings, logging_settings | from ..utils.config import main_settings, logging_settings | ||||||
| from ..utils.shared import DEBUG | from ..utils.shared import DEBUG | ||||||
|  |  | ||||||
| if DEBUG: | if DEBUG: | ||||||
|     from ..utils.debug_utils import dump_to_file |     from ..utils.debug_utils import dump_to_file | ||||||
|  |  | ||||||
| @@ -38,7 +39,6 @@ def _get_host(source: Source) -> str: | |||||||
|     return urlunparse((parsed.scheme, parsed.netloc, "", "", "", "")) |     return urlunparse((parsed.scheme, parsed.netloc, "", "", "", "")) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class BandcampTypes(Enum): | class BandcampTypes(Enum): | ||||||
|     ARTIST = "b" |     ARTIST = "b" | ||||||
|     ALBUM = "a" |     ALBUM = "a" | ||||||
| @@ -55,7 +55,7 @@ class Bandcamp(Page): | |||||||
|             host="https://bandcamp.com/", |             host="https://bandcamp.com/", | ||||||
|             logger=self.LOGGER |             logger=self.LOGGER | ||||||
|         ) |         ) | ||||||
|          |  | ||||||
|         super().__init__(*args, **kwargs) |         super().__init__(*args, **kwargs) | ||||||
|  |  | ||||||
|     def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]: |     def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]: | ||||||
| @@ -68,7 +68,7 @@ class Bandcamp(Page): | |||||||
|             return Album |             return Album | ||||||
|         if path.startswith("track"): |         if path.startswith("track"): | ||||||
|             return Song |             return Song | ||||||
|          |  | ||||||
|         return super().get_source_type(source) |         return super().get_source_type(source) | ||||||
|  |  | ||||||
|     def _parse_autocomplete_api_result(self, data: dict) -> DatabaseObject: |     def _parse_autocomplete_api_result(self, data: dict) -> DatabaseObject: | ||||||
| @@ -124,7 +124,7 @@ class Bandcamp(Page): | |||||||
|                     ) |                     ) | ||||||
|                 ] |                 ] | ||||||
|             ) |             ) | ||||||
|      |  | ||||||
|     def general_search(self, search_query: str, filter_string: str = "") -> List[DatabaseObject]: |     def general_search(self, search_query: str, filter_string: str = "") -> List[DatabaseObject]: | ||||||
|         results = [] |         results = [] | ||||||
|  |  | ||||||
| @@ -148,19 +148,18 @@ class Bandcamp(Page): | |||||||
|                 results.append(r) |                 results.append(r) | ||||||
|  |  | ||||||
|         return results |         return results | ||||||
|      |  | ||||||
|     def label_search(self, label: Label) -> List[Label]: |     def label_search(self, label: Label) -> List[Label]: | ||||||
|         return self.general_search(label.name, filter_string="b") |         return self.general_search(label.name, filter_string="b") | ||||||
|      |  | ||||||
|     def artist_search(self, artist: Artist) -> List[Artist]: |     def artist_search(self, artist: Artist) -> List[Artist]: | ||||||
|         return self.general_search(artist.name, filter_string="b") |         return self.general_search(artist.name, filter_string="b") | ||||||
|      |  | ||||||
|     def album_search(self, album: Album) -> List[Album]: |     def album_search(self, album: Album) -> List[Album]: | ||||||
|         return self.general_search(album.title, filter_string="a") |         return self.general_search(album.title, filter_string="a") | ||||||
|      |  | ||||||
|     def song_search(self, song: Song) -> List[Song]: |     def song_search(self, song: Song) -> List[Song]: | ||||||
|         return self.general_search(song.title, filter_string="t") |         return self.general_search(song.title, filter_string="t") | ||||||
|      |  | ||||||
|  |  | ||||||
|     def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label: |     def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label: | ||||||
|         return Label() |         return Label() | ||||||
| @@ -169,13 +168,13 @@ class Bandcamp(Page): | |||||||
|         name: str = None |         name: str = None | ||||||
|         source_list: List[Source] = [] |         source_list: List[Source] = [] | ||||||
|         contact_list: List[Contact] = [] |         contact_list: List[Contact] = [] | ||||||
|          |  | ||||||
|         band_name_location: BeautifulSoup = soup.find("p", {"id": "band-name-location"}) |         band_name_location: BeautifulSoup = soup.find("p", {"id": "band-name-location"}) | ||||||
|         if band_name_location is not None: |         if band_name_location is not None: | ||||||
|             title_span = band_name_location.find("span", {"class": "title"}) |             title_span = band_name_location.find("span", {"class": "title"}) | ||||||
|             if title_span is not None: |             if title_span is not None: | ||||||
|                 name = title_span.text.strip() |                 name = title_span.text.strip() | ||||||
|          |  | ||||||
|         link_container: BeautifulSoup = soup.find("ol", {"id": "band-links"}) |         link_container: BeautifulSoup = soup.find("ol", {"id": "band-links"}) | ||||||
|         if link_container is not None: |         if link_container is not None: | ||||||
|             li: BeautifulSoup |             li: BeautifulSoup | ||||||
| @@ -189,7 +188,7 @@ class Bandcamp(Page): | |||||||
|             name=name, |             name=name, | ||||||
|             source_list=source_list |             source_list=source_list | ||||||
|         ) |         ) | ||||||
|      |  | ||||||
|     def _parse_album(self, soup: BeautifulSoup, initial_source: Source) -> List[Album]: |     def _parse_album(self, soup: BeautifulSoup, initial_source: Source) -> List[Album]: | ||||||
|         title = None |         title = None | ||||||
|         source_list: List[Source] = [] |         source_list: List[Source] = [] | ||||||
| @@ -197,7 +196,7 @@ class Bandcamp(Page): | |||||||
|         a = soup.find("a") |         a = soup.find("a") | ||||||
|         if a is not None and a["href"] is not None: |         if a is not None and a["href"] is not None: | ||||||
|             source_list.append(Source(self.SOURCE_TYPE, _get_host(initial_source) + a["href"])) |             source_list.append(Source(self.SOURCE_TYPE, _get_host(initial_source) + a["href"])) | ||||||
|          |  | ||||||
|         title_p = soup.find("p", {"class": "title"}) |         title_p = soup.find("p", {"class": "title"}) | ||||||
|         if title_p is not None: |         if title_p is not None: | ||||||
|             title = title_p.text.strip() |             title = title_p.text.strip() | ||||||
| @@ -219,14 +218,13 @@ class Bandcamp(Page): | |||||||
|  |  | ||||||
|         return album_list |         return album_list | ||||||
|  |  | ||||||
|  |  | ||||||
|     def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist: |     def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist: | ||||||
|         artist = Artist() |         artist = Artist() | ||||||
|  |  | ||||||
|         r = self.connection.get(_parse_artist_url(source.url)) |         r = self.connection.get(_parse_artist_url(source.url)) | ||||||
|         if r is None: |         if r is None: | ||||||
|             return artist |             return artist | ||||||
|          |  | ||||||
|         soup = self.get_soup_from_response(r) |         soup = self.get_soup_from_response(r) | ||||||
|  |  | ||||||
|         if DEBUG: |         if DEBUG: | ||||||
| @@ -238,7 +236,7 @@ class Bandcamp(Page): | |||||||
|         if html_music_grid is not None: |         if html_music_grid is not None: | ||||||
|             for subsoup in html_music_grid.find_all("li"): |             for subsoup in html_music_grid.find_all("li"): | ||||||
|                 artist.main_album_collection.append(self._parse_album(soup=subsoup, initial_source=source)) |                 artist.main_album_collection.append(self._parse_album(soup=subsoup, initial_source=source)) | ||||||
|          |  | ||||||
|         for i, data_blob_soup in enumerate(soup.find_all("div", {"id": ["pagedata", "collectors-data"]})): |         for i, data_blob_soup in enumerate(soup.find_all("div", {"id": ["pagedata", "collectors-data"]})): | ||||||
|             data_blob = data_blob_soup["data-blob"] |             data_blob = data_blob_soup["data-blob"] | ||||||
|  |  | ||||||
| @@ -252,7 +250,7 @@ class Bandcamp(Page): | |||||||
|  |  | ||||||
|         artist.source_collection.append(source) |         artist.source_collection.append(source) | ||||||
|         return artist |         return artist | ||||||
|      |  | ||||||
|     def _parse_track_element(self, track: dict) -> Optional[Song]: |     def _parse_track_element(self, track: dict) -> Optional[Song]: | ||||||
|         return Song( |         return Song( | ||||||
|             title=track["item"]["name"].strip(), |             title=track["item"]["name"].strip(), | ||||||
| @@ -266,11 +264,11 @@ class Bandcamp(Page): | |||||||
|         r = self.connection.get(source.url) |         r = self.connection.get(source.url) | ||||||
|         if r is None: |         if r is None: | ||||||
|             return album |             return album | ||||||
|          |  | ||||||
|         soup = self.get_soup_from_response(r) |         soup = self.get_soup_from_response(r) | ||||||
|  |  | ||||||
|         data_container = soup.find("script", {"type": "application/ld+json"}) |         data_container = soup.find("script", {"type": "application/ld+json"}) | ||||||
|          |  | ||||||
|         if DEBUG: |         if DEBUG: | ||||||
|             dump_to_file("album_data.json", data_container.text, is_json=True, exit_after_dump=False) |             dump_to_file("album_data.json", data_container.text, is_json=True, exit_after_dump=False) | ||||||
|  |  | ||||||
| @@ -279,7 +277,7 @@ class Bandcamp(Page): | |||||||
|  |  | ||||||
|         artist_source_list = [] |         artist_source_list = [] | ||||||
|         if "@id" in artist_data: |         if "@id" in artist_data: | ||||||
|             artist_source_list=[Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))] |             artist_source_list = [Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))] | ||||||
|         album = Album( |         album = Album( | ||||||
|             title=data["name"].strip(), |             title=data["name"].strip(), | ||||||
|             source_list=[Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]))], |             source_list=[Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]))], | ||||||
| @@ -307,15 +305,14 @@ class Bandcamp(Page): | |||||||
|         if track_lyrics: |         if track_lyrics: | ||||||
|             self.LOGGER.debug(" Lyrics retrieved..") |             self.LOGGER.debug(" Lyrics retrieved..") | ||||||
|             return [Lyrics(text=FormattedText(html=track_lyrics.prettify()))] |             return [Lyrics(text=FormattedText(html=track_lyrics.prettify()))] | ||||||
|          |  | ||||||
|         return [] |         return [] | ||||||
|          |  | ||||||
|  |  | ||||||
|     def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song: |     def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song: | ||||||
|         r = self.connection.get(source.url) |         r = self.connection.get(source.url) | ||||||
|         if r is None: |         if r is None: | ||||||
|             return Song() |             return Song() | ||||||
|          |  | ||||||
|         soup = self.get_soup_from_response(r) |         soup = self.get_soup_from_response(r) | ||||||
|  |  | ||||||
|         data_container = soup.find("script", {"type": "application/ld+json"}) |         data_container = soup.find("script", {"type": "application/ld+json"}) | ||||||
| @@ -340,7 +337,7 @@ class Bandcamp(Page): | |||||||
|  |  | ||||||
|         song = Song( |         song = Song( | ||||||
|             title=data["name"].strip(), |             title=data["name"].strip(), | ||||||
|             source_list=[Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]), adio_url=mp3_url)], |             source_list=[Source(self.SOURCE_TYPE, data.get("mainEntityOfPage", data["@id"]), audio_url=mp3_url)], | ||||||
|             album_list=[Album( |             album_list=[Album( | ||||||
|                 title=album_data["name"].strip(), |                 title=album_data["name"].strip(), | ||||||
|                 date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"), |                 date=ID3Timestamp.strptime(data["datePublished"], "%d %b %Y %H:%M:%S %Z"), | ||||||
| @@ -348,7 +345,7 @@ class Bandcamp(Page): | |||||||
|             )], |             )], | ||||||
|             main_artist_list=[Artist( |             main_artist_list=[Artist( | ||||||
|                 name=artist_data["name"].strip(), |                 name=artist_data["name"].strip(), | ||||||
|                 source_list=[Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))]   |                 source_list=[Source(self.SOURCE_TYPE, _parse_artist_url(artist_data["@id"]))] | ||||||
|             )], |             )], | ||||||
|             lyrics_list=self._fetch_lyrics(soup=soup) |             lyrics_list=self._fetch_lyrics(soup=soup) | ||||||
|         ) |         ) | ||||||
| @@ -359,5 +356,6 @@ class Bandcamp(Page): | |||||||
|  |  | ||||||
|     def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult: |     def download_song_to_target(self, source: Source, target: Target, desc: str = None) -> DownloadResult: | ||||||
|         if source.audio_url is None: |         if source.audio_url is None: | ||||||
|  |             print(source) | ||||||
|             return DownloadResult(error_message="Couldn't find download link.") |             return DownloadResult(error_message="Couldn't find download link.") | ||||||
|         return self.connection.stream_into(url=source.audio_url, target=target, description=desc) |         return self.connection.stream_into(url=source.audio_url, target=target, description=desc) | ||||||
|   | |||||||
| @@ -628,7 +628,7 @@ class Musify(Page): | |||||||
|                     source_list.append(Source( |                     source_list.append(Source( | ||||||
|                         self.SOURCE_TYPE, |                         self.SOURCE_TYPE, | ||||||
|                         url=current_url, |                         url=current_url, | ||||||
|                         adio_url=self.HOST + download_href |                         audio_url=self.HOST + download_href | ||||||
|                     )) |                     )) | ||||||
|  |  | ||||||
|         return Song( |         return Song( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user