1
1
import sys
2
2
import time
3
3
import json
4
- from InquirerPy import inquirer
4
+ from InquirerPy import inquirer , prompt
5
5
import os
6
6
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
8
8
from subprocess import Popen , DEVNULL
9
9
from termcolor import colored
10
+ import webbrowser
11
+ from discord_integration import discord_data , update_rpc
12
+
10
13
11
14
def clear ():
12
15
system ("clear" )
@@ -38,6 +41,8 @@ def m_welcome():
38
41
39
42
load ()
40
43
44
+ update_rpc ("Menu główne" , "Szuka anime do obejrzenia..." )
45
+
41
46
choices = [
42
47
"Wyszukaj" ,
43
48
]
@@ -48,6 +53,7 @@ def m_welcome():
48
53
choices .append (f"Wznów { continue_data [0 ]['title' ]} / { continue_data [0 ]['title_en' ]} , Odc: { continue_data [1 ]} " )
49
54
50
55
choices .append ("Moja lista" )
56
+ choices .append ("Ustawienia" )
51
57
choices .append ("Dołącz do discorda" )
52
58
choices .append ("Zamknij" )
53
59
@@ -65,15 +71,44 @@ def m_welcome():
65
71
elif ans == choices [2 ]:
66
72
m_mylist ()
67
73
elif ans == choices [3 ]:
68
- m_discord ()
74
+ m_settings ()
69
75
elif ans == choices [4 ]:
76
+ m_discord ()
77
+ elif ans == choices [5 ]:
70
78
sys .exit ()
71
79
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
+
72
108
73
109
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 ()
77
112
78
113
def m_mylist ():
79
114
choices = ['Cofnij' ]
@@ -224,6 +259,7 @@ def w_first(SLUG):
224
259
save ()
225
260
w_players (SLUG , 1 )
226
261
262
+
227
263
def w_list (SLUG ):
228
264
last_episode = get_episodes_count_for_serie (SLUG )
229
265
@@ -248,9 +284,17 @@ def w_players(SLUG, NUMBER, err=''):
248
284
249
285
choices = [player [0 ] for player in players ]
250
286
287
+ choices .append ("Wróć do menu" )
288
+
289
+ last_option = choices [- 1 ]
290
+
251
291
prompt = 'Wybierz źródło: '
252
292
253
293
ans = open_menu (choices = choices , prompt = prompt , qmark = err )
294
+
295
+ if ans == last_option :
296
+ m_welcome ()
297
+
254
298
ans_index_in_choices = choices .index (ans )
255
299
256
300
ans_index = players [ans_index_in_choices ]
@@ -259,22 +303,30 @@ def w_players(SLUG, NUMBER, err=''):
259
303
260
304
261
305
262
- # Wait 10 sec and check if started playing
306
+ # Wait 3 sec and check if started playing
263
307
print ("Rozpoczynanie odtwarzania..." )
264
308
time .sleep (3 ) # CZAS ZALEZNY OD PREDKOSCI LACZA
265
309
if process .poll () is not None :
266
310
w_players (SLUG , NUMBER , err = 'Wybrane źródło nie jest dostępne, lub nie jest wspierane! Możesz to złgosić na discordzie.' )
267
311
268
312
w_default (SLUG , NUMBER , process )
269
313
314
+
270
315
def mpv_play (URL ):
271
316
process = Popen (args = ['mpv' , URL ], shell = False , stdout = DEVNULL , stderr = DEVNULL )
272
317
return process
273
318
274
- def w_default (SLUG , NUMBER , process ):
275
319
320
+ def w_default (SLUG , NUMBER , process ):
276
321
how_many_episodes = get_episodes_count_for_serie (SLUG )
277
322
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
+
278
330
choices = [
279
331
"Następny odcinek" ,
280
332
"Poprzedni odcinek" ,
@@ -284,23 +336,27 @@ def w_default(SLUG, NUMBER, process):
284
336
285
337
prompt = 'Co chcesz zrobić? '
286
338
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 } ' )
288
340
289
341
if ans == choices [0 ]:
290
342
process .kill ()
343
+ update_rpc ("Menu główne" , "Szuka anime do obejrzenia..." )
291
344
continue_data [1 ] = NUMBER + 1 if NUMBER < how_many_episodes else NUMBER
292
345
save ()
293
346
w_players (SLUG , NUMBER + 1 if NUMBER < how_many_episodes else NUMBER )
294
347
elif ans == choices [1 ]:
295
348
process .kill ()
349
+ update_rpc ("Menu główne" , "Szuka anime do obejrzenia..." )
296
350
continue_data [1 ] = NUMBER + 1 if NUMBER < how_many_episodes else NUMBER
297
351
save ()
298
352
w_players (SLUG , NUMBER - 1 if NUMBER >= 2 else NUMBER )
299
353
elif ans == choices [2 ]:
300
354
process .kill ()
355
+ update_rpc ("Menu główne" , "Szuka anime do obejrzenia..." )
301
356
w_list (SLUG )
302
357
elif ans == choices [3 ]:
303
358
process .kill ()
359
+ update_rpc ("Menu główne" , "Szuka anime do obejrzenia..." )
304
360
m_welcome ()
305
361
306
362
@@ -311,6 +367,7 @@ def w_default(SLUG, NUMBER, process):
311
367
PATH_config = os .path .join (PATH_home , ".config" , "doccli" )
312
368
PATH_mylist = os .path .join (PATH_config , "mylist.json" )
313
369
PATH_continue = os .path .join (PATH_config , "continue.json" )
370
+ PATH_settings = os .path .join (PATH_config , "settings.json" )
314
371
315
372
316
373
def load ():
@@ -325,6 +382,11 @@ def load():
325
382
global continue_data
326
383
continue_data = [None , None ]
327
384
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 )
328
390
329
391
with open (PATH_mylist , 'r' ) as json_file :
330
392
loaded_data = json .load (json_file )
@@ -335,9 +397,15 @@ def load():
335
397
loaded_data = json .load (json_file )
336
398
continue_data = loaded_data
337
399
400
+ with open (PATH_settings , 'r' ) as json_file :
401
+ loaded_data = json .load (json_file )
402
+ settings = loaded_data
403
+
338
404
339
405
def save ():
340
406
with open (PATH_mylist , 'w' ) as json_file :
341
407
json .dump (mylist , json_file , indent = 4 )
342
408
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