Skip to content

Commit 688b3b6

Browse files
Fix VEO and improve error handling
1 parent 5812cb6 commit 688b3b6

File tree

9 files changed

+95
-156
lines changed

9 files changed

+95
-156
lines changed

src/gucken/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import warnings
22
warnings.filterwarnings('ignore', message='Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')
33

4-
__version__ = "0.3.6"
4+
__version__ = "0.3.7"

src/gucken/gucken.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,32 @@ async def get_working_direct_link(hosters: list[Hoster], app: "GuckenApp") -> Un
118118
severity="warning",
119119
)
120120
continue
121-
if direct_link is None:
121+
if not direct_link or not direct_link.url or not isinstance(direct_link.url, str) or not isinstance(direct_link, DirectLink):
122122
logging.warning(
123-
"%s: failed to retrieve video URL from: \"%s\"",
123+
"%s: Returned empty URL: \"%s\"",
124124
name,
125-
hoster.url,
126-
exc_info=True
125+
hoster.url
127126
)
128127
app.notify(
129-
"Failed to retrieve video URL",
128+
"Returned empty URL",
130129
title=f"{name} error",
131130
severity="warning",
132131
)
133132
continue
134133
is_working = await direct_link.check_is_working()
135-
logging.info(
136-
'Check: "%s" Working: "%s" URL: "%s"',
137-
name,
138-
is_working,
139-
direct_link,
140-
)
141134
if is_working:
142135
return direct_link
136+
else:
137+
logging.warning(
138+
"%s: Video URL is not working: \"%s\"",
139+
name,
140+
direct_link.url or "None"
141+
)
142+
app.notify(
143+
"Video URL is not working",
144+
title=f"{name} error",
145+
severity="warning",
146+
)
143147
return None
144148

145149

src/gucken/hoster/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class DirectLink:
1111
force_hls: bool = False
1212

1313
async def check_is_working(self) -> bool:
14+
if not self.url:
15+
return False
1416
try:
1517
async with AsyncClient(verify=False) as client:
1618
response = await client.head(

src/gucken/hoster/veo.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
REDIRECT_PATTERN = re_compile("https?://[^'\"<>]+")
1111

12-
# Credit
12+
# Modified
1313
# https://github.com/wolfswolke/aniworld_scraper/blob/41bd0f23cbc02352481dd92e6d986d1fe30c76bf/src/logic/search_for_links.py#L23
1414

1515
def deb_func1(input_string):
@@ -56,17 +56,8 @@ def deb_func(input_var):
5656

5757
def find_script_element(raw_html):
5858
soup = BeautifulSoup(raw_html, features="html.parser")
59-
script_object = soup.find_all("script")
60-
obfuscated_string = ""
61-
for script in script_object:
62-
script = str(script)
63-
if "KGMAaM=" in script:
64-
obfuscated_string = script
65-
break
66-
if obfuscated_string == "":
67-
return None
68-
obfuscated_string = obfuscated_string.split('MKGMa="')[1]
69-
obfuscated_string = obfuscated_string.split('"')[0]
59+
script_object = soup.find("script", type="application/json")
60+
obfuscated_string = script_object.text[2:-2]
7061
output = deb_func(obfuscated_string)
7162
return output["source"]
7263

src/gucken/provider/aniworld.py

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,33 @@
1919
from ..utils import json_loads
2020
from ..utils import fully_unescape
2121

22+
HOSTER_MAP = {
23+
"VOE": VOEHoster,
24+
"Doodstream": DoodstreamHoster,
25+
"Vidoza": VidozaHoster,
26+
"Streamtape": StreamtapeHoster,
27+
"SpeedFiles": SpeedFilesHoster,
28+
"Filemoon": FilemoonHoster,
29+
"Luluvdo": LuluvdoHoster,
30+
"Vidmoly": VidmolyHoster,
31+
"LoadX": LoadXHoster
32+
}
33+
34+
LANGUAGE_MAP = {
35+
"english": Language.EN,
36+
"english-german": Language.EN_DESUB,
37+
"japanese-english": Language.JP_ENSUB,
38+
"japanese-german": Language.JP_DESUB,
39+
"german": Language.DE
40+
}
41+
2242
def provider_to_hoster(provider: str, url: str) -> Hoster:
23-
if provider == "VOE":
24-
return VOEHoster(url)
25-
if provider == "Doodstream":
26-
return DoodstreamHoster(url)
27-
if provider == "Vidoza":
28-
return VidozaHoster(url)
29-
if provider == "Streamtape":
30-
return StreamtapeHoster(url)
31-
if provider == "SpeedFiles":
32-
return SpeedFilesHoster(url)
33-
if provider == "Filemoon":
34-
return FilemoonHoster(url)
35-
if provider == "Luluvdo":
36-
return LuluvdoHoster(url)
37-
if provider == "Vidmoly":
38-
return VidmolyHoster(url)
39-
if provider == "LoadX":
40-
return LoadXHoster(url)
43+
if provider in HOSTER_MAP:
44+
return HOSTER_MAP[provider](url)
4145

4246

4347
def lang_img_src_lang_name_to_lang(name: str) -> Language:
44-
if name == "english":
45-
return Language.EN
46-
if name == "english-german":
47-
return Language.EN_DESUB
48-
if name == "japanese-english":
49-
return Language.JP_ENSUB
50-
if name == "japanese-german":
51-
return Language.JP_DESUB
52-
if name == "german":
53-
return Language.DE
48+
return LANGUAGE_MAP[name]
5449

5550

5651
@dataclass
@@ -283,24 +278,8 @@ async def get_episodes_from_soup(
283278
hoster = set()
284279
for h in episode.find_all_next("i", class_="icon"):
285280
t = h.attrs.get("title")
286-
if t == "VOE":
287-
hoster.add(VOEHoster)
288-
if t == "Doodstream":
289-
hoster.add(DoodstreamHoster)
290-
if t == "Vidoza":
291-
hoster.add(VidozaHoster)
292-
if t == "Streamtape":
293-
hoster.add(StreamtapeHoster)
294-
if t == "SpeedFiles":
295-
hoster.add(SpeedFilesHoster)
296-
if t == "Filemoon":
297-
hoster.add(FilemoonHoster)
298-
if t == "Luluvdo":
299-
hoster.add(LuluvdoHoster)
300-
if t == "Vidmoly":
301-
hoster.add(VidmolyHoster)
302-
if t == "LoadX":
303-
hoster.add(LoadXHoster)
281+
if t in HOSTER_MAP:
282+
hoster.add(HOSTER_MAP[t])
304283

305284
e_count += 1
306285
title_en = fully_unescape(title.find("span").text.strip())

src/gucken/provider/serienstream.py

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,33 @@
2727
headers = {"Host": "serienstream.to"}
2828
extensions = {"sni_hostname": "serienstream.to"}
2929

30+
HOSTER_MAP = {
31+
"VOE": VOEHoster,
32+
"Doodstream": DoodstreamHoster,
33+
"Vidoza": VidozaHoster,
34+
"Streamtape": StreamtapeHoster,
35+
"SpeedFiles": SpeedFilesHoster,
36+
"Filemoon": FilemoonHoster,
37+
"Luluvdo": LuluvdoHoster,
38+
"Vidmoly": VidmolyHoster,
39+
"LoadX": LoadXHoster
40+
}
41+
42+
LANGUAGE_MAP = {
43+
"english": Language.EN,
44+
"english-german": Language.EN_DESUB,
45+
"japanese-english": Language.JP_ENSUB,
46+
"japanese-german": Language.JP_DESUB,
47+
"german": Language.DE
48+
}
3049

3150
def provider_to_hoster(provider: str, url: str) -> Hoster:
32-
if provider == "VOE":
33-
return VOEHoster(url)
34-
if provider == "Doodstream":
35-
return DoodstreamHoster(url)
36-
if provider == "Vidoza":
37-
return VidozaHoster(url)
38-
if provider == "Streamtape":
39-
return StreamtapeHoster(url)
40-
if provider == "SpeedFiles":
41-
return SpeedFilesHoster(url)
42-
if provider == "Filemoon":
43-
return FilemoonHoster(url)
44-
if provider == "Luluvdo":
45-
return LuluvdoHoster(url)
46-
if provider == "Vidmoly":
47-
return VidmolyHoster(url)
48-
if provider == "LoadX":
49-
return LoadXHoster(url)
51+
if provider in HOSTER_MAP:
52+
return HOSTER_MAP[provider](url)
53+
5054

5155
def lang_img_src_lang_name_to_lang(name: str) -> Language:
52-
if name == "english":
53-
return Language.EN
54-
if name == "english-german":
55-
return Language.EN_DESUB
56-
if name == "japanese-english":
57-
return Language.JP_ENSUB
58-
if name == "japanese-german":
59-
return Language.JP_DESUB
60-
if name == "german":
61-
return Language.DE
56+
return LANGUAGE_MAP[name]
6257

6358

6459
@dataclass
@@ -292,24 +287,8 @@ async def get_episodes_from_soup(
292287
hoster = set()
293288
for h in episode.find_all_next("i", class_="icon"):
294289
t = h.attrs.get("title")
295-
if t == "VOE":
296-
hoster.add(VOEHoster)
297-
if t == "Doodstream":
298-
hoster.add(DoodstreamHoster)
299-
if t == "Vidoza":
300-
hoster.add(VidozaHoster)
301-
if t == "Streamtape":
302-
hoster.add(StreamtapeHoster)
303-
if t == "SpeedFiles":
304-
hoster.add(SpeedFilesHoster)
305-
if t == "Filemoon":
306-
hoster.add(FilemoonHoster)
307-
if t == "Luluvdo":
308-
hoster.add(LuluvdoHoster)
309-
if t == "Vidmoly":
310-
hoster.add(VidmolyHoster)
311-
if t == "LoadX":
312-
hoster.add(LoadXHoster)
290+
if t in HOSTER_MAP:
291+
hoster.add(HOSTER_MAP[t])
313292

314293
e_count += 1
315294
title_en = fully_unescape(title.find("span").text.strip())

src/gucken/rome.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ def roman_to_int(roman: str) -> int:
1717
return result
1818

1919

20-
def replace_roman_numerals(text: str) -> str:
21-
def repl(match):
22-
return str(roman_to_int(match.group(0)))
20+
def _repl(match):
21+
return str(roman_to_int(match.group()))
22+
2323

24-
return ROMAN_PATTERN.sub(repl, text)
24+
def replace_roman_numerals(text: str) -> str:
25+
return ROMAN_PATTERN.sub(_repl, text)

src/gucken/update.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dataclasses import dataclass
22
from typing import Union
33

4-
from .networking import AsyncClient
54
from packaging.version import Version
65

76
from . import __version__ as current_version
7+
from .networking import AsyncClient
88
from .utils import json_loads
99

1010
PACKAGE_NAME = "gucken"
@@ -31,7 +31,6 @@ async def check() -> Union[UpdateResult, None]:
3131

3232
def main():
3333
from asyncio import run
34-
3534
print(run(check()))
3635

3736

src/gucken/utils.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#import logging
2-
import os
31
import sys
42
from html import unescape
5-
6-
from typing import Union
7-
from typing import NamedTuple
3+
from os import getenv
4+
from os.path import join, dirname
5+
from typing import Union, NamedTuple
86

97
from .player.android import AndroidChoosePlayer
108
from .player.common import Player
@@ -15,13 +13,15 @@
1513
from .player.wmplayer import WMPlayer
1614

1715
is_android = hasattr(sys, "getandroidapilevel")
16+
is_windows = sys.platform.startswith("win")
17+
is_linux = sys.platform.startswith("linux")
18+
is_mac_os = sys.platform.startswith("darwin")
19+
is_bsd = "freebsd" in sys.platform or sys.platform.startswith("dragonfly")
1820

1921
try:
2022
from orjson import loads as json_loads
21-
# logging.debug("Using orjson")
2223
except ImportError:
2324
from json import loads as json_loads
24-
# logging.debug("Using default json")
2525

2626

2727
def detect_player() -> Union[Player, None]:
@@ -47,51 +47,35 @@ def detect_player() -> Union[Player, None]:
4747
return None
4848

4949

50-
def is_windows():
51-
return sys.platform.startswith("win")
52-
53-
54-
def is_linux():
55-
return sys.platform.startswith("linux")
56-
57-
58-
def is_mac_os():
59-
return sys.platform.startswith("darwin")
60-
61-
62-
def is_bsd():
63-
return "freebsd" in sys.platform or sys.platform.startswith("dragonfly")
64-
65-
6650
class VLCPaths(NamedTuple):
6751
vlc_intf_path: str
6852
vlc_intf_user_path: str
6953
vlc_module_path: str
7054

7155

7256
def get_vlc_intf_user_path(player_path: str) -> VLCPaths:
73-
if is_linux():
57+
if is_linux:
7458
if 'snap' in player_path:
7559
vlc_intf_path = '/snap/vlc/current/usr/lib/vlc/lua/intf/'
76-
vlc_intf_user_path = os.path.join(os.getenv('HOME', '.'), "snap/vlc/current/.local/share/vlc/lua/intf/")
60+
vlc_intf_user_path = join(getenv('HOME', '.'), "snap/vlc/current/.local/share/vlc/lua/intf/")
7761
else:
7862
vlc_intf_path = "/usr/lib/vlc/lua/intf/"
79-
vlc_intf_user_path = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/")
80-
elif is_mac_os():
63+
vlc_intf_user_path = join(getenv('HOME', '.'), ".local/share/vlc/lua/intf/")
64+
elif is_mac_os:
8165
vlc_intf_path = "/Applications/VLC.app/Contents/MacOS/share/lua/intf/"
82-
vlc_intf_user_path = os.path.join(
83-
os.getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/")
84-
elif is_bsd():
66+
vlc_intf_user_path = join(
67+
getenv('HOME', '.'), "Library/Application Support/org.videolan.vlc/lua/intf/")
68+
elif is_bsd:
8569
# *BSD ports/pkgs install to /usr/local by default.
8670
# This should also work for all the other BSDs, such as OpenBSD or DragonFly.
8771
vlc_intf_path = "/usr/local/lib/vlc/lua/intf/"
88-
vlc_intf_user_path = os.path.join(os.getenv('HOME', '.'), ".local/share/vlc/lua/intf/")
72+
vlc_intf_user_path = join(getenv('HOME', '.'), ".local/share/vlc/lua/intf/")
8973
elif "vlcportable.exe" in player_path.lower():
90-
vlc_intf_path = os.path.dirname(player_path).replace("\\", "/") + "/App/vlc/lua/intf/"
74+
vlc_intf_path = dirname(player_path).replace("\\", "/") + "/App/vlc/lua/intf/"
9175
vlc_intf_user_path = vlc_intf_path
9276
else:
93-
vlc_intf_path = os.path.dirname(player_path).replace("\\", "/") + "/lua/intf/"
94-
vlc_intf_user_path = os.path.join(os.getenv('APPDATA', '.'), "VLC\\lua\\intf\\")
77+
vlc_intf_path = dirname(player_path).replace("\\", "/") + "/lua/intf/"
78+
vlc_intf_user_path = join(getenv('APPDATA', '.'), "VLC\\lua\\intf\\")
9579

9680
vlc_module_path = vlc_intf_path + "modules/?.luac"
9781

0 commit comments

Comments
 (0)