implemented stream
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import random
|
||||
from typing import Optional, Union, Type, Dict, List
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
@@ -35,19 +36,22 @@ class Page:
|
||||
SOURCE_TYPE: SourcePages
|
||||
|
||||
@classmethod
|
||||
def get_request(cls, url: str, accepted_response_codes: set = set((200,)), trie: int = 0) -> Optional[
|
||||
def get_request(cls, url: str, stream: bool = False, accepted_response_codes: set = set((200,)), trie: int = 0) -> Optional[
|
||||
requests.Response]:
|
||||
retry = False
|
||||
try:
|
||||
r = cls.API_SESSION.get(url, timeout=cls.TIMEOUT)
|
||||
r = cls.API_SESSION.get(url, timeout=cls.TIMEOUT, stream=stream)
|
||||
except requests.exceptions.Timeout:
|
||||
retry = True
|
||||
except requests.exceptions.ConnectionError:
|
||||
retry = True
|
||||
|
||||
if not retry and r.status_code in accepted_response_codes:
|
||||
return r
|
||||
|
||||
LOGGER.warning(f"{cls.__name__} responded wit {r.status_code} at GET:{url}. ({trie}-{cls.TRIES})")
|
||||
LOGGER.debug(r.content)
|
||||
if not retry:
|
||||
LOGGER.warning(f"{cls.__name__} responded wit {r.status_code} at GET:{url}. ({trie}-{cls.TRIES})")
|
||||
LOGGER.debug(r.content)
|
||||
|
||||
if trie >= cls.TRIES:
|
||||
LOGGER.warning("to many tries. Aborting.")
|
||||
@@ -330,7 +334,12 @@ class Page:
|
||||
if len(sources) == 0:
|
||||
return
|
||||
|
||||
temp_target = cls._download_song_to_targets(source=sources[0], target_list=song.target_collection.shallow_list)
|
||||
temp_target: Target = Target(
|
||||
path=shared.TEMP_DIR,
|
||||
file=str(random.randint(0, 999999))
|
||||
)
|
||||
|
||||
cls._download_song_to_targets(source=sources[0], target=temp_target)
|
||||
cls._post_process_targets(song, temp_target)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -897,7 +897,7 @@ class Musify(Page):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _download_song_to_targets(cls, source: Source) -> Path:
|
||||
def _download_song_to_targets(cls, source: Source, target: Target) -> Path:
|
||||
"""
|
||||
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
|
||||
@@ -906,12 +906,8 @@ class Musify(Page):
|
||||
if url.source_type != MusifyTypes.SONG:
|
||||
return
|
||||
|
||||
target: Target = Target(
|
||||
path=TEMP_FOLDER,
|
||||
file=str(random.randint(0, 999999))
|
||||
)
|
||||
|
||||
|
||||
endpoint = f"https://musify.club/track/dl/{url.musify_id}/{url.name_without_id}.mp3"
|
||||
print(endpoint)
|
||||
|
||||
return target
|
||||
target.stream_into(cls.get_request(endpoint, stream=True))
|
||||
|
||||
Reference in New Issue
Block a user