Fixed bug with inconsistent dynamic creation of direct download links
This commit is contained in:
parent
228709413b
commit
ab5af4aaa9
@ -109,14 +109,15 @@ class Source(DatabaseObject):
|
|||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [
|
return [
|
||||||
('id', self.id),
|
('id', self.id),
|
||||||
('url', self.url)
|
('url', self.url),
|
||||||
|
('audio_url', self.audio_url),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"Src({self.page_enum.value}: {self.url})"
|
return f"Src({self.page_enum.value}: {self.url}, {self.audio_url})"
|
||||||
|
|
||||||
page_str = property(fget=lambda self: self.page_enum.value)
|
page_str = property(fget=lambda self: self.page_enum.value)
|
||||||
type_str = property(fget=lambda self: self.type_enum.value)
|
type_str = property(fget=lambda self: self.type_enum.value)
|
||||||
@ -129,7 +130,6 @@ class SourceCollection(Collection):
|
|||||||
|
|
||||||
super().__init__(data=source_list, element_type=Source)
|
super().__init__(data=source_list, element_type=Source)
|
||||||
|
|
||||||
|
|
||||||
def map_element(self, source: Source):
|
def map_element(self, source: Source):
|
||||||
super().map_element(source)
|
super().map_element(source)
|
||||||
|
|
||||||
|
@ -774,6 +774,8 @@ class Musify(Page):
|
|||||||
source_list: List[Source] = []
|
source_list: List[Source] = []
|
||||||
tracksort = None
|
tracksort = None
|
||||||
|
|
||||||
|
current_url = None
|
||||||
|
|
||||||
def parse_title(_title: str) -> str:
|
def parse_title(_title: str) -> str:
|
||||||
return _title
|
return _title
|
||||||
|
|
||||||
@ -813,6 +815,7 @@ class Musify(Page):
|
|||||||
track_anchor: BeautifulSoup = anchor_list[-1]
|
track_anchor: BeautifulSoup = anchor_list[-1]
|
||||||
href: str = track_anchor.get("href")
|
href: str = track_anchor.get("href")
|
||||||
if href is not None:
|
if href is not None:
|
||||||
|
current_url = cls.HOST + href
|
||||||
source_list.append(Source(cls.SOURCE_TYPE, cls.HOST + href))
|
source_list.append(Source(cls.SOURCE_TYPE, cls.HOST + href))
|
||||||
song_name = parse_title(track_anchor.get_text(strip=True))
|
song_name = parse_title(track_anchor.get_text(strip=True))
|
||||||
|
|
||||||
@ -850,9 +853,10 @@ class Musify(Page):
|
|||||||
download_anchor = playlist_actions.find("a", {"itemprop": "audio"})
|
download_anchor = playlist_actions.find("a", {"itemprop": "audio"})
|
||||||
if download_anchor is not None:
|
if download_anchor is not None:
|
||||||
download_href = download_anchor.get("href")
|
download_href = download_anchor.get("href")
|
||||||
if download_href is not None:
|
if download_href is not None and current_url is not None:
|
||||||
source_list.append(Source(
|
source_list.append(Source(
|
||||||
cls.SOURCE_TYPE,
|
cls.SOURCE_TYPE,
|
||||||
|
url=current_url,
|
||||||
adio_url=cls.HOST + download_href
|
adio_url=cls.HOST + download_href
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -982,13 +986,17 @@ class Musify(Page):
|
|||||||
https://musify.club/track/im-in-a-coffin-life-never-was-waste-of-skin-16360302
|
https://musify.club/track/im-in-a-coffin-life-never-was-waste-of-skin-16360302
|
||||||
https://musify.club/track/dl/16360302/im-in-a-coffin-life-never-was-waste-of-skin.mp3
|
https://musify.club/track/dl/16360302/im-in-a-coffin-life-never-was-waste-of-skin.mp3
|
||||||
"""
|
"""
|
||||||
|
endpoint = source.audio_url
|
||||||
|
|
||||||
|
if source.audio_url is None:
|
||||||
url: MusifyUrl = cls.parse_url(source.url)
|
url: MusifyUrl = cls.parse_url(source.url)
|
||||||
if url.source_type != MusifyTypes.SONG:
|
if url.source_type != MusifyTypes.SONG:
|
||||||
return DownloadResult(error_message=f"The url is not of the type Song: {source.url}")
|
return DownloadResult(error_message=f"The url is not of the type Song: {source.url}")
|
||||||
|
|
||||||
endpoint = f"https://musify.club/track/dl/{url.musify_id}/{url.name_without_id}.mp3"
|
endpoint = f"https://musify.club/track/dl/{url.musify_id}/{url.name_without_id}.mp3"
|
||||||
|
|
||||||
|
cls.LOGGER.warning(f"The source has no audio link. Falling back to {endpoint}.")
|
||||||
|
|
||||||
r = cls.get_request(endpoint, stream=True)
|
r = cls.get_request(endpoint, stream=True)
|
||||||
if r is None:
|
if r is None:
|
||||||
return DownloadResult(error_message=f"couldn't connect to {endpoint}")
|
return DownloadResult(error_message=f"couldn't connect to {endpoint}")
|
||||||
|
Loading…
Reference in New Issue
Block a user