Skip to content

Commit eb6b8a9

Browse files
Dodano discord rich presence, możliwość ustawienia sobie customowego statusu, poprawiono zapisywanie danych.
1 parent 2742855 commit eb6b8a9

File tree

3 files changed

+111
-11
lines changed

3 files changed

+111
-11
lines changed

discord_integration.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
3+
import pypresence.exceptions
4+
from pypresence import Presence
5+
6+
discord_data = ["Menu główne", "Ładowanie..."]
7+
start_time = None
8+
9+
10+
try:
11+
client_ID = '1206583480771936318'
12+
RPC = Presence(client_ID)
13+
RPC.connect()
14+
start_time = time.time()
15+
except: # ojojoj niebezpiecznie
16+
pass
17+
18+
19+
def update_rpc(first_line, second_line):
20+
global discord_data
21+
discord_data = [first_line, second_line]
22+
23+
24+
def start_rpc():
25+
while True:
26+
RPC.update(state=discord_data[1], details=discord_data[0], large_image='icon_1', large_text="Doccli - oglądaj anime bezpośrednio ze swojego terminalu!", buttons=[{"label": "GitHub", "url": "https://github.com/TowarzyszFatCat/doccli"}, {"label": "Discord Projektu", "url": "https://discord.gg/FgfSM7bSEK"}], start=start_time)
27+
time.sleep(5)

main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from menu_module import m_welcome
22
from requests import get
33
from termcolor import colored
4+
import webbrowser
5+
import threading
6+
from discord_integration import start_rpc
47

5-
VERSION = "v2.5.1"
8+
VERSION = "v2.6"
69

710
def check_update() -> None:
811

@@ -22,4 +25,6 @@ def check_update() -> None:
2225

2326
if __name__ == "__main__":
2427
check_update()
28+
thread = threading.Thread(target=start_rpc)
29+
thread.start()
2530
m_welcome()

menu_module.py

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import sys
22
import time
33
import json
4-
from InquirerPy import inquirer
4+
from InquirerPy import inquirer, prompt
55
import os
66
from os import system
7-
from docchi_api_connector import get_series_list, get_episodes_count_for_serie, get_players_list
7+
from docchi_api_connector import get_series_list, get_episodes_count_for_serie, get_players_list, get_details_for_serie
88
from subprocess import Popen, DEVNULL
99
from termcolor import colored
10+
import webbrowser
11+
from discord_integration import discord_data, update_rpc
12+
1013

1114
def clear():
1215
system("clear")
@@ -38,6 +41,8 @@ def m_welcome():
3841

3942
load()
4043

44+
update_rpc("Menu główne", "Szuka anime do obejrzenia...")
45+
4146
choices = [
4247
"Wyszukaj",
4348
]
@@ -48,6 +53,7 @@ def m_welcome():
4853
choices.append(f"Wznów {continue_data[0]['title']} / {continue_data[0]['title_en']}, Odc: {continue_data[1]}")
4954

5055
choices.append("Moja lista")
56+
choices.append("Ustawienia")
5157
choices.append("Dołącz do discorda")
5258
choices.append("Zamknij")
5359

@@ -65,15 +71,44 @@ def m_welcome():
6571
elif ans == choices[2]:
6672
m_mylist()
6773
elif ans == choices[3]:
68-
m_discord()
74+
m_settings()
6975
elif ans == choices[4]:
76+
m_discord()
77+
elif ans == choices[5]:
7078
sys.exit()
7179

80+
def m_settings():
81+
choices = [{
82+
"type": "list",
83+
"message": "Czy chcesz aby ludzie na discordzie widzieli co oglądasz?",
84+
"choices": ["Tak", "Nie"],
85+
}]
86+
87+
res = prompt(questions=choices)
88+
89+
if res[0] == "Nie":
90+
settings[0] = False
91+
save()
92+
m_welcome()
93+
if res[0] == "Tak":
94+
clear()
95+
settings[0] = True
96+
choices2 = [{"type": "input", "message": "Wpisz co tylko zechcesz! Będzie to wyświetlane w II linijce statusu. Zostaw puste jeśli chcesz aby był wyświetlany domyślny status. [Minimalnie 2 znaki] (Domyślna wartość: 'Używa doccli!') \n", "name": "status_dc"}]
97+
res2 = prompt(questions=choices2)
98+
99+
if not res2['status_dc'] == "" and len(res2['status_dc']) > 1:
100+
settings[1] = res2['status_dc']
101+
save()
102+
m_welcome()
103+
else:
104+
save()
105+
m_welcome()
106+
107+
72108

73109
def m_discord():
74-
print(colored('Zaproszenie:', "white"), colored('discord.gg/Y4RcwbE5CJ', "green"))
75-
print('')
76-
input(colored("Naciśnij enter by pominąć...", "yellow"))
110+
webbrowser.open('https://discord.gg/Y4RcwbE5CJ')
111+
m_welcome()
77112

78113
def m_mylist():
79114
choices = ['Cofnij']
@@ -224,6 +259,7 @@ def w_first(SLUG):
224259
save()
225260
w_players(SLUG, 1)
226261

262+
227263
def w_list(SLUG):
228264
last_episode = get_episodes_count_for_serie(SLUG)
229265

@@ -248,9 +284,17 @@ def w_players(SLUG, NUMBER, err=''):
248284

249285
choices = [player[0] for player in players]
250286

287+
choices.append("Wróć do menu")
288+
289+
last_option = choices[-1]
290+
251291
prompt = 'Wybierz źródło: '
252292

253293
ans = open_menu(choices=choices, prompt=prompt, qmark=err)
294+
295+
if ans == last_option:
296+
m_welcome()
297+
254298
ans_index_in_choices = choices.index(ans)
255299

256300
ans_index = players[ans_index_in_choices]
@@ -259,22 +303,30 @@ def w_players(SLUG, NUMBER, err=''):
259303

260304

261305

262-
# Wait 10 sec and check if started playing
306+
# Wait 3 sec and check if started playing
263307
print("Rozpoczynanie odtwarzania...")
264308
time.sleep(3) # CZAS ZALEZNY OD PREDKOSCI LACZA
265309
if process.poll() is not None:
266310
w_players(SLUG, NUMBER, err='Wybrane źródło nie jest dostępne, lub nie jest wspierane! Możesz to złgosić na discordzie.')
267311

268312
w_default(SLUG, NUMBER, process)
269313

314+
270315
def mpv_play(URL):
271316
process = Popen(args=['mpv', URL], shell=False, stdout=DEVNULL, stderr=DEVNULL)
272317
return process
273318

274-
def w_default(SLUG, NUMBER, process):
275319

320+
def w_default(SLUG, NUMBER, process):
276321
how_many_episodes = get_episodes_count_for_serie(SLUG)
277322

323+
details = get_details_for_serie(SLUG)
324+
325+
if settings[0]:
326+
update_rpc(f"Ogląda: {details['title']} [{str(NUMBER)}/{str(how_many_episodes)}]", settings[1])
327+
else:
328+
update_rpc(f"Ogląda anime", settings[1])
329+
278330
choices = [
279331
"Następny odcinek",
280332
"Poprzedni odcinek",
@@ -284,23 +336,27 @@ def w_default(SLUG, NUMBER, process):
284336

285337
prompt = 'Co chcesz zrobić? '
286338

287-
ans = open_menu(choices=choices, prompt=prompt,qmark=f'Odcinek: {NUMBER}/{how_many_episodes}')
339+
ans = open_menu(choices=choices, prompt=prompt, qmark=f'Odcinek: {NUMBER}/{how_many_episodes}')
288340

289341
if ans == choices[0]:
290342
process.kill()
343+
update_rpc("Menu główne", "Szuka anime do obejrzenia...")
291344
continue_data[1] = NUMBER + 1 if NUMBER < how_many_episodes else NUMBER
292345
save()
293346
w_players(SLUG, NUMBER + 1 if NUMBER < how_many_episodes else NUMBER)
294347
elif ans == choices[1]:
295348
process.kill()
349+
update_rpc("Menu główne", "Szuka anime do obejrzenia...")
296350
continue_data[1] = NUMBER + 1 if NUMBER < how_many_episodes else NUMBER
297351
save()
298352
w_players(SLUG, NUMBER - 1 if NUMBER >= 2 else NUMBER)
299353
elif ans == choices[2]:
300354
process.kill()
355+
update_rpc("Menu główne", "Szuka anime do obejrzenia...")
301356
w_list(SLUG)
302357
elif ans == choices[3]:
303358
process.kill()
359+
update_rpc("Menu główne", "Szuka anime do obejrzenia...")
304360
m_welcome()
305361

306362

@@ -311,6 +367,7 @@ def w_default(SLUG, NUMBER, process):
311367
PATH_config = os.path.join(PATH_home, ".config", "doccli")
312368
PATH_mylist = os.path.join(PATH_config, "mylist.json")
313369
PATH_continue = os.path.join(PATH_config, "continue.json")
370+
PATH_settings = os.path.join(PATH_config, "settings.json")
314371

315372

316373
def load():
@@ -325,6 +382,11 @@ def load():
325382
global continue_data
326383
continue_data = [None, None]
327384
json.dump(continue_data, file, indent=4)
385+
if not os.path.exists(PATH_settings):
386+
with open(PATH_settings, 'w') as file:
387+
global settings
388+
settings = [True, "Używa doccli!"]
389+
json.dump(settings, file, indent=4)
328390

329391
with open(PATH_mylist, 'r') as json_file:
330392
loaded_data = json.load(json_file)
@@ -335,9 +397,15 @@ def load():
335397
loaded_data = json.load(json_file)
336398
continue_data = loaded_data
337399

400+
with open(PATH_settings, 'r') as json_file:
401+
loaded_data = json.load(json_file)
402+
settings = loaded_data
403+
338404

339405
def save():
340406
with open(PATH_mylist, 'w') as json_file:
341407
json.dump(mylist, json_file, indent=4)
342408
with open(PATH_continue, 'w') as json_file:
343-
json.dump(continue_data, json_file, indent=4)
409+
json.dump(continue_data, json_file, indent=4)
410+
with open(PATH_settings, 'w') as json_file:
411+
json.dump(settings, json_file, indent=4)

0 commit comments

Comments
 (0)