Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Oct 10, 2023
1 parent 1ba370f commit bb16521
Show file tree
Hide file tree
Showing 16 changed files with 8,694 additions and 6,430 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/standard-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Check for docstring's
run: |
poetry run pylint --limit-inference-results 0 --disable all --enable missing-function-docstring missing-module-docstring missing-class-docstring empty-docstring ./spotdl
poetry run pylint --limit-inference-results 0 --enable missing-function-docstring missing-module-docstring missing-class-docstring empty-docstring --disable=all ./spotdl
- name: Run Pylint check
run: |
Expand Down
10 changes: 0 additions & 10 deletions spotdl/download/config.py

This file was deleted.

4 changes: 2 additions & 2 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from yt_dlp.postprocessor.modify_chapters import ModifyChaptersPP
from yt_dlp.postprocessor.sponsorblock import SponsorBlockPP

from spotdl.download.config import DownloadConfig
from spotdl.download.progress_handler import ProgressHandler
from spotdl.providers.audio import (
AudioProvider,
Expand All @@ -34,6 +33,7 @@
from spotdl.utils.archive import Archive
from spotdl.utils.config import (
DOWNLOADER_OPTIONS,
GlobalConfig,
create_settings_type,
get_errors_path,
get_temp_path,
Expand Down Expand Up @@ -217,7 +217,7 @@ def __init__(
raise DownloaderError(f"Invalid proxy server: {proxy}")
proxies = {"http": proxy, "https": proxy}
logger.info("Setting proxy server: %s", proxy)
DownloadConfig.set_parameter("proxies", proxies)
GlobalConfig.set_parameter("proxies", proxies)

# Initialize archive
self.url_archive = Archive()
Expand Down
18 changes: 4 additions & 14 deletions spotdl/providers/audio/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import requests

from spotdl.download.config import DownloadConfig
from spotdl.providers.audio.base import AudioProvider
from spotdl.types.result import Result
from spotdl.utils.config import GlobalConfig

__all__ = ["BandCamp"]

Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, artist_id: int, track_id: int):
+ str(track_id)
+ "&tralbum_type=t",
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)
result = response.json()
self.track_id = result["id"]
Expand All @@ -92,7 +92,7 @@ def __init__(self, artist_id: int, track_id: int):
+ str(self.track_id)
+ "&tralbum_type=t",
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)
rjson = resp.json()
self.lyrics = rjson["lyrics"][str(self.track_id)]
Expand Down Expand Up @@ -146,7 +146,7 @@ def search(search_string: str = ""):
+ search_string
+ "&param_with_locations=true",
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)

results = response.json()["results"]
Expand All @@ -168,16 +168,6 @@ class BandCamp(AudioProvider):
SUPPORTS_ISRC = False
GET_RESULTS_OPTS: List[Dict[str, Any]] = [{}]

def __init__(self, *args: Any, **kwargs: Any) -> None:
"""
Initialize the SoundCloud API
### Arguments
- args: Arguments passed to the `AudioProvider` class.
- kwargs: Keyword arguments passed to the `AudioProvider` class.
"""

super().__init__(*args, **kwargs)

def get_results(self, search_term: str, *_args, **_kwargs) -> List[Result]:
"""
Expand Down
5 changes: 2 additions & 3 deletions spotdl/providers/audio/piped.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import requests
from yt_dlp import YoutubeDL

from spotdl.download.config import DownloadConfig
from spotdl.providers.audio.base import ISRC_REGEX, AudioProvider, YTDLLogger
from spotdl.types.result import Result
from spotdl.utils.config import get_temp_path
from spotdl.utils.config import GlobalConfig, get_temp_path
from spotdl.utils.formatter import args_to_ytdlp_options

__all__ = ["Piped"]
Expand Down Expand Up @@ -149,7 +148,7 @@ def get_download_metadata(self, url: str, download: bool = False) -> Dict:
piped_data = requests.get(
f"https://pipedapi.kavin.rocks/streams/{url_id}",
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
).json()

yt_dlp_json = {
Expand Down
4 changes: 2 additions & 2 deletions spotdl/providers/audio/sliderkz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import requests

from spotdl.download.config import DownloadConfig
from spotdl.providers.audio.base import AudioProvider
from spotdl.types.result import Result
from spotdl.utils.config import GlobalConfig

__all__ = ["SliderKZ"]

Expand Down Expand Up @@ -50,7 +50,7 @@ def get_results(self, search_term: str, *_args, **_kwargs) -> List[Result]:
url="https://slider.kz/vk_auth.php?q=" + search_term,
headers=HEADERS,
timeout=5,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)

# Check if the response is valid
Expand Down
2 changes: 1 addition & 1 deletion spotdl/providers/lyrics/azlyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):

self.x_code = js_code[start_index : start_index + end_index]

def get_results(self, name: str, artists: List[str], **kwargs) -> Dict[str, str]:
def get_results(self, name: str, artists: List[str], **_) -> Dict[str, str]:
"""
Returns the results for the given song.
Expand Down
8 changes: 4 additions & 4 deletions spotdl/providers/lyrics/genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import requests
from bs4 import BeautifulSoup

from spotdl.download.config import DownloadConfig
from spotdl.providers.lyrics.base import LyricsProvider
from spotdl.utils.config import GlobalConfig

__all__ = ["Genius"]

Expand Down Expand Up @@ -53,7 +53,7 @@ def get_results(self, name: str, artists: List[str], **_) -> Dict[str, str]:
params={"q": title},
headers=self.headers,
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)

results: Dict[str, str] = {}
Expand All @@ -79,7 +79,7 @@ def extract_lyrics(self, url: str, **_) -> Optional[str]:
url,
headers=self.headers,
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)
url = song_response.json()["response"]["song"]["url"]

Expand All @@ -90,7 +90,7 @@ def extract_lyrics(self, url: str, **_) -> Optional[str]:
url,
headers=self.headers,
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)

if not genius_page_response.ok:
Expand Down
8 changes: 4 additions & 4 deletions spotdl/providers/lyrics/musixmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import requests
from bs4 import BeautifulSoup

from spotdl.download.config import DownloadConfig
from spotdl.providers.lyrics.base import LyricsProvider
from spotdl.utils.config import GlobalConfig

__all__ = ["MusixMatch"]

Expand All @@ -19,7 +19,7 @@ class MusixMatch(LyricsProvider):
MusixMatch lyrics provider class.
"""

def extract_lyrics(self, url: str, **kwargs) -> Optional[str]:
def extract_lyrics(self, url: str, **_) -> Optional[str]:
"""
Extracts the lyrics from the given url.
Expand All @@ -35,7 +35,7 @@ def extract_lyrics(self, url: str, **kwargs) -> Optional[str]:
url,
headers=self.headers,
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)

lyrics_soup = BeautifulSoup(lyrics_resp.text, "html.parser")
Expand Down Expand Up @@ -75,7 +75,7 @@ def get_results(self, name: str, artists: List[str], **kwargs) -> Dict[str, str]
search_url,
headers=self.headers,
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
)
search_soup = BeautifulSoup(search_resp.text, "html.parser")
song_url_tag = search_soup.select("a[href^='/lyrics/']")
Expand Down
24 changes: 24 additions & 0 deletions spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ def modernize_settings(options: DownloaderOptions):
options["restrict"] = "strict"


class GlobalConfig:
"""
Class to store global configuration
"""

parameters: Dict[str, Any] = {}

@classmethod
def set_parameter(cls, key, value):
"""
Set a parameter for the download config
"""

cls.parameters[key] = value

@classmethod
def get_parameter(cls, key):
"""
Get a parameter from the download config
"""

return cls.parameters.get(key, None)


SPOTIFY_OPTIONS: SpotifyOptions = {
"client_id": "5f573c9620494bae87890c0f08a60293",
"client_secret": "212476d9b0f3472eaa762d90b19b0ba8",
Expand Down
3 changes: 0 additions & 3 deletions spotdl/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ class SpotdlHandler(RichHandler):
To not highlight keywords in info messages
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def render_message(
self, record: logging.LogRecord, message: str
) -> "ConsoleRenderable":
Expand Down
4 changes: 2 additions & 2 deletions spotdl/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
from mutagen.mp4 import MP4Cover
from mutagen.wave import WAVE

from spotdl.download.config import DownloadConfig
from spotdl.types.song import Song
from spotdl.utils.config import GlobalConfig
from spotdl.utils.formatter import to_ms

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -275,7 +275,7 @@ def embed_cover(audio_file, song: Song, encoding: str):
cover_data = requests.get(
song.cover_url,
timeout=10,
proxies=DownloadConfig.get_parameter("proxies"),
proxies=GlobalConfig.get_parameter("proxies"),
).content
except Exception:
return audio_file
Expand Down
Loading

0 comments on commit bb16521

Please sign in to comment.