forked from einstein95/crunchy-xml-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crunchy-xml-decoder.py
368 lines (327 loc) · 12.3 KB
/
crunchy-xml-decoder.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import argparse
import os
import subprocess
from getpass import getpass
sys.path.append('crunchy-xml-decoder')
import functtest
import ultimate
import login
import decode
import altfuncs
import time
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#(CHECKING)#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
if not os.path.exists("export"):
os.makedirs("export")
iquality = 'highest'
ilang1 = 'English'
ilang2 = 'English'
iforcesub = False
iforceusa = False
ilocalizecookies = False
def defaultsettings(vvquality, vlang1, vlang2, vforcesub, vforceusa, vlocalizecookies):
dsettings='''[SETTINGS]
# Set this to the preferred quality. Possible values are: "android" (hard-subbed), "360p", "480p", "720p", "1080p", or "highest" for highest available.
# Note that any quality higher than 360p still requires premium, unless it's available that way for free (some first episodes).
# We're not miracle workers.
video_quality = '''+vvquality+'''
# Set this to the desired subtitle language. If the subtitles aren't available in that language, it reverts to the second language option (below).
# Available languages: English, Espanol, Espanol_Espana, Francais, Portugues, Turkce, Italiano, Arabic, Deutsch
language = '''+vlang1+'''
# If the first language isn't available, what language would you like as a backup? Only if then they aren't found, then it goes to English as default
language2 = '''+vlang2+'''
# Set this if you want to use --forced-track rather than --default-track for subtitle
forcesubtitle = '''+str(vforcesub)+'''
# Set this if you want to use a US session ID
forceusa = '''+str(vforceusa)+'''
# Set this if you want to Localize the cookies (this option is under testing and may generate some problem and it willnot work with -forceusa- option)
localizecookies = '''+str(vlocalizecookies)+'''
'''
open('.\\settings.ini', 'w').write(dsettings.encode('utf-8'))
if not os.path.exists(".\\settings.ini"):
defaultsettings(iquality, ilang1, ilang2, iforcesub, iforceusa, ilocalizecookies)
if not os.path.exists(".\\cookies"):
if raw_input(u'Do you have an account [Y/N]?').lower() == 'y':
username = raw_input(u'Username: ')
password = getpass('Password(don\'t worry the password are typing but hidden:')
login.login(username, password)
else:
login.login('', '')
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#(Argument Parser)#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
parser = argparse.ArgumentParser()
parser.add_argument("-u","--url", type=str,help="Crunchyroll Anime Link. if you get an error, try using double quotation marks (\")")
parser.add_argument("-sn","--season-number", metavar='#', type=int, nargs = 1, help="Crunchyroll Anime Season Number,it's optional option you can ignore")
parser.add_argument("-en","--episode-number", metavar='#', type=int, nargs = 1, help="Crunchyroll Anime Episode Number,it's optional option you can ignore")
parser.add_argument("-l","--login", metavar=('Username','Password'), nargs = 2, help="Crunchyroll login: -l User password. if your password has a blank, use double quotation marks (\"). Example: \"This is a password.\"")
parser.add_argument("-g","--guest", action='store_true', help="Crunchyroll login as guest")
parser.add_argument("-s","--subs-only", action='store_true', help="Download Crunchyroll Anime Subtitle only. if you get an error, try using double quotation marks (\")")
parser.add_argument("-q","--queue", type=str, nargs = '?', metavar='Queue Directory', const='.\\queue.txt', help="Run List of Crunchyroll Anime Link in queue file")
parser.add_argument("-d","--debug", action='store_true', help="Run crunchy-xml-decoder in Debug Mode")
parser.add_argument("-ds","--default-settings", action='store_true', help="Restore default settings")
arg = parser.parse_args()
sys.argv=[]
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#( )#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
def queueu(queuepath):
if not os.path.exists(queuepath):
open(queuepath, 'w').write(u'#the any line that has hash before the link will be skiped\n')
subprocess.call('notepad.exe '+queuepath)
lines = open(queuepath).readlines()
for line in lines:
if line.rstrip('\n') ==''.join(line.rstrip('\n').split('#', 1)):
#print ''.join(line.rstrip('\n').split('#', 1))
ultimate.ultimate(line.rstrip('\n'), '', '')
for i in range(0, len(lines)):
if lines[i]== line:
lines[i]='#'+lines[i]
new_line_2=''
for new_line_ in lines:
try:
new_line_2=new_line_2+new_line_
except:
new_line_2=new_line_
open(queuepath, 'w').write(new_line_2)
def Languages_(Varname_):
seleccion = 0
if Varname_ == 'slang1':
print '''Set this to the desired subtitle language. If the subtitles aren\'t available in that language, it reverts to the Secondary language option'''
if Varname_ == 'slang2':
print '''If the Primary language isn't available, what language would you like as a backup? Only if then they aren't found, then it goes to English as default'''
print '''Available Languages:
0.- English
1.- Espanol
2.- Espanol (Espana)
3.- Francais
4.- Portugues
5.- Turkce
6.- Italiano
7.- Arabic
8.- Deutsch
'''
try:
seleccion = int(input("> "))
except:
print "ERROR: Invalid option."
Languages_()
if seleccion == 1 :
return 'Espanol'
elif seleccion == 2 :
return 'Espanol_Espana'
elif seleccion == 3 :
return 'Francais'
elif seleccion == 4 :
return 'Portugues'
elif seleccion == 5 :
return 'Turkce'
elif seleccion == 6 :
return 'Italiano'
elif seleccion == 7 :
return 'Arabic'
elif seleccion == 8 :
return 'Deutsch'
elif seleccion == 0 :
return 'English'
else:
print "ERROR: Invalid option."
Languages_()
def videoquality_():
slang1, slang2, sforcesub, sforceusa, slocalizecookies, vquality = altfuncs.config()
seleccion = 5
print '''Set This To The Preferred Quality:
0.- android (hard-subbed)
1.- 360p
2.- 480p
3.- 720p
4.- 1080p
5.- highest
Note: Any Quality Higher Than 360p Still Requires Premium, Unless It's Available That Way For Free (Some First Episodes).
We're Not Miracle Workers.
'''
try:
seleccion = int(input("> "))
except:
print "ERROR: Invalid option."
videoquality_()
if seleccion == 0 :
return 'android'
elif seleccion == 1 :
return '360p'
elif seleccion == 2 :
return '480p'
elif seleccion == 3 :
return '720p'
elif seleccion == 4 :
return '1080p'
elif seleccion == 5 :
return 'highest'
else:
print "ERROR: Invalid option."
videoquality_()
def settings_():
slang1, slang2, sforcesub, sforceusa, slocalizecookies, vquality = altfuncs.config()
slang1 = {u'Español (Espana)' : 'Espanol_Espana', u'Français (France)' : 'Francais', u'Português (Brasil)' : 'Portugues',
u'English' : 'English', u'Español' : 'Espanol', u'Türkçe' : 'Turkce', u'Italiano' : 'Italiano',
u'العربية' : 'Arabic', u'Deutsch' : 'Deutsch'}[slang1]
slang2 = {u'Español (Espana)' : 'Espanol_Espana', u'Français (France)' : 'Francais', u'Português (Brasil)' : 'Portugues',
u'English' : 'English', u'Español' : 'Espanol', u'Türkçe' : 'Turkce', u'Italiano' : 'Italiano',
u'العربية' : 'Arabic', u'Deutsch' : 'Deutsch'}[slang2]
if slang1 == 'Espanol_Espana':
slang1_ = 'Espanol (Espana)'
else:
slang1_ = slang1
if slang2 == 'Espanol_Espana':
slang2_ = 'Espanol (Espana)'
else:
slang2_ = slang2
seleccion = 0
print '''Options:
0.- Exit
1.- Video Quality = '''+vquality+'''
2.- Primary Language = '''+slang1_+'''
3.- Secondary Language = '''+slang2_+'''
4.- Force Subtitle = '''+str(sforcesub)+''' #Use --forced-track in Subtitle
5.- USA Proxy = '''+str(sforceusa)+''' #use a US session ID
6.- Localize cookies = '''+str(slocalizecookies)+''' #Localize the cookies (Experiment)
7.- Restore Default Settings
'''
try:
seleccion = int(input("> "))
except:
print "ERROR: Invalid option."
settings_()
if seleccion == 1 :
vquality = videoquality_()
defaultsettings(vquality, slang1, slang2, sforcesub, sforceusa, slocalizecookies)
settings_()
elif seleccion == 2 :
slang1 = Languages_('slang1')
defaultsettings(vquality, slang1, slang2, sforcesub, sforceusa, slocalizecookies)
settings_()
elif seleccion == 3 :
slang2 = Languages_('slang2')
defaultsettings(vquality, slang1, slang2, sforcesub, sforceusa, slocalizecookies)
settings_()
elif seleccion == 4 :
if sforcesub:
sforcesub = False
else:
sforcesub = True
defaultsettings(vquality, slang1, slang2, sforcesub, sforceusa, slocalizecookies)
settings_()
elif seleccion == 5 :
if sforceusa:
sforceusa = False
else:
sforceusa = True
defaultsettings(vquality, slang1, slang2, sforcesub, sforceusa, slocalizecookies)
settings_()
elif seleccion == 6 :
if slocalizecookies:
slocalizecookies = False
else:
slocalizecookies = True
defaultsettings(vquality, slang1, slang2, sforcesub, sforceusa, slocalizecookies)
settings_()
elif seleccion == 7 :
defaultsettings(iquality, ilang1, ilang2, iforcesub, iforceusa, ilocalizecookies)
settings_()
elif seleccion == 0 :
pass
else:
print "ERROR: Invalid option."
settings_()
def makechoise():
seleccion = 0
print '''Options:
0.- Exit
1.- Download Anime
2.- Download Subtitle only
3.- Login
4.- Login As Guest
5.- Run Queue
6.- Settings
'''
try:
seleccion = int(input("> "))
except:
try:
os.system('cls')
except:
try:
os.system('clear')
except:
pass
print "ERROR: Invalid option."
makechoise()
if seleccion == 1 :
ultimate.ultimate(raw_input('Please enter Crunchyroll video URL:\n'), '', '')
elif seleccion == 2 :
decode.decode(raw_input('Please enter Crunchyroll video URL:\n'))
elif seleccion == 3 :
username = raw_input(u'Username: ')
password = getpass('Password(don\'t worry the password are typing but hidden:')
login.login(username, password)
makechoise()
elif seleccion == 4 :
login.login('', '')
makechoise()
elif seleccion == 5 :
queueu('.\\queue.txt')
elif seleccion == 6 :
settings_()
makechoise()
elif seleccion == 7 :
import debug
elif seleccion == 0 :
sys.exit()
else:
try:
os.system('cls')
except:
try:
os.system('clear')
except:
pass
print "ERROR: Invalid option."
makechoise()
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#( )#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
if arg.url:
page_url = arg.url
if arg.season_number:
seasonnum = arg.season_number[0]
else:
seasonnum = ''
if arg.episode_number:
epnum = arg.episode_number[0]
else:
epnum = ''
if arg.guest:
login.login('', '')
if arg.login:
username = arg.login[0]
password = arg.login[1]
login.login(username, password)
if arg.debug:
import debug
sys.exit()
if arg.subs_only:
if arg.url:
decode.decode(page_url)
else:
decode.decode(raw_input('Please enter Crunchyroll video URL:\n'))
sys.exit()
if arg.default_settings:
defaultsettings(iquality, ilang1, ilang2, iforcesub, iforceusa, ilocalizecookies)
sys.exit()
if arg.queue:
queueu(arg.queue)
if arg.url and not arg.subs_only:
ultimate.ultimate(page_url, seasonnum, epnum)
else:
makechoise()
#print 'username'
#print 'password'
#print 'page_url'
#print 'seasonnum'
#import ultimate