Skip to content

Commit

Permalink
check status code when getting response from piped
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Sep 2, 2024
1 parent cb677af commit fee3859
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions spotdl/providers/audio/piped.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import requests
from yt_dlp import YoutubeDL

from spotdl.providers.audio.base import ISRC_REGEX, AudioProvider, YTDLLogger
from spotdl.providers.audio.base import (
ISRC_REGEX,
AudioProvider,
YTDLLogger,
AudioProviderError,
)
from spotdl.types.result import Result
from spotdl.utils.config import GlobalConfig, get_temp_path
from spotdl.utils.formatter import args_to_ytdlp_options
Expand Down Expand Up @@ -108,6 +113,11 @@ def get_results(self, search_term: str, **kwargs) -> List[Result]:
timeout=20,
)

if response.status_code != 200:
raise AudioProviderError(
f"Failed to get results for {search_term} from Piped: {response.text}"
)

search_results = response.json()

# Simplify results
Expand Down Expand Up @@ -151,11 +161,18 @@ def get_download_metadata(self, url: str, download: bool = False) -> Dict:
"""

url_id = url.split("?v=")[1]
piped_data = requests.get(
piped_response = requests.get(
f"https://pipedapi.kavin.rocks/streams/{url_id}",
timeout=10,
proxies=GlobalConfig.get_parameter("proxies"),
).json()
)

if piped_response.status_code != 200:
raise AudioProviderError(
f"Failed to get metadata for {url} from Piped: {piped_response.text}"
)

piped_data = piped_response.json()

yt_dlp_json = {
"title": piped_data["title"],
Expand Down

0 comments on commit fee3859

Please sign in to comment.