Skip to content

Commit

Permalink
v1.2.2 quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NoAiOne committed Jan 21, 2020
1 parent 740e60c commit 30d2fcf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 55 deletions.
2 changes: 1 addition & 1 deletion yuu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .ext import *

__version__ = "1.2.1"
__version__ = "1.2.2"


def version_compare(new_version):
Expand Down
94 changes: 40 additions & 54 deletions yuu/ext/abematv.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self, url, session):
self.url = url
self.m3u8_url = None
self.resolution = None
self.resolution_o = None
self.device_id = None
self.is_m3u8 = False
self.est_filesize = None # In MiB
Expand Down Expand Up @@ -272,6 +273,7 @@ def parse(self, resolution=None, check_only=False):

if resolution == 'best':
resolution = '1080p'
self.resolution_o = 'best'
if resolution == 'worst':
resolution = '180p'

Expand Down Expand Up @@ -408,6 +410,10 @@ def parse(self, resolution=None, check_only=False):
self.yuu_logger.debug('Data requested')
self.yuu_logger.debug('Parsing json API')
jsdata = req.json()
if jsdata['mediaStatus']:
if 'drm' in jsdata['mediaStatus']:
if jsdata['mediaStatus']['drm']:
return None, 'This video has a different DRM method and cannot be decrypted by yuu for now'
title = jsdata['series']['title']
epnum = jsdata['episode']['title']
hls = jsdata['playback']['hls']
Expand Down Expand Up @@ -444,7 +450,11 @@ def parse_m3u8(self, m3u8_url):
files = x.files[1:]
if not files[0]:
files = files[1:]
if 'tsda' in files[5]:
# Assume DRMed
return None, None, None, 'This video has a different DRM method and cannot be decrypted by yuu for now'
resgex = re.findall(r'(\d*)(?:\/\w+.ts)', files[0])[0]
keys_data = x.keys[0]
iv = x.keys[0].iv
ticket = x.keys[0].uri[18:]

Expand All @@ -455,6 +465,8 @@ def parse_m3u8(self, m3u8_url):
parsed_files.append(f)

if self.resolution[:-1] != resgex:
if not self.resolution_o:
self.yuu_logger.warn('Changing resolution, from {} to {}p'.format(self.resolution, resgex))
self.resolution = resgex + 'p'
self.yuu_logger.debug('Total files: {}'.format(len(files)))
self.yuu_logger.debug('IV: {}'.format(iv))
Expand Down Expand Up @@ -517,79 +529,53 @@ def resolutions(self, m3u8_uri):
self.yuu_logger.debug('Requesting data to API')

m3u8_ = m3u8_uri[:m3u8_uri.rfind('/')]
base_url = m3u8_[:m3u8_.rfind('/')] + '/'
m3u8_1080 = m3u8_[:m3u8_.rfind('/')] + '/1080/playlist.m3u8'
m3u8_720 = m3u8_[:m3u8_.rfind('/')] + '/720/playlist.m3u8'
m3u8_480 = m3u8_[:m3u8_.rfind('/')] + '/480/playlist.m3u8'
m3u8_360 = m3u8_[:m3u8_.rfind('/')] + '/360/playlist.m3u8'
m3u8_240 = m3u8_[:m3u8_.rfind('/')] + '/240/playlist.m3u8'
m3u8_180 = m3u8_[:m3u8_.rfind('/')] + '/180/playlist.m3u8'

rr_all = self.session.get(m3u8_[:m3u8_.rfind('/')] + '/playlist.m3u8')
rr_all = self.session.get(base_url + 'playlist.m3u8')

if 'timeshift forbidden' in rr_all.text:
return None, 'This video can\'t be downloaded for now.'

r_all = m3u8.loads(rr_all.text)
r1080 = m3u8.loads(self.session.get(m3u8_1080).text)
r720 = m3u8.loads(self.session.get(m3u8_720).text)
r480 = m3u8.loads(self.session.get(m3u8_480).text)
r360 = m3u8.loads(self.session.get(m3u8_360).text)
r240 = m3u8.loads(self.session.get(m3u8_240).text)
r180 = m3u8.loads(self.session.get(m3u8_180).text)

play_res = []
for r_p in r_all.playlists:
play_res.append(list(r_p.stream_info.resolution))

x1080 = r1080.files[1:]
if not x1080:
return None, 'This video can\'t be downloaded for now.'
x1080 = x1080[5]
x720 = r720.files[1:][5]
x480 = r480.files[1:][5]
x360 = r360.files[1:][5]
x240 = r240.files[1:][5]
x180 = r180.files[1:][5]
temp = []
temp.append(r_p.stream_info.resolution)
temp.append(base_url + r_p.uri)
play_res.append(temp)

resgex = re.compile(r'(\d*)(?:\/\w+.ts)')

ava_reso = []
if '1080' in re.findall(resgex, x1080):
temp_ = ['1080p']
for r in play_res:
if 1080 in r:
temp_.append('{w}x{h}'.format(w=r[0], h=r[1]))
ava_reso.append(temp_)
if '720' in re.findall(resgex, x720):
temp_ = ['720p']
for r in play_res:
if 720 in r:
temp_.append('{w}x{h}'.format(w=r[0], h=r[1]))
ava_reso.append(temp_)
if '480' in re.findall(resgex, x480):
temp_ = ['480p']
for r in play_res:
if 480 in r:
temp_.append('{w}x{h}'.format(w=r[0], h=r[1]))
ava_reso.append(temp_)
if '360' in re.findall(resgex, x360):
temp_ = ['360p']
for r in play_res:
if 360 in r:
temp_.append('{w}x{h}'.format(w=r[0], h=r[1]))
ava_reso.append(temp_)
if '240' in re.findall(resgex, x240):
temp_ = ['240p']
for r in play_res:
if 240 in r:
temp_.append('{w}x{h}'.format(w=r[0], h=r[1]))
ava_reso.append(temp_)
if '180' in re.findall(resgex, x180):
temp_ = ['180p']
for r in play_res:
if 180 in r:
temp_.append('{w}x{h}'.format(w=r[0], h=r[1]))
ava_reso.append(temp_)
for resdata in play_res:
reswh, m3u8_uri = resdata
resw, resh = reswh
self.yuu_logger.debug('Validating {}p resolution'.format(resh))
rres = m3u8.loads(self.session.get(m3u8_uri).text)

m3f = rres.files[1:]
if not m3f:
return None, 'This video can\'t be downloaded for now.'
self.yuu_logger.debug('Sample link: ' + m3f[5])

if 'tsda' in files[5]:
# Assume DRMed
return None, 'This video has a different DRM method and cannot be decrypted by yuu for now'

if str(resh) in re.findall(resgex, m3f[5]):
ava_reso.append(
[
'{h}p'.format(h=resh),
'{w}x{h}'.format(w=resw, h=resh)
]
)

if ava_reso:
reso = [r[0] for r in ava_reso]
Expand Down

0 comments on commit 30d2fcf

Please sign in to comment.