-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: SubSource | ||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- '.github/workflows/cron-tests-subsource.yml' | ||
schedule: | ||
- cron: '0 7 * * *' | ||
workflow_dispatch: ~ | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: setup-python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: install | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: test | ||
run: | | ||
pytest -v -k 'test_subsource' ./tests/test_suite.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__api = "https://api.subsource.net/api/" | ||
|
||
__getMovie = __api + "getMovie" | ||
__getSub = __api + "getSub" | ||
__search = __api + "searchMovie" | ||
__download = __api + "downloadSub/" | ||
|
||
def __extract_season_episode(core, text): | ||
pattern = core.re.compile(r'(?:S(\d+)|Season\s*(\d+))[^E]*?(?:E(\d+)|Episode\s*(\d+))', core.re.IGNORECASE) | ||
match = pattern.search(text) | ||
|
||
if match: | ||
# Extract season and episode numbers from groups | ||
season = match.group(1) or match.group(2) | ||
episode = match.group(3) or match.group(4) | ||
return (season, episode) | ||
|
||
# If no matches found, attempt to capture episode-like sequences | ||
fallback_pattern = core.re.compile(r'\bE?P?(\d{2,5})\b', core.re.IGNORECASE) | ||
fallback_matches = fallback_pattern.findall(text) | ||
|
||
if fallback_matches: | ||
# Assuming the last number in the fallback matches is the episode number | ||
episode_number = fallback_matches[-1] | ||
return (None, episode_number) | ||
|
||
return (None, None) | ||
|
||
def build_search_requests(core, service_name, meta): | ||
def get_movie(response): | ||
results = response.json() | ||
found = results.get("found", []) | ||
movie_name = "" | ||
|
||
for res in found: | ||
if res.get("type", "Movie") == "Movie" and meta.is_tvshow: | ||
continue | ||
movie_name = res["linkName"] | ||
break | ||
|
||
params = {"movieName": movie_name, "langs": meta.languages} | ||
if meta.is_tvshow: | ||
params["season"] = "season-" + meta.season | ||
return {"method": "POST", "url": __getMovie, "data": params} | ||
|
||
name = (meta.title if meta.is_movie else meta.tvshow) | ||
year = meta.tvshow_year if meta.is_tvshow else meta.year | ||
|
||
params = {"query": name + " " + year} | ||
request = { | ||
"method": "POST", | ||
"url": __search, | ||
"data": params, | ||
"next": lambda gm: get_movie(gm) | ||
} | ||
return [request] | ||
|
||
|
||
def parse_search_response(core, service_name, meta, response): | ||
try: | ||
results = response.json() | ||
except Exception as exc: | ||
core.logger.error("%s - %s" % (service_name, exc)) | ||
return [] | ||
|
||
service = core.services[service_name] | ||
|
||
if "subs" not in results: | ||
return [] | ||
|
||
movie_details = results.get("movie", {}) | ||
|
||
# altname = movie_details.get("altName") | ||
full_name = movie_details.get("fullName", "") | ||
|
||
def map_result(result): | ||
name = result.get("releaseName", "") | ||
lang = result.get("lang") | ||
|
||
if lang not in meta.languages: | ||
return None | ||
|
||
rating = result.get("rating", 0) | ||
lang_code = core.utils.get_lang_id(lang, core.kodi.xbmc.ISO_639_1) | ||
|
||
if meta.is_tvshow: | ||
subtitle_season = core.re.search(r'Season\s(\d+)', full_name) | ||
season, episode = __extract_season_episode(core, name) | ||
season = subtitle_season.group(1).zfill(2) if subtitle_season else season | ||
|
||
if season == meta.season.zfill(2) and episode == meta.episode.zfill(2): | ||
name = meta.filename | ||
elif not season and meta.season == "1" and episode == meta.episode.zfill(2): | ||
name = meta.filename | ||
|
||
return { | ||
"service_name": service_name, | ||
"service": service.display_name, | ||
"lang": lang, | ||
"name": name, | ||
"rating": rating, | ||
"lang_code": lang_code, | ||
"sync": "true" if meta.filename_without_ext in result["releaseName"] else "false", | ||
"impaired": "true" if result.get("hi", 0) != 0 else "false", | ||
"color": "teal", | ||
"action_args": { | ||
"url": result["subId"], | ||
"lang": lang, | ||
"filename": name, | ||
"full_link": result["fullLink"], | ||
}, | ||
} | ||
|
||
return list(map(map_result, results["subs"])) | ||
|
||
|
||
def build_download_request(core, service_name, args): | ||
*_, movie, lang, sub_id = args["full_link"].split("/") | ||
params = {"movie": movie, "lang": lang, "id": sub_id} | ||
|
||
def downloadsub(response): | ||
result = response.json() | ||
download_token = result["sub"]["downloadToken"] | ||
return {"method": "GET", "url": __download + download_token, "stream": True} | ||
|
||
request = { | ||
"method": "POST", | ||
"url": __getSub, | ||
"data": params, | ||
"next": lambda dw: downloadsub(dw) | ||
} | ||
|
||
return request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
d8ee5059ea7680d1c5001bc49d4287ad966f4bc3 | ||
8359e9e740c02c4d115755752d544406f6892c8b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters