mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
feat:(anime screen):add basic error handling
This commit is contained in:
@@ -19,10 +19,12 @@ class AnimeScreenController:
|
|||||||
def fetch_streams(self, anime_title, is_dub=False, episode="1"):
|
def fetch_streams(self, anime_title, is_dub=False, episode="1"):
|
||||||
if self.view.is_dub:
|
if self.view.is_dub:
|
||||||
is_dub = self.view.is_dub.active
|
is_dub = self.view.is_dub.active
|
||||||
self.view.current_anime_data = self.model.get_anime_data_from_provider(
|
if anime_data := self.model.get_anime_data_from_provider(
|
||||||
anime_title, is_dub
|
anime_title, is_dub
|
||||||
)
|
):
|
||||||
self.view.current_links = self.model.get_episode_streams(episode, is_dub)
|
self.view.current_anime_data = anime_data
|
||||||
|
if current_links := self.model.get_episode_streams(episode, is_dub):
|
||||||
|
self.view.current_links = current_links
|
||||||
# TODO: add auto start
|
# TODO: add auto start
|
||||||
#
|
#
|
||||||
# self.view.current_link = self.view.current_links[0]["gogoanime"][0]
|
# self.view.current_link = self.view.current_links[0]["gogoanime"][0]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from fuzzywuzzy import fuzz
|
from fuzzywuzzy import fuzz
|
||||||
from kivy.cache import Cache
|
from kivy.cache import Cache
|
||||||
|
from kivy.logger import Logger
|
||||||
|
|
||||||
from ..libs.anilist import AniList
|
from ..libs.anilist import AniList
|
||||||
from ..libs.anime_provider.allanime.api import anime_provider
|
from ..libs.anime_provider.allanime.api import anime_provider
|
||||||
@@ -46,55 +47,64 @@ class AnimeScreenModel(BaseScreenModel):
|
|||||||
current_title = ""
|
current_title = ""
|
||||||
|
|
||||||
def get_anime_data_from_provider(self, anime_title: tuple, is_dub, id=None):
|
def get_anime_data_from_provider(self, anime_title: tuple, is_dub, id=None):
|
||||||
if self.current_title == anime_title and self.current_anime_data:
|
try:
|
||||||
return self.current_anime_data
|
if self.current_title == anime_title and self.current_anime_data:
|
||||||
translation_type = "dub" if is_dub else "sub"
|
return self.current_anime_data
|
||||||
search_results = anime_provider.search_for_anime(
|
translation_type = "dub" if is_dub else "sub"
|
||||||
anime_title[0], translation_type
|
search_results = anime_provider.search_for_anime(
|
||||||
)
|
anime_title[0], translation_type
|
||||||
|
|
||||||
if search_results:
|
|
||||||
_search_results = search_results["shows"]["edges"]
|
|
||||||
result = max(
|
|
||||||
_search_results,
|
|
||||||
key=lambda x: anime_title_percentage_match(x["name"], anime_title),
|
|
||||||
)
|
)
|
||||||
self.current_anime_id = result["_id"]
|
|
||||||
self.current_anime_data = anime_provider.get_anime(result["_id"])
|
if search_results:
|
||||||
self.current_title = anime_title
|
_search_results = search_results["shows"]["edges"]
|
||||||
return self.current_anime_data
|
result = max(
|
||||||
return {}
|
_search_results,
|
||||||
|
key=lambda x: anime_title_percentage_match(x["name"], anime_title),
|
||||||
|
)
|
||||||
|
self.current_anime_id = result["_id"]
|
||||||
|
self.current_anime_data = anime_provider.get_anime(result["_id"])
|
||||||
|
self.current_title = anime_title
|
||||||
|
return self.current_anime_data
|
||||||
|
return {}
|
||||||
|
except Exception as e:
|
||||||
|
Logger.info("anime_screen error: %s" % e)
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_episode_streams(self, episode, is_dub):
|
def get_episode_streams(self, episode, is_dub):
|
||||||
translation_type = "dub" if is_dub else "sub"
|
translation_type = "dub" if is_dub else "sub"
|
||||||
|
|
||||||
if cached_episode := Cache.get(
|
try:
|
||||||
"streams.anime", f"{self.current_title}{episode}{is_dub}"
|
if cached_episode := Cache.get(
|
||||||
):
|
"streams.anime", f"{self.current_title}{episode}{is_dub}"
|
||||||
return cached_episode
|
):
|
||||||
if self.current_anime_data:
|
return cached_episode
|
||||||
episode_streams = anime_provider.get_anime_episode(
|
if self.current_anime_data:
|
||||||
self.current_anime_id, episode, translation_type
|
episode_streams = anime_provider.get_anime_episode(
|
||||||
)
|
self.current_anime_id, episode, translation_type
|
||||||
streams = anime_provider.get_episode_streams(episode_streams)
|
)
|
||||||
|
streams = anime_provider.get_episode_streams(episode_streams)
|
||||||
|
|
||||||
if streams:
|
if streams:
|
||||||
_streams = list(streams)
|
_streams = list(streams)
|
||||||
streams = []
|
streams = []
|
||||||
for stream in _streams:
|
for stream in _streams:
|
||||||
streams.append(
|
streams.append(
|
||||||
{
|
{
|
||||||
f"{stream[0]}": [
|
f"{stream[0]}": [
|
||||||
_stream["link"] for _stream in stream[1]["links"]
|
_stream["link"] for _stream in stream[1]["links"]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Cache.append(
|
Cache.append(
|
||||||
"streams.anime",
|
"streams.anime",
|
||||||
f"{self.current_title}{episode}{is_dub}",
|
f"{self.current_title}{episode}{is_dub}",
|
||||||
streams,
|
streams,
|
||||||
)
|
)
|
||||||
return streams
|
return streams
|
||||||
|
return []
|
||||||
|
except Exception as e:
|
||||||
|
Logger.info("anime_screen error: %s" % e)
|
||||||
|
return []
|
||||||
|
|
||||||
# should return {type:{provider:streamlink}}
|
# should return {type:{provider:streamlink}}
|
||||||
|
|
||||||
|
|||||||
0
fastanime/Utility/downloader/__init__.py
Normal file
0
fastanime/Utility/downloader/__init__.py
Normal file
0
fastanime/View/AnimeScreen/__init__.py
Normal file
0
fastanime/View/AnimeScreen/__init__.py
Normal file
0
fastanime/View/DownloadsScreen/__init__.py
Normal file
0
fastanime/View/DownloadsScreen/__init__.py
Normal file
0
fastanime/View/MylistScreen/__init__.py
Normal file
0
fastanime/View/MylistScreen/__init__.py
Normal file
0
fastanime/View/SearchScreen/__init__.py
Normal file
0
fastanime/View/SearchScreen/__init__.py
Normal file
0
fastanime/libs/anime_provider/__init__.py
Normal file
0
fastanime/libs/anime_provider/__init__.py
Normal file
0
fastanime/libs/mpv/__init__.py
Normal file
0
fastanime/libs/mpv/__init__.py
Normal file
@@ -1,33 +0,0 @@
|
|||||||
[build-system]
|
|
||||||
requires = ["setuptools"]
|
|
||||||
build-backend = "setuptools.build_meta"
|
|
||||||
[project]
|
|
||||||
name = "AniXStream"
|
|
||||||
version = "0.0.1"
|
|
||||||
authors = [
|
|
||||||
{ name="Benex254", email="benexprojects@gmail.com" },
|
|
||||||
]
|
|
||||||
description = "A wrapper over all and every anime cli or package"
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.10"
|
|
||||||
classifiers = [
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Operating System :: OS Independent",
|
|
||||||
]
|
|
||||||
dependencies = [
|
|
||||||
"kivy",
|
|
||||||
"plyer",
|
|
||||||
"fuzzywuzzy",
|
|
||||||
"python-Levenshtein",
|
|
||||||
"kivymd @ https://github.com/kivymd/KivyMD/archive/master.zip",
|
|
||||||
"ffpyplayer",
|
|
||||||
"pytube",
|
|
||||||
"animdl"
|
|
||||||
]
|
|
||||||
[project.urls]
|
|
||||||
Homepage = "https://github.com/benex254/aniXstream"
|
|
||||||
Issues = "https://github.com/benex254/aniXstream"
|
|
||||||
[project.scripts]
|
|
||||||
anixstream="anixstream.__main__:run_app"
|
|
||||||
|
|
||||||
@@ -5,4 +5,3 @@ plyer
|
|||||||
https://github.com/kivymd/KivyMD/archive/master.zip
|
https://github.com/kivymd/KivyMD/archive/master.zip
|
||||||
fuzzywuzzy
|
fuzzywuzzy
|
||||||
python-Levenshtein
|
python-Levenshtein
|
||||||
dotenv
|
|
||||||
|
|||||||
60
setup.py
Normal file
60
setup.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
assert sys.version_info >= (3, 10, 0), "FastAnime requires python 3.10+"
|
||||||
|
|
||||||
|
path = os.path.abspath(".")
|
||||||
|
|
||||||
|
kv_file_paths = []
|
||||||
|
|
||||||
|
app_dir = os.path.join(path, "fastanime")
|
||||||
|
print(app_dir)
|
||||||
|
|
||||||
|
views_folder = os.path.join(app_dir, "View")
|
||||||
|
for dirpath, dirnames, filenames in os.walk(views_folder):
|
||||||
|
for filename in filenames:
|
||||||
|
if os.path.splitext(filename)[1] == ".kv":
|
||||||
|
kv_file = os.path.join(dirpath, filename)
|
||||||
|
kv_file_paths.append(kv_file)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
setup(
|
||||||
|
version="0.2.0",
|
||||||
|
packages=[
|
||||||
|
*find_packages(
|
||||||
|
include=[
|
||||||
|
"fastanime",
|
||||||
|
"fastanime.*",
|
||||||
|
"fastanime.Utility.*",
|
||||||
|
"fastanime.libs.*",
|
||||||
|
]
|
||||||
|
),
|
||||||
|
],
|
||||||
|
package_dir={"fastanime": "fastanime"},
|
||||||
|
package_data={
|
||||||
|
"fastanime": [
|
||||||
|
"assets/*",
|
||||||
|
"configs/*",
|
||||||
|
*kv_file_paths,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
install_requires=[
|
||||||
|
"kivy",
|
||||||
|
"plyer",
|
||||||
|
"fuzzywuzzy",
|
||||||
|
"python-Levenshtein",
|
||||||
|
"kivymd @ https://github.com/kivymd/KivyMD/archive/master.zip",
|
||||||
|
"ffpyplayer",
|
||||||
|
"yt-dlp",
|
||||||
|
],
|
||||||
|
setup_requires=[],
|
||||||
|
python_requires=">=3.10",
|
||||||
|
entry_points={
|
||||||
|
"gui_scripts": [
|
||||||
|
"fastanime = fastanime.__main__:get_hook_dirs",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user