]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/funimation.py
2 from __future__
import unicode_literals
3 from . common
import InfoExtractor
4 from .. compat
import compat_HTTPError
14 class FunimationIE ( InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?funimation\.com/shows/.+[^ ]/videos/official/(?P<id>[^?]+)'
18 'url' : 'http://www.funimation.com/shows/air/videos/official/breeze' ,
21 'title' : 'Air - 1 - Breeze ' ,
23 'thumbnail' : 'http://www.funimation.com/admin/uploads/default/recap_thumbnails/7555590/home_spotlight/AIR0001.jpg' ,
24 'description' : 'Travelling puppeteer Yukito arrives in a small town where he hopes to earn money through the magic of his puppets. When a young girl named Misuzu lures him to her home with the promise of food, his life changes forever. ' ,
29 ( username
, password
) = self
._ get
_l ogin
_ info
()
32 login_url
= 'http://www.funimation.com/login'
33 data
= urlencode_postdata ( encode_dict ({
34 'email_field' : username
,
35 'password_field' : password
,
37 login_request
= sanitized_Request ( login_url
, data
)
38 login_request
. add_header ( 'Content-Type' , 'application/x-www-form-urlencoded' )
40 login
= self
._ download
_ webpage
(
41 login_request
, None , 'Logging in as %s ' % username
)
42 except ExtractorError
as e
:
43 if isinstance ( e
. cause
, compat_HTTPError
) and e
. cause
. code
== 403 :
44 raise ExtractorError ( 'Funimation is not available in your region.' , expected
= True )
46 if re
. search ( r
'<meta property="og:url" content="http://www.funimation.com/login"/>' , login
) is not None :
47 raise ExtractorError ( 'Unable to login, wrong username or password.' , expected
= True )
49 def _real_initialize ( self
):
52 def _real_extract ( self
, url
):
53 mobj
= re
. match ( self
._ VALID
_U RL
, url
)
54 video_id
= mobj
. group ( 'id' )
56 webpage
= self
._ download
_ webpage
( url
, video_id
)
57 except ExtractorError
as e
:
58 if isinstance ( e
. cause
, compat_HTTPError
) and e
. cause
. code
== 403 :
59 raise ExtractorError ( 'Funimation is not available in your region.' , expected
= True )
61 if re
. search ( r
'"sdUrl":"http' , webpage
) is None :
62 raise ExtractorError ( 'You are not logged-in or the stream requires subscription.' , expected
= True )
64 m3u8
= self
._ search
_ regex
( r
'".+Url":"(.+?m3u8)"' , webpage
, 'm3u8' ) + self
._ search
_ regex
( r
'"authToken":"(.+?)"' , webpage
, 'm3u8' )
65 formats
= self
._ extract
_ m
3u8_ formats
( m3u8
. replace ( ' \\ ' , '' ), video_id
, ext
= 'mp4' , entry_protocol
= 'm3u8_native' )
67 video_show
= self
._ search
_ regex
( r
'"artist":"(.+?)"' , webpage
, 'video_show' )
68 video_track
= self
._ search
_ regex
( r
'"videoNumber":"(\d+).0"' , webpage
, 'video_track' )
69 video_title
= self
._ search
_ regex
( r
'"title":"( {0} .+?)"' . format ( video_track
), webpage
, 'video_title' )
70 video_id
= self
._ search
_ regex
( r
'"FUNImationID":"(.+?)"' , webpage
, 'video_id' )
74 'title' : video_show
+ ' - ' + video_title
+ ' ' ,
76 'thumbnail' : self
._ og
_ search
_ thumbnail
( webpage
),
77 'description' : self
._ og
_ search
_ description
( webpage
)