-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
1156 lines (996 loc) · 46.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
from PySide6.QtCore import Qt, QTimer, QPoint
from PySide6.QtGui import QIcon, QGuiApplication, QAction, QPixmap, QCursor
from PySide6.QtWidgets import QMainWindow, QApplication, QDialog, QMenu, QFileDialog
import about_window
import android_config_window
import anime4k
import icons
import launch_parameters_window
import localization
import main_window
import open_folder_window
import open_url_window
import reference_window
import screenshot_window
import settings_window
from config import ConfigManager
from mpv import MPV
name_program = 'Anime Player'
version = '2.0 Beta 5'
video_formats = ('mp4', 'mkv', 'webm', 'avi', 'mov', 'wmv', '3gp', 'ts', 'mpeg')
audio_formats = ('m4a', 'mp3', 'flac', 'ogg', 'aac', 'opus', 'wav')
subtitles_formats = ('ass', 'idx', 'srt', 'ssa', 'sub', 'ttml', 'vtt')
formats = video_formats + audio_formats
config = ConfigManager('config.json')
localization.set_locale(config.get('language'))
loc = localization.strings
class AndroidConfigWindow(QDialog):
def __init__(self):
super(AndroidConfigWindow, self).__init__()
self.ui = android_config_window.Ui_AndroidConfigWindow()
self.ui.setupUi(self)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.setWindowTitle(loc['Create config for Android'])
self.ui.label.setText(loc['You can use this config to use the Anime4K algorithm in the mpv video player on android'])
self.ui.label_2.setText(loc['Enter the path to the shaders'])
self.ui.label_3.setText(loc['Select the algorithm configuration'])
self.ui.selected.setText(loc['Selected'])
self.ui.all.setText(loc['All'])
self.ui.selected.clicked.connect(self.selected)
self.ui.all.clicked.connect(self.all)
self.modes = []
for quality in anime4k.qualities:
self.modes += [f'{loc["Mode"]} {mode} ({quality})' for mode in anime4k.modes]
self.ui.comboBox.addItems(self.modes)
def selected(self):
quality = self.ui.comboBox.currentText().replace(')', '').split('(')[1]
mode = self.ui.comboBox.currentText().split(' ')[1]
self.ui.plainTextEdit.setPlainText(f'# {self.ui.comboBox.currentText()}\n' + anime4k.android_config(anime4k.create_preset(quality, mode), self.ui.lineEdit.text()))
def all(self):
mods = []
for mod in self.modes:
quality = mod.replace(')', '').split('(')[1]
mode = mod.split(' ')[1]
mods.append(f'# {mod}\n' + '# ' + anime4k.android_config(anime4k.create_preset(quality, mode), self.ui.lineEdit.text()))
self.ui.plainTextEdit.setPlainText('\n\n'.join(mods))
class LaunchParametersWindow(QDialog):
def __init__(self):
super(LaunchParametersWindow, self).__init__()
self.ui = launch_parameters_window.Ui_LaunchParemetersWindow()
self.ui.setupUi(self)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.setWindowTitle(loc['Launch parameters'])
self.ui.label.setText(loc['Manual launch parameters'])
self.ui.buttonBox.buttons()[0].setText(loc['Save'])
self.ui.buttonBox.buttons()[1].setText(loc['Cancel'])
self.ui.buttonBox.buttons()[2].setText(loc['Apply'])
self.ui.plainTextEdit.setPlainText(config.get('launchParameters', ''))
self.ui.buttonBox.buttons()[0].clicked.connect(self.save)
self.ui.buttonBox.buttons()[2].clicked.connect(self.apply)
def save(self):
config.set('launchParameters', self.ui.plainTextEdit.toPlainText())
def apply(self):
try:
exec(self.ui.plainTextEdit.toPlainText())
config.set('launchParameters', self.ui.plainTextEdit.toPlainText())
Player.volume_update(player.volume)
self.setWindowTitle(loc['Success'])
except Exception:
self.setWindowTitle(loc['Error'])
class ReferenceWindow(QDialog):
def __init__(self):
super(ReferenceWindow, self).__init__()
self.ui = reference_window.Ui_ReferenceWindow()
self.ui.setupUi(self)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.setWindowTitle(loc['Reference'])
self.ui.buttonBox.buttons()[0].setText(loc['Close'])
if loc['lang'] == 'Русский':
reference_file_name = 'GLSL_Instructions_Advanced_ru.txt'
else:
reference_file_name = 'GLSL_Instructions_Advanced.txt'
with open(f'{os.path.dirname(__file__) + os.sep}doc{os.sep}{reference_file_name}', 'r', encoding='utf-8') as ref_data:
reference = ref_data.read()
self.ui.plainTextEdit.setPlainText(reference)
class ScreenshotWindow(QDialog):
def __init__(self):
super(ScreenshotWindow, self).__init__()
self.ui = screenshot_window.Ui_ScreenshotWindow()
self.ui.setupUi(self)
self.setFixedSize(520, 120)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.ui.lineEdit.setText(screenshot_path)
self.setWindowTitle(loc['Screenshot'])
self.ui.label.setText(loc['Enter folder path for screenshots'])
self.ui.select.setText(loc['Select'])
self.ui.paste.setText(loc['Paste'])
self.ui.buttonBox.buttons()[0].setText(loc['Save'])
self.ui.buttonBox.buttons()[1].setText(loc['Close'])
self.ui.paste.clicked.connect(lambda: self.ui.lineEdit.setText(QGuiApplication.clipboard().text()))
self.ui.select.clicked.connect(self.select)
self.ui.buttonBox.accepted.connect(self.save)
def select(self):
folder_name = QFileDialog.getExistingDirectory()
if folder_name is not None and folder_name != '':
self.ui.lineEdit.setText(folder_name)
def save(self):
global screenshot_path
screenshot_path = self.ui.lineEdit.text().strip()
if screenshot_path is not None and screenshot_path != '':
player.screenshot_directory = screenshot_path
player.screenshot_jpeg_quality = 100
try:
player.screenshot()
except SystemError:
self.ui.label.setText(loc['Error'])
class AboutWindow(QDialog):
def __init__(self):
super(AboutWindow, self).__init__()
self.ui = about_window.Ui_AboutWindow()
self.ui.setupUi(self)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.ui.image.setPixmap(QPixmap(f'{os.path.dirname(__file__) + os.sep}images{os.sep}anime-player-icon.png'))
self.setWindowTitle(loc['About'])
self.ui.label_2.setText(f'Anime Player v{version}')
self.ui.label_3.setText(f'{player.mpv_version}\n\n{loc["About program"]}')
self.ui.buttonBox.buttons()[0].setText(loc['Close'])
class SettingsWindow(QDialog):
def __init__(self):
super(SettingsWindow, self).__init__()
self.ui = settings_window.Ui_SettingsWindow()
self.ui.setupUi(self)
self.setFixedHeight(220)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
match config.get('language'):
case 'Русский':
self.lang = 'Русский'
case 'English':
self.lang = 'English'
case _:
self.lang = 'Auto'
match config.get('theme'):
case 'Light':
self.theme = 'Light'
case 'Dark':
self.theme = 'Dark'
case _:
self.theme = 'System'
self.ui.language.setCurrentText(self.lang)
self.ui.openLastFile.setChecked(config.get('onOpenLastFile', True))
self.ui.posLastFile.setChecked(config.get('onPosLastFile', True))
self.ui.volumePlus.setChecked(config.get('volumePlus', False))
self.ui.svp.setChecked(config.get('SVP', False))
self.ui.theme.setCurrentText(self.theme)
self.ui.labelTheme.setVisible(False)
self.ui.theme.setVisible(False)
self.ui.buttonBox.accepted.connect(self.ok)
self.setWindowTitle(loc['Settings'])
self.ui.label.setText(loc['Language selection'])
self.ui.openLastFile.setText(loc['On startup open the last opened file'])
self.ui.posLastFile.setText(loc['Set the position of the last opened file'])
self.ui.volumePlus.setText(loc['Increase maximum volume up to 150%'])
self.ui.svp.setText(loc['Activate SVP'])
self.ui.buttonBox.buttons()[1].setText(loc['Cancel'])
self.ui.labelTheme.setText(loc['Theme'])
def ok(self):
config.set('onOpenLastFile', self.ui.openLastFile.isChecked())
config.set('onPosLastFile', self.ui.posLastFile.isChecked())
config.set('SVP', self.ui.svp.isChecked())
config.set('volumePlus', self.ui.volumePlus.isChecked())
if config.get('volumePlus', False) != self.ui.volumePlus.isChecked():
if not self.ui.volumePlus.isChecked() and player.volume > 100:
player.volume = 100
# window['-VOLUME-'].update(value=100)
# window['-VOLUME-'].update(range=(0, 100 if not values['-VOLUME_PLUS-'] else 150))
config.set('volumePlus', self.ui.volumePlus.isChecked())
if config.get('language', self.lang) != self.ui.language.currentText() or config.get('theme', self.theme) != self.ui.theme.currentText():
config.set('language', self.ui.language.currentText())
config.set('theme', self.ui.theme.currentText())
if self.ui.svp.isChecked():
if player.input_ipc_server != 'mpvpipe':
player.input_ipc_server = 'mpvpipe'
player.hwdec = 'auto-copy'
player.hwdec_codecs = 'all'
player.hr_seek_framedrop = False
else:
player.input_ipc_server = ''
player.hwdec = 'auto'
player.hr_seek_framedrop = True
class OpenURLWindow(QDialog):
def __init__(self):
super(OpenURLWindow, self).__init__()
self.ui = open_url_window.Ui_OpenURLWindow()
self.ui.setupUi(self)
self.setFixedSize(550, 120)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.links_history = config.get('linksHistory', [])
self.ui.comboBox.addItems(self.links_history)
self.ui.paste.clicked.connect(lambda: self.ui.comboBox.setCurrentText(QGuiApplication.clipboard().text()))
self.ui.clear.clicked.connect(self.clear)
self.ui.buttonBox.accepted.connect(self.ok)
self.setWindowTitle(loc['Opening a link'])
self.ui.label.setText(loc['Enter the URL'])
self.ui.paste.setText(loc['Paste'])
self.ui.clear.setText(loc['Clear'])
self.ui.buttonBox.buttons()[1].setText(loc['Cancel'])
def clear(self):
self.links_history = []
self.ui.comboBox.clear()
self.ui.comboBox.clearEditText()
config.set('linksHistory', [])
def ok(self):
new_link = self.ui.comboBox.currentText().strip()
if new_link is not None and new_link != '':
if self.links_history.count(new_link) > 0:
self.links_history.remove(new_link)
self.links_history.insert(0, new_link)
config.set('linksHistory', self.links_history)
Player.open_url(new_link)
class OpenFolderWindow(QDialog):
def __init__(self):
super(OpenFolderWindow, self).__init__()
self.ui = open_folder_window.Ui_OpenFolderWindow()
self.ui.setupUi(self)
self.setFixedSize(550, 120)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.folders_history = config.get('foldersHistory', [])
self.ui.comboBox.addItems(self.folders_history)
self.ui.paste.clicked.connect(lambda: self.ui.comboBox.setCurrentText(QGuiApplication.clipboard().text()))
self.ui.clear.clicked.connect(self.clear)
self.ui.buttonBox.accepted.connect(self.ok)
self.ui.select.clicked.connect(self.select)
self.setWindowTitle(loc['Opening a folder'])
self.ui.label.setText(loc['Select a folder'])
self.ui.select.setText(loc['Select'])
self.ui.paste.setText(loc['Paste'])
self.ui.clear.setText(loc['Clear'])
self.ui.buttonBox.buttons()[1].setText(loc['Cancel'])
def clear(self):
self.folders_history = []
self.ui.comboBox.clear()
self.ui.comboBox.clearEditText()
config.set('foldersHistory', [])
def ok(self):
new_folder = self.ui.comboBox.currentText().strip()
if new_folder is not None and new_folder != '':
if self.folders_history.count(new_folder) > 0:
self.folders_history.remove(new_folder)
self.folders_history.insert(0, new_folder)
config.set('foldersHistory', self.folders_history)
Player.open_folder(new_folder)
def select(self):
folder_name = QFileDialog.getExistingDirectory()
if folder_name is not None and folder_name != '':
self.ui.comboBox.setCurrentText(folder_name)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = main_window.Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowIcon(QIcon(f'{os.path.dirname(__file__) + os.sep}favicon.ico'))
self.ui.rightPanel.setVisible(False)
self.ui.play.setIcon(QIcon(icons.play))
self.ui.prev.setIcon(QIcon(icons.prev))
self.ui.next.setIcon(QIcon(icons.next))
self.ui.fullscreen.setIcon(QIcon(icons.fullscreen))
self.ui.audio.setIcon(QIcon(icons.audio))
self.ui.sub.setIcon(QIcon(icons.sub))
self.ui.menu.setIcon(QIcon(icons.menu))
self.ui.video.setPixmap(QPixmap(f'{os.path.dirname(__file__) + os.sep}images{os.sep}play-button.png'))
self.ui.play.clicked.connect(lambda: Player.play())
self.ui.prev.clicked.connect(lambda: Player.prev())
self.ui.next.clicked.connect(lambda: Player.next())
self.ui.fullscreen.clicked.connect(lambda: Player.fullscreen_switch())
self.ui.menu.clicked.connect(self.right_panel_visible)
self.ui.sub.clicked.connect(lambda: Player.sub_view())
self.ui.audio.clicked.connect(lambda: Player.audio_view())
self.ui.volume.valueChanged.connect(lambda: Player.volume_update(self.ui.volume.value()))
self.ui.time.valueChanged.connect(lambda: self.change_time())
self.ui.video.setMouseTracking(True)
self.ui.controlPanel.setMouseTracking(True)
self.setMouseTracking(True)
self.centralWidget().setMouseTracking(True)
self.timer = QTimer()
self.timer.setInterval(500)
self.timer.timeout.connect(self.timer_update)
self.timer.start()
self.ui.fileList.clicked.connect(lambda: Player.update_filelist(self.ui.fileList.currentItem().text()))
# Верхнее меню
self.ui.action_Exit.triggered.connect(lambda: self.close())
self.ui.action_Close.triggered.connect(lambda: Player.close())
self.ui.action_Open_file.triggered.connect(self.open_file)
self.ui.action_Open_folder.triggered.connect(self.open_folder)
self.ui.action_Open_URL.triggered.connect(self.open_url)
self.ui.action_Settings.triggered.connect(self.settings)
self.ui.action_Reference.triggered.connect(self.reference)
self.ui.action_Launch_parameters.triggered.connect(self.launch_parameters)
self.ui.action_Create_config_Android.triggered.connect(self.android_config)
self.ui.action_Fullscreen.triggered.connect(lambda: Player.fullscreen_switch())
self.ui.action_Play_Pause.triggered.connect(lambda: Player.play())
self.ui.action_Disable.triggered.connect(lambda: Player.disable_anime4k())
self.ui.action_Volume_plus.triggered.connect(self.volume_plus)
self.ui.action_Volume_minus.triggered.connect(self.volume_minus)
self.ui.action_Rewind_plus.triggered.connect(self.rewind_plus)
self.ui.action_Rewind_minus.triggered.connect(self.rewind_minus)
self.ui.action_About.triggered.connect(self.about)
self.ui.action_Playlist.triggered.connect(self.right_panel_visible)
self.ui.action_Take_a_screenshot.triggered.connect(self.screenshot)
self.ui.action_Zoom_in.triggered.connect(lambda: self.zoom(0.01))
self.ui.action_Zoom_out.triggered.connect(lambda: self.zoom(-0.01))
self.ui.action_x025.triggered.connect(lambda: self.speed(0.25))
self.ui.action_x05.triggered.connect(lambda: self.speed(0.5))
self.ui.action_x075.triggered.connect(lambda: self.speed(0.75))
self.ui.action_x10.triggered.connect(lambda: self.speed(1.0))
self.ui.action_x125.triggered.connect(lambda: self.speed(1.25))
self.ui.action_x15.triggered.connect(lambda: self.speed(1.5))
self.ui.action_x175.triggered.connect(lambda: self.speed(1.75))
self.ui.action_x20.triggered.connect(lambda: self.speed(2.0))
self.ui.action_x225.triggered.connect(lambda: self.speed(2.25))
self.ui.action_x25.triggered.connect(lambda: self.speed(2.5))
self.ui.action_x275.triggered.connect(lambda: self.speed(2.75))
self.ui.action_x30.triggered.connect(lambda: self.speed(3.0))
self.ui.action_Settings.setText(loc['Settings'])
self.ui.menu_File.setTitle(loc['File'])
self.ui.action_Open_file.setText(loc['Open file'])
self.ui.action_Open_URL.setText(loc['Open URL'])
self.ui.action_Open_folder.setText(loc['Open folder'])
self.ui.action_Close.setText(loc['Close'])
self.ui.action_Exit.setText(loc['Exit'])
self.ui.menu_Playback.setTitle(loc['Playback'])
self.ui.action_Play_Pause.setText(loc['Play | Pause'])
self.ui.action_Fullscreen.setText(loc['Fullscreen'])
self.ui.menu_Increasing_image_quality.setTitle(loc['Increasing image quality'])
self.ui.action_Disable.setText(loc['Disable'])
self.ui.menu_Other.setTitle(loc['Other'])
self.ui.action_About.setText(loc['About'])
self.ui.action_Launch_parameters.setText(loc['Launch parameters'])
self.ui.action_Take_a_screenshot.setText(loc['Take a screenshot'])
self.ui.action_Create_config_Android.setText(loc['Create config for Android'])
self.ui.action_Reference.setText(loc['Reference'])
self.ui.menu_Playback_speed.setTitle(loc['Playback speed'])
self.ui.action_Volume_plus.setText(loc['Volume +10'])
self.ui.action_Volume_minus.setText(loc['Volume -10'])
self.ui.action_Rewind_plus.setText(loc['Rewind +5 sec'])
self.ui.action_Rewind_minus.setText(loc['Rewind -5 sec'])
self.ui.action_Zoom_in.setText(loc['Zoom in'])
self.ui.action_Zoom_out.setText(loc['Zoom out'])
self.ui.action_Playlist.setText(loc['Playlist'])
self.ui.sourceInfo.setText(loc['Information'])
modes = []
for quality in anime4k.qualities:
modes += [f'{loc["Mode"]} {mode} ({quality})' for mode in anime4k.modes]
tabs = {}
for quality in anime4k.qualities:
if f'{loc["Quality"]} {quality}' not in tabs.keys():
tabs[f'{loc["Quality"]} {quality}'] = []
tabs[f'{loc["Quality"]} {quality}'] += [f'{loc["Mode"]} {mode}' for mode in anime4k.modes]
tabs[f'{loc["Quality"]} HQ'] = [f'{loc["Mode"]} {mode}' for mode in list(anime4k.ultra_hq_presets.keys())]
for quality in tabs.keys():
menu = QMenu(self.menuBar())
menu.setTitle(quality)
self.ui.menu_Increasing_image_quality.addMenu(menu)
for mode in tabs[quality]:
action = QAction(self)
action.setText(mode)
action.triggered.connect(lambda ignore=False, q=quality, m=mode: Player.set_preset_quality(q, m))
menu.addAction(action)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
self.setAcceptDrops(True)
def mouseMoveEvent(self, event):
if Player.fullscreen:
Player.update_fullscreen_layout(event.position().x(), event.position().y())
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.acceptProposedAction()
def dropEvent(self, event):
for url in event.mimeData().urls():
file_name = url.toLocalFile()
if os.path.isfile(file_name):
Player.open_file(file_name)
elif os.path.isdir(file_name):
Player.open_folder(file_name)
elif os.path.islink(file_name):
Player.open_url(file_name)
break
def mouseDoubleClickEvent(self, event):
Player.fullscreen_switch()
def mouseReleaseEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton:
Player.play()
@staticmethod
def screenshot():
screenshot_win = ScreenshotWindow()
screenshot_win.setModal(True)
screenshot_win.exec()
@staticmethod
def zoom(value):
player.video_zoom += value
@staticmethod
def speed(speed):
player.speed = speed
@staticmethod
def timer_update():
Player.update_info()
Player.update_cursor()
def change_time(self):
if player.time_pos is not None and int(player.time_pos) != self.ui.time.value():
Player.new_position(self.ui.time.value())
def closeEvent(self, event):
Player.save_parameters()
def open_file(self):
file_name = QFileDialog.getOpenFileName(self, filter=f"{loc['All supported files']} ({' '.join(['*.' + f for f in formats])});;{loc['Video']} ({' '.join(['*.' + f for f in video_formats])});;{loc['Audio']} ({' '.join(['*.' + f for f in audio_formats])});;{loc['All files']} (*.*)")
if file_name[0] is not None and file_name[0] != '':
Player.open_file(file_name[0])
@staticmethod
def open_folder():
open_folder_win = OpenFolderWindow()
open_folder_win.setModal(True)
open_folder_win.exec()
@staticmethod
def open_url():
open_url_win = OpenURLWindow()
open_url_win.setModal(True)
open_url_win.exec()
def settings(self):
settings_win = SettingsWindow()
settings_win.setModal(True)
settings_win.exec()
if not config.get('volumePlus', False):
self.ui.volume.setValue(player.volume)
self.ui.volume.setMaximum(100)
else:
self.ui.volume.setMaximum(150)
@staticmethod
def about():
about_win = AboutWindow()
about_win.setModal(True)
about_win.exec()
@staticmethod
def reference():
reference_win = ReferenceWindow()
reference_win.setModal(True)
reference_win.exec()
def launch_parameters(self):
launch_parameters_win = LaunchParametersWindow()
launch_parameters_win.setModal(True)
launch_parameters_win.exec()
self.ui.volume.setValue(player.volume)
@staticmethod
def android_config():
android_config_win = AndroidConfigWindow()
android_config_win.setModal(True)
android_config_win.exec()
def right_panel_visible(self):
if Player.fullscreen:
Player.is_menu_visible = not Player.is_menu_visible
else:
self.ui.rightPanel.setVisible(not self.ui.rightPanel.isVisible())
def show_context_menu(self):
menu = QMenu()
menu.addAction(self.ui.action_Open_file)
menu.addAction(self.ui.action_Open_folder)
menu.addAction(self.ui.action_Open_URL)
menu.addAction(self.ui.action_Close)
menu.addSeparator()
menu.addMenu(self.ui.menu_Increasing_image_quality)
menu.addSeparator()
menu.addAction(self.ui.action_Play_Pause)
menu.addMenu(self.ui.menu_Playback_speed)
menu.addAction(self.ui.action_Playlist)
menu.addAction(self.ui.action_Zoom_in)
menu.addAction(self.ui.action_Zoom_out)
menu.addAction(self.ui.action_Take_a_screenshot)
menu.addAction(self.ui.action_Fullscreen)
menu.addSeparator()
menu.addAction(self.ui.action_Settings)
menu.addAction(self.ui.action_About)
menu.addSeparator()
menu.addAction(self.ui.action_Exit)
menu.exec(QCursor.pos())
def volume_plus(self):
if player.volume > 95 and self.ui.volume.maximum() == 100:
player.volume = 100
elif player.volume > 145 and self.ui.volume.maximum() == 150:
player.volume = 150
else:
player.volume += 5
self.ui.volume.setValue(player.volume)
Player.volume_update(player.volume)
def volume_minus(self):
if player.volume < 5:
player.volume = 0
else:
player.volume -= 5
self.ui.volume.setValue(player.volume)
Player.volume_update(player.volume)
@staticmethod
def rewind_plus():
if player.time_pos is not None:
player.seek(5)
window.ui.time.setValue(player.time_pos)
window.ui.currentTime.setText('{:02d}:{:02d}'.format(*divmod(int(player.time_pos), 60)))
@staticmethod
def rewind_minus():
if player.time_pos is not None:
if player.time_pos > 5:
player.seek(-5)
else:
player.time_pos = 0
window.ui.time.setValue(player.time_pos)
window.ui.currentTime.setText('{:02d}:{:02d}'.format(*divmod(int(player.time_pos), 60)))
class Player:
"""
Управление плеером
"""
folder: str = ''
filename: str = ''
files: list = []
filenames_only: list = []
filenum: int = -1
fullscreen: bool = False
is_menu_visible: bool = True
is_maximized: bool = False
audio: dict = {}
sub: dict = {}
duration: int = 0
info: dict = {
'preset': '',
'codec': '',
'resolution': '',
'fps': 0,
'frame_drop': 0
}
cursor_last: tuple = (0, 0)
cursor_timer: int = 0
@classmethod
def list_files(cls):
return [os.path.join(cls.folder, f) for f in os.listdir(cls.folder) if (f.split('.')[-1].lower() in formats)]
@classmethod
def list_filenames(cls):
filenames = [f for f in os.listdir(cls.folder) if (f.split('.')[-1].lower() in formats)]
return [f'{i + 1}) ' + filenames[i] for i in range(len(filenames))]
@classmethod
def sub_view(cls):
cls.sub = {}
if player.track_list is not None:
for track in player.track_list:
if track['type'] == 'sub':
if 'title' in track.keys():
cls.sub[track['id']] = f'{track["title"]}'
if 'lang' in track.keys():
cls.sub[track['id']] = f'{track["lang"]} - ' + cls.sub[track['id']]
elif 'lang' in track.keys():
cls.sub[track['id']] = f'{track["lang"]} - {track["codec"]}'
else:
cls.sub[track['id']] = track['codec']
def set_sub(index: int):
player.sid = index
def add_subtitles():
file_name = QFileDialog.getOpenFileName(filter=f"{loc['Subtitles']} ({' '.join(['*.' + f for f in subtitles_formats])});;{loc['All files']} (*.*)")
if file_name[0] is not None and file_name[0] != '':
player.sub_add(file_name[0])
menu_sub = QMenu()
if len(cls.sub) > 0:
action = QAction(window)
action.setText(loc['Disable'])
action.triggered.connect(lambda: set_sub(0))
menu_sub.addAction(action)
action = QAction(window)
action.setText(loc['Add subtitles'])
action.triggered.connect(add_subtitles)
menu_sub.addAction(action)
menu_sub.addSeparator()
for key, value in cls.sub.items():
action = QAction(window)
action.setText(f'{key}) {value}')
action.triggered.connect(lambda ignore=False, x=key: set_sub(x))
menu_sub.addAction(action)
else:
action = QAction(window)
action.setText(loc['Add subtitles'])
action.triggered.connect(add_subtitles)
menu_sub.addAction(action)
menu_sub.exec(window.ui.sub.mapToGlobal(QPoint(0, 0)))
@classmethod
def audio_view(cls):
cls.audio = {}
if player.track_list is not None:
for track in player.track_list:
if track['type'] == 'audio':
cls.audio[track['id']] = f'{track['codec']} {track['audio-channels']}ch {track['demux-samplerate']} Hz'
if 'title' in track.keys():
cls.audio[track['id']] = f'{track["title"]} (' + cls.audio[track['id']] + ')'
if 'lang' in track.keys():
cls.audio[track['id']] = f'{track["lang"]} - ' + cls.audio[track['id']]
elif 'lang' in track.keys():
cls.audio[track['id']] = f'{track["lang"]} - {cls.audio[track['id']]}'
def set_audio(index: int):
player.aid = index
menu_audio = QMenu()
if len(cls.audio) > 0:
action = QAction(window)
action.setText(loc['Disable'])
action.triggered.connect(lambda: set_audio(0))
menu_audio.addAction(action)
menu_audio.addSeparator()
for key, value in cls.audio.items():
action = QAction(window)
action.setText(f'{key}) {value}')
action.triggered.connect(lambda ignore=False, a=key: set_audio(a))
menu_audio.addAction(action)
else:
action = QAction(window)
action.setText(loc['No audio tracks'])
menu_audio.addAction(action)
menu_audio.exec(window.ui.audio.mapToGlobal(QPoint(0, 0)))
@classmethod
def update_info(cls, no_update_fps=True):
# duration = player.duration
time_pos = player.time_pos
Player.info['codec'] = player.video_format if player.video_format is not None else player.audio_codec_name
Player.info['resolution'] = (player.width, player.height)
if no_update_fps:
Player.info['fps'] = player.estimated_vf_fps
Player.info['frame_drop'] = player.frame_drop_count
# Обновление информации о разрешении, FPS, кодеке и потерянных кадрах
str_info = {
'preset': Player.info['preset'],
'codec': f'{Player.info["codec"].upper()}' if Player.info["codec"] is not None else '',
'resolution': f'{Player.info["resolution"][0]}x{Player.info["resolution"][1]}' if Player.info["resolution"] != (None, None) else '',
'fps': f'{round(Player.info["fps"], 1) if Player.info["fps"] is not None else "0.0"} FPS' if Player.info["resolution"] != (None, None) else '',
'frame_drop': f'{loc["Frames lost"]}: {Player.info["frame_drop"]}' if Player.info["frame_drop"] is not None else ''
}
window.ui.mediaInfo.setText(' | '.join([string for string in str_info.values() if string != '']))
# Обновление кнопки ИГРАТЬ
if player.duration is not None and player.pause:
window.ui.play.setIcon(QIcon(icons.play))
# Обновление ползунка прокрутки и времени
if player.duration is not None and time_pos is not None:
if cls.duration != player.duration:
cls.duration = player.duration
window.ui.time.setMaximum(cls.duration)
window.ui.allTime.setText('{:02d}:{:02d}'.format(*divmod(int(cls.duration), 60)))
window.ui.time.setValue(time_pos)
window.ui.currentTime.setText('{:02d}:{:02d}'.format(*divmod(int(time_pos), 60)))
else:
window.ui.time.setMaximum(0)
window.ui.time.setValue(0)
window.ui.currentTime.setText('00:00')
window.ui.allTime.setText('00:00')
@classmethod
def play_file(cls, file: str, timeout=3, position: float = 0):
player.play(file)
if position > 0:
try:
player.wait_for_property('duration', lambda val: val is not None, timeout=timeout)
except TimeoutError:
pass
else:
cls.new_position(position, slider_update=True)
@classmethod
def play(cls):
"""Воспроизведение / Пауза"""
if cls.filename != '':
if player.duration is None:
Player.play_file(cls.filename)
player.pause = False
window.ui.play.setIcon(QIcon(icons.pause))
elif not player.pause:
player.pause = True
window.ui.play.setIcon(QIcon(icons.play))
else:
player.pause = False
window.ui.play.setIcon(QIcon(icons.pause))
@classmethod
def next(cls):
"""Переход к следующему файлу"""
if cls.filenum < len(cls.files) - 1:
cls.filenum += 1
cls.filename = cls.files[cls.filenum]
window.ui.fileList.setCurrentRow(cls.filenum)
window.setWindowTitle(f'{cls.filename.rsplit(os.sep, 1)[-1]} - {name_program}')
Player.play_file(cls.filename)
@classmethod
def prev(cls):
"""Переход к предыдущему файлу"""
if cls.filenum > 0:
cls.filenum -= 1
cls.filename = cls.files[cls.filenum]
window.ui.fileList.setCurrentRow(cls.filenum)
window.setWindowTitle(f'{cls.filename.rsplit(os.sep, 1)[-1]} - {name_program}')
Player.play_file(cls.filename)
else:
cls.filenum = 0
window.ui.fileList.setCurrentRow(cls.filenum)
window.setWindowTitle(f'{cls.filename.rsplit(os.sep, 1)[-1]} - {name_program}')
@classmethod
def open_file(cls, file: str, pause: bool = False, position: float = 0):
"""
Открытие файла
:param file: путь к файлу
:param pause: должна ли стоять пауза после открытия
:param position: позиция
"""
file = file.replace('/', os.sep)
player.stop()
player.pause = pause
if pause:
window.ui.play.setIcon(QIcon(icons.play))
else:
window.ui.play.setIcon(QIcon(icons.pause))
cls.folder = file.rsplit(os.sep, 1)[0]
cls.files = [file]
cls.filenames_only = [file.split(os.sep)[-1]]
cls.filenum = 0
cls.filename = file
window.ui.fileList.clear()
window.ui.fileList.addItems(cls.filenames_only)
window.ui.fileList.setCurrentRow(cls.filenum)
window.ui.sourceInfo.setText(cls.folder)
window.setWindowTitle(f'{cls.filename.rsplit(os.sep, 1)[-1]} - {name_program}')
Player.play_file(cls.filename, position=position)
config.set('opened', ['file', file])
@classmethod
def open_url(cls, link: str, pause: bool = False, position: float = 0):
"""
Открытие с помощью URL-адреса
:param link: URL-адрес
:param pause: должна ли стоять пауза после открытия
:param position: позиция
"""
player.stop()
player.pause = pause
if pause:
window.ui.play.setIcon(QIcon(icons.play))
else:
window.ui.play.setIcon(QIcon(icons.pause))
cls.folder = 'URL'
cls.files = [link]
cls.filenames_only = []
cls.filenum = 0
cls.filename = link
window.ui.fileList.clear()
window.ui.fileList.addItems(cls.files)
window.ui.fileList.setCurrentRow(cls.filenum)
window.ui.sourceInfo.setText(cls.folder)
window.setWindowTitle(f'{cls.filename.rsplit("/", 1)[-1]} - {name_program}')
Player.play_file(cls.filename, position=position, timeout=5)
config.set('opened', ['url', link])
@classmethod
def open_folder(cls, folder: str, pause: bool = True, file: str = '', position: float = 0):
"""
Открытие папки
:param file:
:param folder: путь к папке
:param pause: должна ли стоять пауза после открытия
:param file: полное имя файла
:param position: позиция
"""
cls.folder = folder.replace('/', os.sep)
player.stop()
player.pause = pause
if pause:
window.ui.play.setIcon(QIcon(icons.play))
else:
window.ui.play.setIcon(QIcon(icons.pause))
cls.files = cls.list_files()
cls.filenames_only = cls.list_filenames()
if file != '' and os.path.exists(file):
cls.filenum = cls.files.index(file)
else:
cls.filenum = 0
if len(cls.files) != 0:
cls.filename = cls.files[cls.filenum]
window.setWindowTitle(f'{cls.filename.rsplit(os.sep, 1)[-1]} - {name_program}')
Player.play_file(cls.filename, position=position)
else:
cls.filename = ''
window.setWindowTitle(name_program)
window.ui.fileList.clear()
window.ui.fileList.addItems(cls.filenames_only)
window.ui.fileList.setCurrentRow(cls.filenum)
window.ui.rightPanel.setVisible(True)
window.ui.sourceInfo.setText(cls.folder)
config.set('opened', ['folder', folder])
@classmethod
def close(cls):
"""
Закрытие открытых фалов и переход в изначальное состояние
"""
player.stop()
player.pause = False
window.ui.play.setIcon(QIcon(icons.play))
cls.folder = ''
cls.filename = ''
cls.files = []
cls.filenames_only = []
cls.filenum = -1
window.ui.fileList.clear()
window.ui.sourceInfo.setText(loc['Information'])
# window['-AUDIO-'].update(menu_definition=['', []])
window.setWindowTitle(name_program)
config.set('opened', ['', ''])
@classmethod
def update_filelist(cls, file_name_in_list: str):
"""
Обновление списка файлов
:param file_name_in_list: Имя файла в списке файлов (вместе с номером)
"""
if len(cls.filenames_only) >= 1:
if len(cls.filenames_only) > 1 or len(file_name_in_list) > 1 and file_name_in_list[1] == ')':
filename_temp = os.path.join(cls.folder, file_name_in_list.split(' ', 1)[-1])
if cls.filename != filename_temp or cls.filenum < 0:
cls.filename = filename_temp
cls.filenum = cls.files.index(cls.filename)
Player.play_file(cls.filename)
window.setWindowTitle(f'{cls.filename.rsplit(os.sep, 1)[-1]} - {name_program}')
@classmethod
def fullscreen_switch(cls):
"""
Переключение полноэкранного режима
"""
if not cls.fullscreen:
cls.fullscreen = True
cls.is_maximized = window.isMaximized()
window.showFullScreen()
window.ui.menubar.setFixedHeight(0)
window.ui.controlPanel.setVisible(False)
cls.is_menu_visible = window.ui.rightPanel.isVisible()
window.ui.rightPanel.setVisible(False)
else:
cls.fullscreen = False
if cls.is_maximized:
window.showMaximized()
else:
window.showNormal()
window.ui.menubar.setFixedHeight(window.ui.menubar.sizeHint().height() + 1)
window.ui.controlPanel.setVisible(True)
window.ui.rightPanel.setVisible(cls.is_menu_visible)
window.ui.video.unsetCursor()
cls.cursor_timer = 0
@classmethod
def update_fullscreen_layout(cls, x: float, y: float):
if y > window.ui.centralwidget.size().height() - window.ui.controlPanel.height():
window.ui.controlPanel.setVisible(True)