This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
pikpakdown.py
6046 lines (4549 loc) · 225 KB
/
pikpakdown.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
# -*- coding: utf-8 -*-
import json
import os
app_config = {}
icon_content = {}
def set_config():
with open("config.json", "w") as jsonFile:
json.dump(app_config, jsonFile, indent=4, ensure_ascii=False)
jsonFile.close()
def read_config():
global app_config
if os.path.isfile("config.json") == True:
with open('config.json', 'r') as f:
# 读取数据并分割。 最后一个为空,所以去除
app_config = json.loads(f.read())
f.close()
else:
app_config = {
"user": "",
"password": "",
"Aria2_host": "",
"Aria2_port": "",
"Aria2_secret": "",
"download_url_key": "False",
"download_url_word": "",
"Aria2_path": "",
"domain_ip_key": "False",
"Potplayer_path": "",
"IDMplayer_path": "",
"Download_path": "",
"Webdav_admin": "",
"bitcomet_url": "",
"Webdav_password": "",
"Webdav_port": 9090,
"Proxy_type": "None",
"Proxy_ip": "",
"Proxy_port": "",
"Proxy_admin": "",
"Proxy_pass": "",
"Nginx_url":"",
"User_url": "",
"refresh_token": ""
}
with open("config.json", "w") as jsonFile:
json.dump(app_config, jsonFile, indent=4, ensure_ascii=False)
jsonFile.close()
read_config()
if app_config['Proxy_type'] == "None":
os.environ['no_proxy'] = '*'
elif app_config['Proxy_type'] == "系统代理":
import urllib.request
try:
proxy=urllib.request.getproxies()
print(proxy)
os.environ['HTTP_PROXY'] = str(proxy['http'])
os.environ['HTTPS_PROXY'] = str(proxy['http'])
except:
print("获取系统代理失败")
os.environ['no_proxy'] = '*'
else:
if app_config['Proxy_admin'] != "":
os.environ[
'HTTP_PROXY'] = f"{app_config['Proxy_type']}://{app_config['Proxy_admin']}:{app_config['Proxy_pass']}@{app_config['Proxy_ip']}:{app_config['Proxy_port']}"
os.environ[
'HTTPS_PROXY'] = f"{app_config['Proxy_type']}://{app_config['Proxy_admin']}:{app_config['Proxy_pass']}@{app_config['Proxy_ip']}:{app_config['Proxy_port']}"
else:
os.environ[
'HTTP_PROXY'] = f"{app_config['Proxy_type']}://{app_config['Proxy_ip']}:{app_config['Proxy_port']}"
os.environ[
'HTTPS_PROXY'] = f"{app_config['Proxy_type']}://{app_config['Proxy_ip']}:{app_config['Proxy_port']}"
from need.hashui import Ui_Addhash
from need.register import Ui_Register_Form
from need.yang import Ui_Form
from need.magnetui import Ui_MagnetDialog
from need.rename_fileui import Ui_Rename_file_Dialog
from need.web import Open_webdav_Worker
from need.creat_new_folderui import Ui_New_folder_Dialog
from need.phone import Ui_Phone_Form
import time
import re
from PyQt5.QtWidgets import QMessageBox,QDialogButtonBox
from need.pikabout import check_login, get_list, get_download_url,back_tash,Register_account_send,Register_account_get, \
get_offline_list, magnet_upload, gcid_hash_file,get_quate_info,push_vip_code,Phone_login_get,Phone_login_send,\
delete_task,get_trash_list,delete_tash,get_my_vip, \
get_headers, login, pikpak_add_hash, get_folder_all_file,creat_folder,copy_files,move_files,delete_files,rename_file
from need.plugins import thread_Bitcomet,thread_Thunder, thread_IDM, thread_pot, check_aria2, thread_aria2, Copy_downloadurl_Worker,Copy_magnet_Worker
import sys
from PyQt5.QtWidgets import QMenu, QTableWidget, QTableWidgetItem, QHeaderView, QTreeWidgetItem
from PyQt5.QtCore import QThread, QWaitCondition, QMutex, QPoint, QPropertyAnimation, QUrl
from PyQt5 import QtCore, QtWidgets, Qt
from PyQt5.QtWidgets import QFileDialog,QDesktopWidget
from PyQt5.QtGui import QMouseEvent, QIcon, QDesktopServices, QMovie,QIntValidator
from PyQt5.QtWidgets import QDialog, QLabel, \
QGridLayout, QSpacerItem, QSizePolicy, QGraphicsDropShadowEffect, \
QListWidget, QListWidgetItem,QPushButton
import need.res_rc
from PyQt5.QtCore import QEvent, QObject
from oss2 import StsAuth, Bucket
import oss2
import aria2p
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QPixmap, QImage, QPainterPath,QTextCursor
from functools import reduce # 导入排序模块
from PyQt5.QtCore import pyqtProperty, QSize, Qt, QRectF, QTimer
from PyQt5.QtGui import QColor, QPainter, QFont
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout
import threading
from ping3 import ping
import os,base64
import requests
from urllib.parse import urlparse
from io import BytesIO
from subprocess import Popen
import subprocess
upload_task=[]
normal_button_style = '''
QPushButton:!hover{
border:1px solid rgb(234,144,146);
color: rgb(234,144,146);
font: 75 14pt "微软雅黑";
border-radius:8px;
padding:5px 10px 5px 10px;
}
QPushButton:hover{
border:1px solid rgb(234,144,146);
background-color:#faefef;
color: rgb(234,144,146);
font: 75 14pt "微软雅黑";
border-radius:8px;
}
'''
running_button_style = '''
QPushButton:!hover{
border:1px solid rgb(234,144,146);
color: rgb(234,144,146);
font: 75 14pt "微软雅黑";
border-radius:8px;
padding:5px 10px 5px 10px;
}
QPushButton:hover{
border:1px solid rgb(234,144,146);
background-color:#faefef;
color: rgb(234,144,146);
font: 75 14pt "微软雅黑";
border-radius:8px;
}
'''
# 列表样式
HeaderView_style = '''
QTableWidget{
border:1px solid #ADADAD;
};
QHeaderView{
background-color: #F0F0F0;
border:1px solid #d0d0d0;
border-top-style:groove
text-align:center;
font:9pt '宋体';
color: #5B5B5B;
vertical-align:top;
};
'''
# 右键菜单样式
Menu_Style = """
QMenu {
/* 半透明效果 */
background-color: rgba(255, 255, 255, 230);
border: none;
border-radius: 4px;
}
QMenu::item {
border-radius: 4px;
/* 这个距离很麻烦需要根据菜单的长度和图标等因素微调 */
padding: 8px 48px 8px 36px; /* 36px是文字距离左侧距离*/
background-color: transparent;
}
/* 鼠标悬停和按下效果 */
QMenu::item:selected {
border-radius: 0px;
/* 半透明效果 */
background-color: rgba(232, 232, 232, 232);
}
/* 禁用效果 */
QMenu::item:disabled {
background-color: transparent;
}
/* 图标距离左侧距离 */
QMenu::icon {
left: 15px;
}
/* 分割线效果 */
QMenu::separator {
height: 1px;
background-color: rgb(232, 236, 243);
}
"""
# 滚动条样式
QScrollBar_style = '''
/*QScrollBar Style*/
/*纵向滚动条*/
QScrollBar:vertical {
background: transparent; /*背景透明*/
width: 10px; /*宽度*/
margin: 0px 0px 0px 0px; /**/
padding-top: 12px; /*距离上面12px*/
padding-bottom: 12px; /*距离底部12px*/
}
/*横向滚动条*/
QScrollBar:horizontal {
background: transparent;
height: 10px; /*高度*/
margin: 0px 0px 0px 0px;
padding-left: 12px; /*距离左边12px*/
padding-right: 12px; /*距离右边12px*/
}
/*当鼠标放到纵向或者横向滚动条上面时*/
QScrollBar:vertical:hover,QScrollBar:horizontal:hover {
background: rgba(0, 0, 0, 30); /*修改背景透明度 30*/
border-radius: 5px; /*圆角*/
}
/*纵向滚动条上面的滑块*/
QScrollBar::handle:vertical {
background: rgb(131,179,249);
width: 10px;
border-radius: 5px;
border: none;
}
/*横向滚动条上面的滑块*/
QScrollBar::handle:horizontal {
background: rgba(0, 0, 0, 50);
height: 10px;
border-radius: 5px;
border: none;
}
/*当鼠标放到滚动条滑块上面时改变透明度实现颜色的深浅变化*/
QScrollBar::handle:vertical:hover,QScrollBar::handle:horizontal:hover {
background: #6A6AFF;
}
/*纵向滚动条下部分块*/
QScrollBar::add-page:vertical {
width: 10px;
background: transparent;
}
/*横向滚动条后面部分块*/
QScrollBar::add-page:horizontal {
height: 10px;
background: transparent;
}
/*纵向滚动条上面部分块*/
QScrollBar::sub-page:vertical {
width: 10px;
background: transparent;
}
/*横向滚动条左部分块*/
QScrollBar::sub-page:horizontal {
height: 10px;
background: transparent;
}
/*纵向滚动条顶部三角形位置*/
QScrollBar::sub-line:vertical {
height: 12px;
width: 10px;
background: transparent;
subcontrol-position: top;
}
/*横向滚动条左侧三角形位置*/
QScrollBar::sub-line:horizontal {
height: 10px;
width: 12px;
background: transparent;
subcontrol-position: left;
}
/*纵向滚动条下面三角形部分*/
QScrollBar::add-line:vertical {
height: 12px;
width: 10px;
background: transparent;
subcontrol-position: bottom;
}
/*横向滚动条右边的三角形部分*/
QScrollBar::add-line:horizontal {
height: 10px;
width: 12px;
background: transparent;
subcontrol-position: right;
}
}'''
# 进度条样式
QProgressBar_StyleSheet = '''
QProgressBar::chunk {
background-color:rgb(58, 154, 255);
border-radius:4px;
}
QProgressBar {
border:none; /*无边框*/
background:white;
text-align:center; /*文本的位置*/
color: black; /*文本颜色*/
}
'''
aria2_button_style = '''QPushButton:!hover{
border:1px #369;
border-radius:8px;
}
QPushButton:hover{
border:1px #369;
background-color:#B9B9FF;
border-radius:8px;
}'''
def hum_convert(value):
try:
value = float(value)
except ValueError as e:
return value
if value == 0:
return "0"
units = ["B", "KB", "MB", "GB", "TB", "PB"]
size = 1024.0
for i in range(len(units)):
if (value / size) < 1:
return "%.2f%s" % (value, units[i])
value = value / size
# 提示框相关
class NotificationIcon:
Info, Success, Warning, Error, Close = range(5)
Types = {
Info: None,
Success: None,
Warning: None,
Error: None,
Close: None
}
@classmethod
def init(cls):
cls.Types[cls.Info] = QPixmap(QImage.fromData(base64.b64decode(
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAC5ElEQVRYR8VX0VHbQBB9e/bkN3QQU0FMBSEVYFcQ8xPBJLJ1FWAqOMcaxogfTAWQCiAVRKkgTgfmM4zRZu6QhGzL0p0nDPr17e7bt7tv14RX/uiV48MJgAon+8TiAMRtMFogaqUJxADPwRRzg67kl8+xbWJWANR40iPQSSFgtX/mGQkaDr56V3VAKgGos4s2JXwJoF3naMPvMS+SrpTHs032GwGkdF+DsFMVnJm/oyGGeHico0EjIjpYes+YMyVd6R/flfkpBWCCQ9zaZM2LZDfLMGXsZ5kdI/lYBmINgHHyyLd1mWdBbAFAM/GY7K2WYx1AeB4T6L1N9umbGxZ0qktATaEAdCps48D39oq/LwEw3U5CN92LfczJoewfT7MAywDCaEbAuxeLrh0zz4L+0e4aAJfGy+sP3IMxlH1vpMJoSMCJDXgWtJeJVc6ACs9HBBrYODCJAFdYvAmkPJxnNqMwYht7Bn+T/lGg3z4DGEd3RPhQ54DBvwAOVkeqagRXfTLjh+x7+8sALOtfHLuiYzWOAiLoKbD58mnIGbCmLxUepS6NQmYlUGE0JeCTTXT9JvA9E9sZgO5iIpoyc6/YzcqSwQzgG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kbiPnC9DxH5aHcd4FYGD5MOqVOg/muslh0/vphkm63k5eXZvA0I6qD+ZCI3jDzLxANiHn1NNvb6+30aVYgwLeeUsgFW1svsPA3Ncq4MHzVeO8AAAAASUVORK5CYII=')))
cls.Types[cls.Close] = QPixmap(QImage.fromData(base64.b64decode(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAeElEQVQ4T2NkoBAwUqifgboGzJy76AIjE3NCWmL0BWwumzV/qcH/f38XpCfHGcDkUVwAUsDw9+8GBmbmAHRDcMlheAGbQnwGYw0DZA1gp+JwFUgKZyDCDQGpwuIlrGGAHHAUGUCRFygKRIqjkeKERE6+oG5eIMcFAOqSchGwiKKAAAAAAElFTkSuQmCC')))
@classmethod
def icon(cls, ntype):
return cls.Types.get(ntype)
class NotificationItem(QWidget):
closed = pyqtSignal(QListWidgetItem)
def __init__(self, title, message, item, *args, ntype=0, callback=None, **kwargs):
super(NotificationItem, self).__init__(*args, **kwargs)
self.item = item
self.callback = callback
layout = QHBoxLayout(self, spacing=0)
layout.setContentsMargins(0, 0, 0, 0)
self.bgWidget = QWidget(self) # 背景控件, 用于支持动画效果
layout.addWidget(self.bgWidget)
layout = QGridLayout(self.bgWidget)
layout.setHorizontalSpacing(15)
layout.setVerticalSpacing(10)
# 标题左边图标
layout.addWidget(
QLabel(self, pixmap=NotificationIcon.icon(ntype)), 0, 0)
# 标题
self.labelTitle = QLabel(title, self)
font = self.labelTitle.font()
font.setBold(True)
font.setPixelSize(22)
self.labelTitle.setFont(font)
# 关闭按钮
self.labelClose = QLabel(
self, cursor=Qt.PointingHandCursor, pixmap=NotificationIcon.icon(NotificationIcon.Close))
# 消息内容
self.labelMessage = QLabel(
message, self, cursor=Qt.PointingHandCursor, wordWrap=True, alignment=Qt.AlignLeft | Qt.AlignTop)
font = self.labelMessage.font()
font.setPixelSize(20)
self.labelMessage.setFont(font)
self.labelMessage.adjustSize()
# 添加到布局
layout.addWidget(self.labelTitle, 0, 1)
layout.addItem(QSpacerItem(
40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum), 0, 2)
layout.addWidget(self.labelClose, 0, 3)
layout.addWidget(self.labelMessage, 1, 1, 1, 2)
# 边框阴影
effect = QGraphicsDropShadowEffect(self)
effect.setBlurRadius(12)
effect.setColor(QColor(0, 0, 0, 25))
effect.setOffset(0, 2)
self.setGraphicsEffect(effect)
self.adjustSize()
# 5秒自动关闭
self._timer = QTimer(self, timeout=self.doClose)
self._timer.setSingleShot(True) # 只触发一次
self._timer.start(5000)
def doClose(self):
try:
# 可能由于手动点击导致item已经被删除了
self.closed.emit(self.item)
except:
pass
def showAnimation(self, width):
# 显示动画
pass
def closeAnimation(self):
# 关闭动画
pass
def mousePressEvent(self, event):
super(NotificationItem, self).mousePressEvent(event)
w = self.childAt(event.pos())
if not w:
return
if w == self.labelClose: # 点击关闭图标
# 先尝试停止计时器
self._timer.stop()
self.closed.emit(self.item)
elif w == self.labelMessage and self.callback and callable(self.callback):
# 点击消息内容
self._timer.stop()
self.closed.emit(self.item)
self.callback() # 回调
def paintEvent(self, event):
# 圆角以及背景色
super(NotificationItem, self).paintEvent(event)
painter = QPainter(self)
path = QPainterPath()
path.addRoundedRect(QRectF(self.rect()), 6, 6)
painter.fillPath(path, Qt.white)
class NotificationWindow(QListWidget):
_instance = None
def __init__(self, *args, **kwargs):
super(NotificationWindow, self).__init__(*args, **kwargs)
self.setSpacing(20)
self.setMinimumWidth(412)
self.setMaximumWidth(412)
QApplication.instance().setQuitOnLastWindowClosed(True)
# 隐藏任务栏,无边框,置顶等
self.setWindowFlags(self.windowFlags() | Qt.Tool |
Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
# 去掉窗口边框
self.setFrameShape(self.NoFrame)
# 背景透明
self.viewport().setAutoFillBackground(False)
self.setAttribute(Qt.WA_TranslucentBackground, True)
# 不显示滚动条
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# 获取屏幕高宽
rect = QApplication.instance().desktop().availableGeometry(self)
self.setMinimumHeight(rect.height())
self.setMaximumHeight(rect.height())
self.move(rect.width() - self.minimumWidth() - 18, 0)
def removeItem(self, item):
# 删除item
w = self.itemWidget(item)
self.removeItemWidget(item)
item = self.takeItem(self.indexFromItem(item).row())
w.close()
w.deleteLater()
del item
@classmethod
def _createInstance(cls):
# 创建实例
if not cls._instance:
cls._instance = NotificationWindow()
cls._instance.show()
NotificationIcon.init()
@classmethod
def info(cls, title, message, callback=None):
cls._createInstance()
item = QListWidgetItem(cls._instance)
w = NotificationItem(title, message, item, cls._instance,
ntype=NotificationIcon.Info, callback=callback)
w.closed.connect(cls._instance.removeItem)
item.setSizeHint(QSize(cls._instance.width() -
cls._instance.spacing(), w.height()))
cls._instance.setItemWidget(item, w)
@classmethod
def success(cls, title, message, callback=None):
cls._createInstance()
item = QListWidgetItem(cls._instance)
w = NotificationItem(title, message, item, cls._instance,
ntype=NotificationIcon.Success, callback=callback)
w.closed.connect(cls._instance.removeItem)
item.setSizeHint(QSize(cls._instance.width() -
cls._instance.spacing(), w.height()))
cls._instance.setItemWidget(item, w)
@classmethod
def warning(cls, title, message, callback=None):
cls._createInstance()
item = QListWidgetItem(cls._instance)
w = NotificationItem(title, message, item, cls._instance,
ntype=NotificationIcon.Warning, callback=callback)
w.closed.connect(cls._instance.removeItem)
item.setSizeHint(QSize(cls._instance.width() -
cls._instance.spacing(), w.height()))
cls._instance.setItemWidget(item, w)
@classmethod
def error(cls, title, message, callback=None):
cls._createInstance()
item = QListWidgetItem(cls._instance)
w = NotificationItem(title, message, item,
ntype=NotificationIcon.Error, callback=callback)
w.closed.connect(cls._instance.removeItem)
width = cls._instance.width() - cls._instance.spacing()
item.setSizeHint(QSize(width, w.height()))
cls._instance.setItemWidget(item, w)
# 主页刷新调用
class refreshThread(QThread):
refresh_proess_signal = pyqtSignal(list) # 创建信号
def __init__(self, folder_id):
super(refreshThread, self).__init__()
self.folder_id = folder_id
def start_choose_icon(self, icon_url):
global icon_content
if icon_url in icon_content:
return icon_content[icon_url]
else:
try:
result = requests.get(icon_url, timeout=5).content
icon_content[icon_url] = result
return result
except:
return ""
def run(self):
try:
file_list = get_list(self.folder_id)
for a in range(len(file_list)):
file_list[a]['icon_content']=self.start_choose_icon(icon_url=file_list[a]['icon_link'])
self.refresh_proess_signal.emit(file_list) # 发送信号
except:
(type, value, traceback) = sys.exc_info()
sys.excepthook(type, value, traceback)
# 下载调用
class downloadThread(QThread):
download_proess_signal = pyqtSignal(list) # 创建信号
def __init__(self, url, filesize, file_name, buffer, down_path):
super(downloadThread, self).__init__()
if app_config['Download_path'] != "":
self.file_path = f"{app_config['Download_path']}/{down_path}"
if not os.path.exists(self.file_path):
os.makedirs(self.file_path)
else:
self.file_path = f"下载/{down_path}"
parent_path = os.path.dirname(self.file_path)
if not os.path.exists(self.file_path):
os.makedirs(self.file_path)
self.file_name = file_name
self.url = url
self.filesize = filesize
self.buffer = buffer
self.download_list = []
self.currdownload = None
self.aria2 = aria2p.API(
aria2p.Client(
host="http://127.0.0.1",
port=29385,
secret="pikpakdown"
)
)
try:
sta = self.aria2.get_stats()
except Exception as e:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Error ({new_time}):本地aria2未启动,即将启动")
pid = os.getpid()
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE |subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
subprocess.Popen(
["Aria2/aria2c.exe", '--enable-rpc=true', f'--stop-with-process={pid}', '--conf-path=Aria2/aria2.conf',
"--rpc-listen-port=29385", '--rpc-secret=pikpakdown'], startupinfo=startupinfo)
try:
sta = self.aria2.get_stats()
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"INFO ({new_time}):本地Aria2启动成功")
except Exception as e:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Error ({new_time}):连接本地Aria2失败:{e}")
return
def run(self):
try:
currdownload = self.aria2.add_uris([self.url], options={"dir": self.file_path, "out": self.file_name})
self.currdownload = currdownload
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Info ({new_time}):内部下载添加任务:{self.file_name} 路径:{self.file_path}")
except Exception as e:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Error ({new_time}):添加下载任务失败:{self.file_name}:{e}")
return None
# 上传调用
class uploadThread(QThread):
upload_proess_signal = pyqtSignal(list) # 创建信号
def __init__(self, path, folder_id, row):
super(uploadThread, self).__init__()
try:
self.folder_id = folder_id
self.file_path = path
self.old_time = 0
self.old_part = 0
self.row = row
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Info ({new_time}):开始上传:{path}")
self._isPause = False
self._isRemove = False
self._value = 0
self.cond = QWaitCondition()
self.mutex = QMutex()
except Exception as e:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Error ({new_time}):上传错误:{e}")
def pause(self):
self._isPause = True
upload_task.append(str(QThread.currentThread()))
def resume(self):
self._isPause = False
self.cond.wakeAll()
def remove(self):
self._isRemove = True
self.cond.wakeAll()
def percentage(self, consumed_bytes, total_bytes):
"""进度条回调函数,计算当前完成的百分比
:param consumed_bytes: 已经上传/下载的数据量
:param total_bytes: 总数据量
"""
self.mutex.lock()
if self._isPause:
self.upload_proess_signal.emit([0, self.row, '0M/S', "上传暂停"]) # 发送信号
self.cond.wait(self.mutex)
for a in upload_task:
if a == str(QThread.currentThread()):
upload_task.remove(a)
break
if self._isRemove:
self.upload_proess_signal.emit([0, self.row, '0M/S', "上传删除"]) # 发送信号
# self.exit(0) # 关闭线程
for a in upload_task:
if a == str(QThread.currentThread()):
upload_task.remove(a)
break
QThread.exit(0)
if total_bytes:
if self.old_time == 0:
self.old_time = time.time()
self.old_part = float(consumed_bytes)
else:
if time.time() - self.old_time > 2:
if float(consumed_bytes) != self.old_part:
speed = (float(consumed_bytes) - self.old_part) / 1024 / 1024 / 2
else:
speed = 0
self.old_time = time.time()
self.old_part = float(consumed_bytes)
rate = int(100 * (float(consumed_bytes) / float(total_bytes)))
self.upload_proess_signal.emit([rate, self.row, '%.2fM/S' % speed, "上传中"]) # 发送信号
else:
self.upload_proess_signal.emit([100, self.row, '0M/S', "上传完成"]) # 发送信号
self.mutex.unlock()
def run(self):
try:
self.upload_proess_signal.emit([0, self.row, '0M/S', "开始计算hash"]) # 发送信号
file_hash, file_size, filename = gcid_hash_file(self.file_path)
if app_config['Nginx_url'] == "":
pikpak_api_url = "https://api-drive.mypikpak.com"
else:
pikpak_api_url = app_config['Nginx_url']
upload_url = f"{pikpak_api_url}/drive/v1/files"
login_headers = get_headers()
upload_url_data = {
"kind": "drive#file",
"name": str(filename),
"size": int(file_size),
"hash": str(file_hash),
"upload_type": "UPLOAD_TYPE_RESUMABLE",
"objProvider": {"provider": "UPLOAD_TYPE_UNKNOWN"}}
if self.folder_id != "":
upload_url_data["parent_id"] = self.folder_id
upload_result = requests.post(url=upload_url, headers=login_headers, json=upload_url_data, timeout=5).json()
if "error" in upload_result:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Info ({new_time}):登录过期,正在重新登录")
login()
login_headers = get_headers()
upload_result = requests.post(url=upload_url, headers=login_headers, json=upload_url_data, timeout=5)
if 'resumable' in upload_result:
auth = StsAuth(access_key_id=upload_result['resumable']['params']['access_key_id'],
access_key_secret=upload_result['resumable']['params']['access_key_secret'],
security_token=upload_result['resumable']['params']['security_token']
)
# Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = Bucket(auth=auth,
endpoint=f"https://{upload_result['resumable']['params']['endpoint']}",
bucket_name=upload_result['resumable']['params']['bucket'], is_cname=True,
)
key = upload_result['resumable']['params']['key']
oss2.resumable_upload(bucket, key, self.file_path,
multipart_threshold=265 * 1024,
part_size=265 * 1024,
num_threads=2,
progress_callback=self.percentage)
self.upload_proess_signal.emit([100, self.row, '0M/S', "上传完成"]) # 发送信号
else:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Info ({new_time}):已存在,直接秒传:{filename}")
self.upload_proess_signal.emit([100, self.row, '%.2fM/S' % 0, "秒传完成"]) # 发送信号
for a in upload_task:
if a == str(self.row):
upload_task.remove(a)
break
self.exit()
except Exception as e:
new_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"Error ({new_time}):上传失败:{e}")
self.upload_proess_signal.emit([0, self.row, '0M/S', "上传失败"]) # 发送信号
# 添加磁力子弹窗
class MyMagnet_Form(QDialog, Ui_MagnetDialog):
_signal = QtCore.pyqtSignal(str)
def __init__(self, parent=None):
super(MyMagnet_Form, self).__init__(parent)
self.setupUi(self)
# 将子窗口置顶
self.setWindowModality(QtCore.Qt.ApplicationModal)
# dialog相关
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground, True)
# self.widget.setStyleSheet(Widget_Stylesheet)
# 添加阴影
effect = QGraphicsDropShadowEffect(self)
effect.setBlurRadius(12)
effect.setOffset(0, 0)
effect.setColor(Qt.gray)
self.setGraphicsEffect(effect)
self.magnetpushButton.clicked.connect(self.push_new_magnnet)
self.cloeseButton.clicked.connect(self.close)
# 窗口淡化动画
self.animation = QPropertyAnimation(self, b'windowOpacity')
self.animation.setDuration(500) # 持续时间1秒
self.doShow()
###
# 窗口淡化动画
def doShow(self):
try:
# 尝试先取消动画完成后关闭窗口的信号
self.animation.finished.disconnect(self.close)
except:
pass
self.animation.stop()
# 透明度范围从0逐渐增加到1
self.animation.setStartValue(0)
self.animation.setEndValue(1)
self.animation.start()
def doClose(self):
self.animation.stop()
self.animation.finished.connect(self.close) # 动画完成则关闭窗口
# 透明度范围从1逐渐减少到0
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.animation.start()
###
# 鼠标移动事件
def mouseMoveEvent(self, e: QMouseEvent): # 重写移动事件
if self._tracking:
self._endPos = e.pos() - self._startPos
self.move(self.pos() + self._endPos)
def mousePressEvent(self, e: QMouseEvent):
if e.button() == Qt.LeftButton:
self._startPos = QPoint(e.x(), e.y())
self._tracking = True
def mouseReleaseEvent(self, e: QMouseEvent):
if e.button() == Qt.LeftButton:
self._tracking = False
self._startPos = None
self._endPos = None
###
def push_new_magnnet(self):
magnet_url = self.magnettextEdit.toPlainText()
if magnet_url == "":
QMessageBox.information(self, "提示", "输入框为空")
return
self._signal.emit(magnet_url)
self.close()
# 添加秒传子弹窗
class MyHash_Form(QDialog, Ui_Addhash):
# 定义信号
_signal = QtCore.pyqtSignal(list)
def __init__(self, parent=None):
super(MyHash_Form, self).__init__(parent)
self.setupUi(self)
# 将子窗口置顶
self.setWindowModality(QtCore.Qt.ApplicationModal)
# dialog相关
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground, True)