Skip to content

Commit

Permalink
Save .syncedlyrics in cache dir of the os
Browse files Browse the repository at this point in the history
  • Loading branch information
moehmeni committed Jul 27, 2024
1 parent 41fb47d commit bc97f85
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions syncedlyrics/providers/musixmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os
from .base import LRCProvider
from ..utils import Lyrics, get_best_match, format_time
from ..utils import Lyrics, get_best_match, format_time, get_cache_path

# Inspired from https://github.com/Marekkon5/onetagger/blob/0654131188c4df2b4b171ded7cdb927a4369746e/crates/onetagger-platforms/src/musixmatch.rs
# Huge part converted from Rust to Py by ChatGPT :)
Expand Down Expand Up @@ -36,10 +36,9 @@ def _get(self, action: str, query: List[tuple]):
return response

def _get_token(self):
# Check if token is cached and not expired
token_path = os.path.join(".syncedlyrics", "musixmatch_token.json")
token_path = get_cache_path("syncedlyrics", False) / "musixmatch_token.json"
current_time = int(time.time())
if os.path.exists(token_path):
if token_path.exists():
with open(token_path, "r") as token_file:
cached_token_data = json.load(token_file)
cached_token = cached_token_data.get("token")
Expand All @@ -57,7 +56,7 @@ def _get_token(self):
# Cache the new token
self.token = new_token
token_data = {"token": new_token, "expiration_time": expiration_time}
os.makedirs(".syncedlyrics", exist_ok=True)
token_path.parent.mkdir(parents=True, exist_ok=True)
with open(token_path, "w") as token_file:
json.dump(token_data, token_file)

Expand Down

0 comments on commit bc97f85

Please sign in to comment.