@@ -34,11 +34,8 @@ def _legacy_video(video_id):
3434 return q
3535
3636
37- @m3u8
3837@query
39- def live (channel ):
40- token = channel_token (channel )
41-
38+ def _live (channel , token ):
4239 q = UsherQuery ('api/channel/hls/{channel}.m3u8' )
4340 q .add_urlkw (keys .CHANNEL , channel )
4441 q .add_param (keys .SIG , token [keys .SIG ])
@@ -49,12 +46,17 @@ def live(channel):
4946
5047
5148@m3u8
52- @query
53- def _vod (video_id ):
54- video_id = video_id [1 :]
49+ def live (channel ):
50+ token = channel_token (channel )
51+ if keys .ERROR in token :
52+ return token
53+ else :
54+ return _live (channel , token )
5555
56- token = vod_token (video_id )
5756
57+ @m3u8
58+ @query
59+ def _vod (video_id , token ):
5860 q = UsherQuery ('vod/{id}' )
5961 q .add_urlkw (keys .ID , video_id )
6062 q .add_param (keys .NAUTHSIG , token [keys .SIG ])
@@ -64,13 +66,22 @@ def _vod(video_id):
6466
6567
6668def video (video_id ):
67- if video_id .startswith ('videos' ):
68- video_id = 'v' + video_id [6 :]
69- return _vod (video_id )
70- elif video_id .startswith ('v' ):
71- return _vod (video_id )
69+ if video_id .startswith ('videos' ) or video_id .startswith ('v' ):
70+ if video_id .startswith ('videos' ):
71+ video_id = 'v' + video_id [6 :]
72+ video_id = video_id [1 :]
73+ token = vod_token (video_id )
74+ if keys .ERROR in token :
75+ return token
76+ else :
77+ return _vod (video_id , token )
7278 elif video_id .startswith (('a' , 'c' )):
73- return _legacy_video (video_id )
79+ video_id = video_id [1 :]
80+ token = vod_token (video_id )
81+ if keys .ERROR in token :
82+ return token
83+ else :
84+ return _vod (video_id , token )
7485 else :
7586 raise NotImplementedError ('Unknown Video Type' )
7687
0 commit comments