refactor: move out some constants from config.py

This commit is contained in:
2026-04-05 01:14:39 +02:00
parent 9d6c2e2113
commit d8c3813e39
2 changed files with 9 additions and 7 deletions
-1
View File
@@ -67,7 +67,6 @@ SPOTIFY_SECRET_URL = (
) )
SPOTIFY_SP_DC = os.environ.get("SPOTIFY_SP_DC", "") SPOTIFY_SP_DC = os.environ.get("SPOTIFY_SP_DC", "")
SPOTIFY_TOKEN_CACHE_FILE = os.path.join(CACHE_DIR, "spotify_token.json") SPOTIFY_TOKEN_CACHE_FILE = os.path.join(CACHE_DIR, "spotify_token.json")
SPOTIFY_APP_VERSION = "1.2.88.21.g8e037c8f"
# Netease api # Netease api
NETEASE_SEARCH_URL = "https://music.163.com/api/cloudsearch/pc" NETEASE_SEARCH_URL = "https://music.163.com/api/cloudsearch/pc"
+9 -6
View File
@@ -31,7 +31,6 @@ from ..models import TrackMeta, LyricResult, CacheStatus
from ..lrc import LRCData from ..lrc import LRCData
from ..config import ( from ..config import (
HTTP_TIMEOUT, HTTP_TIMEOUT,
SPOTIFY_APP_VERSION,
TTL_NOT_FOUND, TTL_NOT_FOUND,
TTL_NETWORK_ERROR, TTL_NETWORK_ERROR,
SPOTIFY_TOKEN_URL, SPOTIFY_TOKEN_URL,
@@ -43,6 +42,13 @@ from ..config import (
UA_BROWSER, UA_BROWSER,
) )
_SPOTIFY_BASE_HEADERS = {
"Referer": "https://open.spotify.com/",
"Origin": "https://open.spotify.com",
"App-Platform": "WebPlayer",
"Spotify-App-Version": "1.2.88.21.g8e037c8f",
}
class SpotifyFetcher(BaseFetcher): class SpotifyFetcher(BaseFetcher):
def __init__(self) -> None: def __init__(self) -> None:
@@ -198,8 +204,8 @@ class SpotifyFetcher(BaseFetcher):
headers = { headers = {
"User-Agent": UA_BROWSER, "User-Agent": UA_BROWSER,
"Accept": "*/*", "Accept": "*/*",
"Referer": "https://open.spotify.com/",
"Cookie": f"sp_dc={SPOTIFY_SP_DC}", "Cookie": f"sp_dc={SPOTIFY_SP_DC}",
**_SPOTIFY_BASE_HEADERS,
} }
async with httpx.AsyncClient(headers=headers) as client: async with httpx.AsyncClient(headers=headers) as client:
@@ -281,10 +287,7 @@ class SpotifyFetcher(BaseFetcher):
"User-Agent": UA_BROWSER, "User-Agent": UA_BROWSER,
"Accept": "application/json", "Accept": "application/json",
"Authorization": f"Bearer {token}", "Authorization": f"Bearer {token}",
"Referer": "https://open.spotify.com/", **_SPOTIFY_BASE_HEADERS,
"App-Platform": "WebPlayer",
"Spotify-App-Version": SPOTIFY_APP_VERSION,
"Origin": "https://open.spotify.com",
} }
try: try: