Skip to content

Commit

Permalink
fixes (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat authored Oct 13, 2023
1 parent 554dab6 commit 698983a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def __init__(

found_files = gather_known_songs(self.settings["output"], scan_format)

logger.debug("Found %s %s files", len(found_files), scan_format)

for song_url, song_paths in found_files.items():
known_paths = self.known_songs.get(song_url)
if known_paths is None:
Expand Down
1 change: 0 additions & 1 deletion spotdl/providers/audio/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class BandCamp(AudioProvider):
SUPPORTS_ISRC = False
GET_RESULTS_OPTS: List[Dict[str, Any]] = [{}]


def get_results(self, search_term: str, *_args, **_kwargs) -> List[Result]:
"""
Get results from slider.kz
Expand Down
43 changes: 33 additions & 10 deletions spotdl/providers/lyrics/azlyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ def __init__(self):
self.session = requests.Session()
self.session.headers.update(self.headers)

self.session.get("https://www.azlyrics.com/")

resp = self.session.get("https://www.azlyrics.com/geo.js")

# extract value from js code
js_code = resp.text
start_index = js_code.find('value"') + 9
end_index = js_code[start_index:].find('");')

self.x_code = js_code[start_index : start_index + end_index]
self.x_code = self.get_x_code()

def get_results(self, name: str, artists: List[str], **_) -> Dict[str, str]:
"""
Expand All @@ -47,6 +38,12 @@ def get_results(self, name: str, artists: List[str], **_) -> Dict[str, str]:
- A dictionary with the results. (The key is the title and the value is the url.)
"""

if self.x_code is None:
self.x_code = self.get_x_code()

if self.x_code is None:
return {}

# Join every artist by comma in artists
artist_str = ", ".join(artist for artist in artists if artist)

Expand Down Expand Up @@ -122,3 +119,29 @@ def extract_lyrics(self, url: str, **_) -> Optional[str]:
lyrics = lyrics_div.get_text().strip()

return lyrics

def get_x_code(self) -> Optional[str]:
"""
Returns the x_code used by AZLyrics.
### Returns
- The x_code used by AZLyrics or None if it couldn't be retrieved.
"""

x_code = None

try:
self.session.get("https://www.azlyrics.com/")

resp = self.session.get("https://www.azlyrics.com/geo.js")

# extract value from js code
js_code = resp.text
start_index = js_code.find('value"') + 9
end_index = js_code[start_index:].find('");')

x_code = js_code[start_index : start_index + end_index]
except requests.ConnectionError:
pass

return x_code

0 comments on commit 698983a

Please sign in to comment.