Skip to content

Commit c5d02b9

Browse files
committed
animeyi indirmeden kütüphaneye eklemece
1 parent dfe1adb commit c5d02b9

File tree

13 files changed

+334
-129
lines changed

13 files changed

+334
-129
lines changed

.github/md/en/linkedin.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/md/en/reddit.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/md/en/twitter.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/md/tr/linkedin.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/md/tr/reddit.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/md/tr/twitter.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

weeb_cli/commands/library.py

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import questionary
2+
from pathlib import Path
3+
from rich.console import Console
4+
from rich.table import Table
5+
from weeb_cli.i18n import i18n
6+
from weeb_cli.ui.header import show_header
7+
from weeb_cli.services.local_library import local_library
8+
from weeb_cli.config import config
9+
10+
console = Console()
11+
12+
def show_library_menu():
13+
while True:
14+
console.clear()
15+
show_header(i18n.t("menu.options.library"))
16+
17+
virtual_count = len(local_library.get_virtual_library())
18+
indexed_count = len(local_library.get_indexed_anime())
19+
20+
console.print(f"[cyan]{i18n.t('library.online_library')}:[/cyan] {virtual_count} anime")
21+
console.print(f"[cyan]{i18n.t('library.local_library')}:[/cyan] {indexed_count} anime\n")
22+
23+
opt_online = i18n.t("library.online_library")
24+
opt_local = i18n.t("library.local_library")
25+
26+
try:
27+
choice = questionary.select(
28+
i18n.t("library.select_type"),
29+
choices=[opt_online, opt_local],
30+
pointer=">",
31+
use_shortcuts=False
32+
).ask()
33+
34+
if choice is None:
35+
return
36+
37+
if choice == opt_online:
38+
show_virtual_library()
39+
elif choice == opt_local:
40+
show_local_library()
41+
42+
except KeyboardInterrupt:
43+
return
44+
45+
def show_virtual_library():
46+
while True:
47+
console.clear()
48+
show_header(i18n.t("library.online_library"))
49+
50+
library = local_library.get_virtual_library()
51+
52+
if not library:
53+
console.print(f"[dim]{i18n.t('library.online_empty')}[/dim]")
54+
try:
55+
input(i18n.t("common.continue_key"))
56+
except KeyboardInterrupt:
57+
pass
58+
return
59+
60+
console.print(f"[cyan]{i18n.t('library.total_anime')}:[/cyan] {len(library)}\n")
61+
62+
choices = []
63+
for item in library:
64+
title = item["anime_title"]
65+
provider = item["provider_name"]
66+
year = f" ({item['year']})" if item.get("year") else ""
67+
68+
choices.append(questionary.Choice(
69+
title=f"{title}{year} - [{provider}]",
70+
value=item
71+
))
72+
73+
try:
74+
selected = questionary.select(
75+
i18n.t("library.select_anime"),
76+
choices=choices,
77+
pointer=">",
78+
use_shortcuts=False
79+
).ask()
80+
81+
if selected is None:
82+
return
83+
84+
open_virtual_anime(selected)
85+
86+
except KeyboardInterrupt:
87+
return
88+
89+
def show_local_library():
90+
from weeb_cli.commands.downloads import show_anime_episodes
91+
92+
while True:
93+
console.clear()
94+
show_header(i18n.t("library.local_library"))
95+
96+
indexed = local_library.get_indexed_anime()
97+
98+
if not indexed:
99+
console.print(f"[dim]{i18n.t('library.local_empty')}[/dim]")
100+
try:
101+
input(i18n.t("common.continue_key"))
102+
except KeyboardInterrupt:
103+
pass
104+
return
105+
106+
console.print(f"[cyan]{i18n.t('library.total_anime')}:[/cyan] {len(indexed)}\n")
107+
108+
choices = []
109+
for item in indexed:
110+
title = item["title"]
111+
source = item["source_name"]
112+
ep_count = item["episode_count"]
113+
available = Path(item["folder_path"]).exists()
114+
115+
status = "✓" if available else "✗"
116+
117+
choices.append(questionary.Choice(
118+
title=f"{status} {title} - {ep_count} {i18n.t('downloads.episode_short')} [{source}]",
119+
value=item
120+
))
121+
122+
try:
123+
selected = questionary.select(
124+
i18n.t("library.select_anime"),
125+
choices=choices,
126+
pointer=">",
127+
use_shortcuts=False
128+
).ask()
129+
130+
if selected is None:
131+
return
132+
133+
anime_path = selected["folder_path"]
134+
if not Path(anime_path).exists():
135+
console.print(f"[red]{i18n.t('library.local_not_available')}[/red]")
136+
try:
137+
input(i18n.t("common.continue_key"))
138+
except KeyboardInterrupt:
139+
pass
140+
continue
141+
142+
anime_info = {
143+
"title": selected["title"],
144+
"path": anime_path,
145+
"episodes": local_library._scan_anime_folder(Path(anime_path)),
146+
"episode_count": selected["episode_count"],
147+
"source": selected["source_name"]
148+
}
149+
show_anime_episodes(anime_info)
150+
151+
except KeyboardInterrupt:
152+
return
153+
154+
def open_virtual_anime(item):
155+
from weeb_cli.commands.search.anime_details import show_anime_details
156+
from weeb_cli.providers.registry import get_provider
157+
158+
anime_id = item["anime_id"]
159+
provider_name = item["provider_name"]
160+
current_provider = config.get("scraping_source", "")
161+
162+
if current_provider != provider_name:
163+
console.print(f"[yellow]{i18n.t('library.switching_provider', provider=provider_name)}[/yellow]")
164+
config.set("scraping_source", provider_name)
165+
166+
provider = get_provider(provider_name)
167+
if not provider:
168+
console.print(f"[red]{i18n.t('library.provider_not_found', provider=provider_name)}[/red]")
169+
try:
170+
input(i18n.t("common.continue_key"))
171+
except KeyboardInterrupt:
172+
pass
173+
return
174+
175+
anime_data = {
176+
"id": anime_id,
177+
"slug": anime_id,
178+
"title": item["anime_title"],
179+
"name": item["anime_title"],
180+
"cover": item.get("cover_url"),
181+
"type": item.get("anime_type"),
182+
"year": item.get("year")
183+
}
184+
185+
show_anime_details(anime_data)

weeb_cli/commands/search/anime_details.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
console = Console()
1313

1414
def show_anime_details(anime):
15+
from weeb_cli.services.local_library import local_library
16+
from weeb_cli.config import config as app_config
17+
1518
slug = anime.get("slug") or anime.get("id")
1619
if not slug:
1720
console.print(f"[red]{i18n.t('details.error_slug')}[/red]")
@@ -35,14 +38,32 @@ def show_anime_details(anime):
3538
_display_anime_info(details)
3639

3740
try:
38-
action = _get_user_action()
41+
provider_name = app_config.get("scraping_source", "")
42+
in_library = local_library.is_in_virtual_library(slug, provider_name)
43+
44+
action = _get_user_action(in_library)
3945
if action is None:
4046
return
4147

4248
if action == i18n.t("details.download"):
4349
handle_download_flow(slug, details)
4450
elif action == i18n.t("details.watch"):
4551
handle_watch_flow(slug, details)
52+
elif action == i18n.t("details.add_to_library"):
53+
anime_title = details.get("title", "")
54+
cover = anime.get("cover") or details.get("cover")
55+
anime_type = anime.get("type") or details.get("type")
56+
year = anime.get("year") or details.get("year")
57+
58+
if local_library.add_to_virtual_library(slug, anime_title, provider_name, cover, anime_type, year):
59+
console.print(f"[green]{i18n.t('details.added_to_library')}[/green]")
60+
else:
61+
console.print(f"[yellow]{i18n.t('details.already_in_library')}[/yellow]")
62+
time.sleep(1)
63+
elif action == i18n.t("details.remove_from_library"):
64+
local_library.remove_from_virtual_library(slug, provider_name)
65+
console.print(f"[green]{i18n.t('details.removed_from_library')}[/green]")
66+
time.sleep(1)
4667

4768
except KeyboardInterrupt:
4869
return
@@ -59,13 +80,22 @@ def _display_anime_info(details):
5980
desc = desc[:497] + "..."
6081
console.print(f"\n[dim]{desc}[/dim]\n", justify="left")
6182

62-
def _get_user_action():
83+
def _get_user_action(in_library=False):
6384
opt_watch = i18n.t("details.watch")
6485
opt_dl = i18n.t("details.download")
86+
opt_add = i18n.t("details.add_to_library")
87+
opt_remove = i18n.t("details.remove_from_library")
88+
89+
choices = [opt_watch, opt_dl]
90+
91+
if in_library:
92+
choices.append(opt_remove)
93+
else:
94+
choices.append(opt_add)
6595

6696
return questionary.select(
6797
i18n.t("details.action_prompt"),
68-
choices=[opt_watch, opt_dl],
98+
choices=choices,
6999
pointer=">",
70100
use_shortcuts=False
71101
).ask()

0 commit comments

Comments
 (0)