-
Notifications
You must be signed in to change notification settings - Fork 2
/
Downloads.py
84 lines (70 loc) · 2.84 KB
/
Downloads.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
from os import system, chdir, remove, getcwd
from os import name as systemName
import sys
from you_get import common as you_get
import multiprocessing as mp
from glob import glob
import pickle
class Download(object):
def __init__(self,Ep_info_list):
self.Ep_info_list = Ep_info_list
def __clearTerminal(self):
if systemName =='nt':
system('cls')
elif systemName == 'posix':
system('clear')
def __creatDict(self,listT,st,end):
dictT = {}
for i,j in zip(range(st,end+1),listT):
dictT[i] = j
return dictT
def __use_youget(self,down_url_dict):
redownDict={}
for i in list(down_url_dict.keys()):
try:
sys.argv=['you-get',down_url_dict[i]]
you_get.main()
self.__clearTerminal()
except:
print("""
""")
print("下载{}的过程出了点问题,稍后会重新下载".format(down_url_dict[i]))
print("""
""")
redownDict[i] = down_url_dict[i]
return redownDict
def down_load(self):
print("请问要从第几集开始下载?")
startEp_id = int(input(">>> "))
print("要下载到第几集?")
endEp_id = int(input(">>> "))
down_list = self.Ep_info_list[startEp_id-1:endEp_id]
down_dict = self.__creatDict(down_list,startEp_id,endEp_id)
print("马上开始下载,请稍后...")
redown = self.__use_youget(down_dict)
tryNum = 0
while len(redown) != 0 and tryNum < 5:
redown = self.__use_youget(redown)
tryNum += 1
self.__clearTerminal()
if len(redown)>1:
print("对不起,下载无能为力,请等以后的版本")
print("没能下载的有一下几集:")
print(str(redown))
removeList = glob(r"./*.xml")
for x in removeList:
remove(x)
print("下载好的文件放在在这里了:{}".format(getcwd()))
print("""
##################################################################
#### ####
#### ####
#### ####
#### 下载已经完成 ####
#### ####
#### 按回车键退出程序 ####
#### ####
#### ####
##################################################################
""")
input()