Skip to content

Commit

Permalink
Fixed subdivx provider after recent changes to their website. #2686
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 committed Sep 30, 2024
1 parent bd3d1e5 commit a1fac16
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions custom_libs/subliminal_patch/providers/subdivx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
import re

from requests import Session
from subliminal import __short_version__
from subliminal.video import Episode
from subliminal.video import Movie
from subliminal import ProviderError
from subliminal.video import Episode, Movie
from subliminal_patch.exceptions import APIThrottled
from subliminal_patch.providers import Provider
from subliminal_patch.providers.utils import get_archive_from_bytes
from subliminal_patch.providers.utils import get_subtitle_from_archive
from subliminal_patch.providers.utils import update_matches
from subliminal_patch.providers.utils import USER_AGENTS
from subliminal_patch.providers.utils import (get_archive_from_bytes, get_subtitle_from_archive, update_matches,
USER_AGENTS)
from subliminal_patch.subtitle import Subtitle
from subzero.language import Language

Expand Down Expand Up @@ -111,7 +108,6 @@ def __init__(self):
self.session = Session()

def initialize(self):
# self.session.headers["User-Agent"] = f"Subliminal/{__short_version__}"
self.session.headers["User-Agent"] = random.choice(USER_AGENTS)
self.session.cookies.update({"iduser_cookie": _IDUSER_COOKIE})

Expand Down Expand Up @@ -166,9 +162,26 @@ def _query(self, video, languages):
return subtitles

def _query_results(self, query, video):
token_link = f"{_SERVER_URL}/inc/gt.php?gt=1"

token_response = self.session.get(token_link, timeout=30)

if token_response.status_code != 200:
raise ProviderError("Unable to obtain a token")

try:
token_response_json = token_response.json()
except JSONDecodeError:
raise ProviderError("Unable to parse JSON response")
else:
if 'token' in token_response_json and token_response_json['token']:
token = token_response_json['token']
else:
raise ProviderError("Response doesn't include a token")

search_link = f"{_SERVER_URL}/inc/ajax.php"

payload = {"tabla": "resultados", "filtros": "", "buscar": query}
payload = {"tabla": "resultados", "filtros": "", "buscar393": query, "token": token}

logger.debug("Query: %s", query)

Expand Down Expand Up @@ -197,7 +210,7 @@ def _query_results(self, query, video):
# Iterate over each subtitle in the response
for item in data["aaData"]:
id = item["id"]
page_link = f"{_SERVER_URL}/descargar.php?id={id}"
page_link = f"{_SERVER_URL}/{id}"
title = _clean_title(item["titulo"])
description = item["descripcion"]
uploader = item["nick"]
Expand Down

0 comments on commit a1fac16

Please sign in to comment.