-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:standardize the user data helper to kork for both cli and gui
- Loading branch information
Benex254
committed
Jul 7, 2024
1 parent
2aa02d6
commit f08062e
Showing
8 changed files
with
193 additions
and
52 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
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,36 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
from .. import USER_DATA_PATH | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class UserData: | ||
user_data = {"watch_history": {}, "animelist": []} | ||
|
||
def __init__(self): | ||
try: | ||
if os.path.isfile(USER_DATA_PATH): | ||
with open(USER_DATA_PATH, "r") as f: | ||
user_data = json.load(f) | ||
self.user_data.update(user_data) | ||
print(user_data, self.user_data) | ||
except Exception as e: | ||
logger.error(e) | ||
|
||
def update_watch_history(self, watch_history: dict): | ||
self.user_data["watch_history"] = watch_history | ||
self._update_user_data() | ||
|
||
def update_animelist(self, anime_list: list): | ||
self.user_data["animelist"] = list(set(anime_list)) | ||
self._update_user_data() | ||
|
||
def _update_user_data(self): | ||
with open(USER_DATA_PATH, "w") as f: | ||
json.dump(self.user_data, f) | ||
|
||
|
||
user_data_helper = UserData() |
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,6 +1,68 @@ | ||
import click | ||
|
||
from ...libs.anime_provider.allanime.api import anime_provider | ||
from ...Utility.downloader.downloader import downloader | ||
from ..config import Config | ||
from ..utils.utils import clear, fuzzy_inquirer | ||
|
||
|
||
@click.command() | ||
def download(): | ||
print("download") | ||
@click.option("--anime-title", prompt="Enter the anime title", required=True) | ||
@click.option("--episode-start", prompt="Enter the episode start", required=True) | ||
@click.option("--episode-end", prompt="Enter the episode end", required=True) | ||
@click.pass_obj | ||
def download(config: Config, anime_title, episode_start, episode_end): | ||
translation_type = config.translation_type | ||
download_dir = config.downloads_dir | ||
quality = config.quality | ||
search_results = anime_provider.search_for_anime( | ||
anime_title, translation_type=translation_type | ||
) | ||
|
||
episodes_to_download = range(int(episode_start), int(episode_end) + 1) | ||
options = {show["name"]: show for show in search_results["shows"]["edges"]} | ||
anime = fuzzy_inquirer("Please select the anime:", options.keys()) | ||
|
||
anime_data = options[anime] | ||
availableEpisodesDetail = anime_data["availableEpisodes"] | ||
|
||
episodes = availableEpisodesDetail[translation_type] | ||
|
||
server = config.server | ||
for episode_number in episodes_to_download: | ||
if episode_number not in range(episodes): | ||
print(f"Episode {episode_number} not available") | ||
continue | ||
print(f"Downloading episode {episode_number} of {anime_data['name']}") | ||
episode = anime_provider.get_anime_episode( | ||
anime_data["_id"], str(episode_number), translation_type | ||
) | ||
|
||
# get streams for episode from provider | ||
episode_streams = anime_provider.get_episode_streams(episode) | ||
episode_streams = { | ||
episode_stream[0]: episode_stream[1] for episode_stream in episode_streams | ||
} | ||
|
||
# prompt for preferred server | ||
if not server or server not in episode_streams.keys(): | ||
server = fuzzy_inquirer("Please select server:", episode_streams.keys()) | ||
print(episode) | ||
print(episode_streams) | ||
selected_server = episode_streams[server] | ||
|
||
links = selected_server["links"] | ||
if quality > len(links) - 1: | ||
quality = config.quality = len(links) - 1 | ||
elif quality < 0: | ||
quality = config.quality = 0 | ||
stream_link = links[quality]["link"] | ||
|
||
downloader._download_file( | ||
stream_link, | ||
download_dir, | ||
(anime_data["name"], str(episode_number)), | ||
lambda *_: "", | ||
silent=True, | ||
) | ||
clear() |
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
Oops, something went wrong.