Skip to content

Commit

Permalink
Sort search results
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandcracker committed May 27, 2024
1 parent 3b81163 commit bd46bbd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ termux-setup-storage
- [x] Browsing
- [x] Descriptions
- [x] Watching
- [ ] Trailer
- [x] Automatically start next episode
- [x] Discord Presence **Very WIP**
- [MPV] only
Expand Down Expand Up @@ -241,6 +242,10 @@ Place your custom CSS in `user_config_path("gucken").joinpath("custom.css")` and
- [ ] More CLI args
- [ ] reverse proxy
- [ ] Chapters for VLC
- [ ] DoH support
- [ ] More threads and asyncio.gather to make everything faster
- [ ] Watchlist
- [ ] Notifications

[Anime4k]: https://github.com/bloc97/Anime4K
[MPV]: https://mpv.io/
Expand Down
2 changes: 1 addition & 1 deletion src/gucken/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.10"
__version__ = "0.1.11"
34 changes: 18 additions & 16 deletions src/gucken/gucken.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from time import sleep, time
from typing import ClassVar, List, Union

from fuzzywuzzy import fuzz
from platformdirs import user_config_path, user_log_path
from pypresence import AioPresence, DiscordNotFound
from rich.markup import escape
Expand Down Expand Up @@ -479,19 +480,21 @@ async def lookup_anime(self, keyword: str) -> None:
for e in l:
final_results.append(e)

# TODO: Sort final_results with fuzzy-sort
# from fuzzywuzzy import process process.extract()
def fuzzy_sort_key(result):
return fuzz.ratio(keyword, result.name)

final_results = sorted(final_results, key=fuzzy_sort_key, reverse=True)
if len(final_results) > 0:
self.current = final_results
items = []
for series in final_results:
# TODO: show provider
await results_list_view.append(
ClickableListItem(
items.append(ClickableListItem(
Markdown(
f"##### {series.name} {series.production_year}\n{series.description}"
f"##### {series.name} {series.production_year} [{series.provider_name}]"
f"\n{series.description}"
)
)
)
))
await results_list_view.extend(items)
results_list_view.loading = False
if len(final_results) > 0:

Expand Down Expand Up @@ -598,7 +601,7 @@ async def update_check(self):
async def play(
self, series_search_result: SearchResult, episodes: list[Episode], index: int
) -> None:
p = self.query_one("#player", Select).value
p = gucken_settings_manager.settings["settings"]["player"]["player"]
if p == Select.BLANK:
_player = self.detected_player
else:
Expand Down Expand Up @@ -637,9 +640,8 @@ async def play(
direct_link = await get_working_direct_link(sorted_hoster)

# TODO: check for header support
# TODO: pass ani_skip as script
syncplay = self.query_one("#syncplay", RadioButton).value
fullscreen = self.query_one("#fullscreen", RadioButton).value
syncplay = gucken_settings_manager.settings["settings"]["syncplay"]
fullscreen = gucken_settings_manager.settings["settings"]["fullscreen"]

title = f"{series_search_result.name} S{episode.season}E{episode.episode_number} - {episode.title}"
args = _player.play(direct_link.url, title, fullscreen, direct_link.headers)
Expand Down Expand Up @@ -675,9 +677,9 @@ async def update():
# TODO: Support based on mpv
# TODO: recover start --start=00:56
if isinstance(_player, MPVPlayer) or isinstance(_player, VLCPlayer):
ani_skip_opening = self.query_one("#ani_skip_opening", RadioButton).value
ani_skip_ending = self.query_one("#ani_skip_ending", RadioButton).value
ani_skip_chapters = self.query_one("#ani_skip_chapters", RadioButton).value
ani_skip_opening = gucken_settings_manager.settings["settings"]["ani_skip"]["skip_opening"]
ani_skip_ending = gucken_settings_manager.settings["settings"]["ani_skip"]["skip_ending"]
ani_skip_chapters = gucken_settings_manager.settings["settings"]["ani_skip"]["chapters"]

if ani_skip_opening or ani_skip_ending or ani_skip_chapters:
timings = await get_timings_from_search(
Expand Down Expand Up @@ -821,7 +823,7 @@ async def play_next(should_next):
callback=play_next,
)

autoplay = self.query_one("#autoplay", RadioButton).value
autoplay = gucken_settings_manager.settings["settings"]["autoplay"]["enabled"]
if not len(episodes) <= index + 1:
if autoplay is True:
self.app.call_later(push_next_screen)
Expand Down
21 changes: 13 additions & 8 deletions src/gucken/provider/aniworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ class AniWorldSeries(Series):
tags: set[str]

def to_markdown(self) -> str:
return (
f"# {self.name} {self.production_year}\n{self.full_description}\n\n"
f"**Regisseure**: {', '.join(self.regisseure)}\\\n"
f"**Schauspieler**: {', '.join(self.schauspieler)}\\\n"
f"**Produzent**: {', '.join(self.produzent)}\\\n"
f"**Land**: {', '.join(self.land)}\\\n"
f"**Tags**: {', '.join(self.tags)}"
)
string_builder = [f"# {self.name} {self.production_year}\n{self.full_description}\n\n"]
if len(self.regisseure) > 0:
string_builder.append(f"**Regisseure**: {', '.join(self.regisseure)}\\\n")
if len(self.schauspieler) > 0:
string_builder.append(f"**Schauspieler**: {', '.join(self.schauspieler)}\\\n")
if len(self.produzent) > 0:
string_builder.append(f"**Produzent**: {', '.join(self.produzent)}\\\n")
if len(self.land) > 0:
string_builder.append(f"**Land**: {', '.join(self.land)}\\\n")
if len(self.tags) > 0:
string_builder.append(f"**Tags**: {', '.join(self.tags)}")
return "".join(string_builder)


@dataclass
Expand Down Expand Up @@ -136,6 +140,7 @@ async def search(keyword: str) -> Union[list[AniWorldSearchResult], None]:
for series in results:
search_results.append(
AniWorldSearchResult(
provider_name="aniworld.to",
name=unescape(series.get("name")).strip(),
link=series.get("link"),
description=unescape(series.get("description")),
Expand Down
1 change: 1 addition & 0 deletions src/gucken/provider/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SearchResult:
name: str
description: str = None
cover: str = None
provider_name: str = None

@abstractmethod
async def get_series(self) -> Series:
Expand Down
21 changes: 13 additions & 8 deletions src/gucken/provider/serienstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ class SerienStreamSeries(Series):
tags: set[str]

def to_markdown(self) -> str:
return (
f"# {self.name} {self.production_year}\n{self.full_description}\n\n"
f"**Regisseure**: {', '.join(self.regisseure)}\\\n"
f"**Schauspieler**: {', '.join(self.schauspieler)}\\\n"
f"**Produzent**: {', '.join(self.produzent)}\\\n"
f"**Land**: {', '.join(self.land)}\\\n"
f"**Tags**: {', '.join(self.tags)}"
)
string_builder = [f"# {self.name} {self.production_year}\n{self.full_description}\n\n"]
if len(self.regisseure) > 0:
string_builder.append(f"**Regisseure**: {', '.join(self.regisseure)}\\\n")
if len(self.schauspieler) > 0:
string_builder.append(f"**Schauspieler**: {', '.join(self.schauspieler)}\\\n")
if len(self.produzent) > 0:
string_builder.append(f"**Produzent**: {', '.join(self.produzent)}\\\n")
if len(self.land) > 0:
string_builder.append(f"**Land**: {', '.join(self.land)}\\\n")
if len(self.tags) > 0:
string_builder.append(f"**Tags**: {', '.join(self.tags)}")
return "".join(string_builder)


@dataclass
Expand Down Expand Up @@ -137,6 +141,7 @@ async def search(keyword: str) -> Union[list[SerienStreamSearchResult], None]:
for series in results:
search_results.append(
SerienStreamSearchResult(
provider_name="serienstream.to",
name=unescape(series.get("name")).strip(),
link=series.get("link"),
description=unescape(series.get("description")),
Expand Down

0 comments on commit bd46bbd

Please sign in to comment.