feat: implement caching and redirect endpoints for premium live streams
This commit is contained in:
@@ -276,7 +276,30 @@ class Radio357Scraper:
|
||||
self.db.commit()
|
||||
self.logger(f"R357: [{self.requests_made}/{self.hard_limit}] Pomyślnie pobrano {fetched} nowych linków.")
|
||||
|
||||
def update_live_stream_url(self):
|
||||
token = self.get_token()
|
||||
if not token:
|
||||
return
|
||||
|
||||
self.logger("R357: Aktualizacja adresu live stream...")
|
||||
url = "https://stream.radio357.pl/?s=www"
|
||||
try:
|
||||
r = requests.get(url, headers={"User-Agent": "Mozilla/5.0"}, cookies={"token": token}, allow_redirects=False, timeout=5)
|
||||
if r.status_code in (301, 302, 307) and "Location" in r.headers:
|
||||
target_url = r.headers["Location"]
|
||||
config_url = self.db.query(Config).filter_by(key="r357_live_url").first()
|
||||
if not config_url:
|
||||
self.db.add(Config(key="r357_live_url", value=target_url))
|
||||
else:
|
||||
config_url.value = target_url
|
||||
self.db.commit()
|
||||
self.logger(f"R357: Zapisano nowy strumień: {target_url}")
|
||||
except Exception as e:
|
||||
self.logger(f"R357 Błąd podczas pobierania streamu premium: {e}")
|
||||
|
||||
def run_full_sync(self, specific_program_slug=None):
|
||||
self.sync_episodes(specific_program_slug)
|
||||
self.backfill_urls(specific_program_slug)
|
||||
if not specific_program_slug:
|
||||
self.update_live_stream_url()
|
||||
self.logger(f"R357: Koniec. Wysłano zapytania: {self.requests_made}/{self.hard_limit} (w tym backfill ograniczony do {self.backfill_limit}).")
|
||||
|
||||
Reference in New Issue
Block a user