Skip to content

Commit 5812cb6

Browse files
add error handling
1 parent 39a0ce9 commit 5812cb6

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ selenium or playwright
240240
- [ ] Update checker option to perform update
241241
- [ ] Watchlist
242242
- [ ] New anime/series Notifications
243-
- [ ] Image preview (Kitty protocol, iterm protocol, Sixel, textual-web)
244243
- [ ] Use something like opencv to time match a sub from aniworld with a high quality video form another site.
245244
- [ ] Nix package
246245
- [ ] Docker image
@@ -271,7 +270,6 @@ selenium or playwright
271270

272271
### Bugs & DX
273272

274-
- [ ] Proper error handling
275273
- [ ] Logging and Crash reports
276274
- [ ] Blacklist detection & bypass
277275
- [ ] 404 detection inside Hoster and don't crash whole program on http error + crash reports/logs

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.5"
4+
__version__ = "0.3.6"

src/gucken/gucken.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,41 @@ def hoster_sort_key(_hoster: str) -> int:
100100
return sorted(hoster_list, key=hoster_sort_key)
101101

102102

103-
async def get_working_direct_link(hosters: list[Hoster]) -> Union[DirectLink, None]:
103+
async def get_working_direct_link(hosters: list[Hoster], app: "GuckenApp") -> Union[DirectLink, None]:
104104
for hoster in hosters:
105-
direct_link = await hoster.get_direct_link()
105+
name = type(hoster).__name__
106+
try:
107+
direct_link = await hoster.get_direct_link()
108+
except Exception:
109+
logging.warning(
110+
"%s: failed to retrieve video URL from: \"%s\"",
111+
name,
112+
hoster.url,
113+
exc_info=True
114+
)
115+
app.notify(
116+
"Failed to retrieve video URL",
117+
title=f"{name} error",
118+
severity="warning",
119+
)
120+
continue
121+
if direct_link is None:
122+
logging.warning(
123+
"%s: failed to retrieve video URL from: \"%s\"",
124+
name,
125+
hoster.url,
126+
exc_info=True
127+
)
128+
app.notify(
129+
"Failed to retrieve video URL",
130+
title=f"{name} error",
131+
severity="warning",
132+
)
133+
continue
106134
is_working = await direct_link.check_is_working()
107135
logging.info(
108136
'Check: "%s" Working: "%s" URL: "%s"',
109-
type(hoster).__name__,
137+
name,
110138
is_working,
111139
direct_link,
112140
)
@@ -716,7 +744,7 @@ async def play(
716744

717745
lang = sort_favorite_lang(episode.available_language, self.language)[0]
718746
sorted_hoster = sort_favorite_hoster(processed_hoster.get(lang), self.hoster)
719-
direct_link = await get_working_direct_link(sorted_hoster)
747+
direct_link = await get_working_direct_link(sorted_hoster, self)
720748

721749
# TODO: check for header support
722750
syncplay = gucken_settings_manager.settings["settings"]["syncplay"]

src/gucken/hoster/common.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ def has_headers(self) -> bool:
2929
return False
3030

3131

32-
@dataclass
33-
class EmptyDirectLink(DirectLink):
34-
url: str = None
35-
36-
async def check_is_working(self) -> bool:
37-
return False
38-
3932
@dataclass
4033
class Hoster:
4134
url: str

src/gucken/hoster/filemoon.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import logging
21
from re import compile as re_compile
32

4-
from .common import DirectLink, Hoster, EmptyDirectLink
3+
from .common import DirectLink, Hoster
54
from ..networking import AsyncClient
65
from ..packer import unpack
76

@@ -33,6 +32,3 @@ async def get_direct_link(self) -> DirectLink:
3332
video_match = VIDEO_URL_REGEX.search(unpacked)
3433
if video_match:
3534
return DirectLink(video_match.group(1))
36-
37-
logging.warning("Filemoon: failed to retrieve video URL from: \"%s\"", self.url)
38-
return EmptyDirectLink()

0 commit comments

Comments
 (0)