]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/adultswim.py
39335b8272295dbf2b640881cd29a6f5b99acaba
2 from __future__
import unicode_literals
6 from . common
import InfoExtractor
14 class AdultSwimIE ( InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?adultswim\.com/videos/(?P<is_playlist>playlists/)?(?P<show_path>[^/]+)/(?P<episode_path>[^/?#]+)/?'
18 'url' : 'http://adultswim.com/videos/rick-and-morty/pilot' ,
21 'md5' : '247572debc75c7652f253c8daa51a14d' ,
23 'id' : 'rQxZvXQ4ROaSOqq-or2Mow-0' ,
25 'title' : 'Rick and Morty - Pilot Part 1' ,
26 'description' : "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "
30 'md5' : '77b0e037a4b20ec6b98671c4c379f48d' ,
32 'id' : 'rQxZvXQ4ROaSOqq-or2Mow-3' ,
34 'title' : 'Rick and Morty - Pilot Part 4' ,
35 'description' : "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "
40 'id' : 'rQxZvXQ4ROaSOqq-or2Mow' ,
41 'title' : 'Rick and Morty - Pilot' ,
42 'description' : "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "
45 'url' : 'http://www.adultswim.com/videos/playlists/american-parenting/putting-francine-out-of-business/' ,
48 'md5' : '2eb5c06d0f9a1539da3718d897f13ec5' ,
50 'id' : '-t8CamQlQ2aYZ49ItZCFog-0' ,
52 'title' : 'American Dad - Putting Francine Out of Business' ,
53 'description' : 'Stan hatches a plan to get Francine out of the real estate business.Watch more American Dad on [adult swim].'
58 'id' : '-t8CamQlQ2aYZ49ItZCFog' ,
59 'title' : 'American Dad - Putting Francine Out of Business' ,
60 'description' : 'Stan hatches a plan to get Francine out of the real estate business.Watch more American Dad on [adult swim].'
63 'url' : 'http://www.adultswim.com/videos/tim-and-eric-awesome-show-great-job/dr-steve-brule-for-your-wine/' ,
66 'md5' : '3e346a2ab0087d687a05e1e7f3b3e529' ,
68 'id' : 'sY3cMUR_TbuE4YmdjzbIcQ-0' ,
70 'title' : 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine' ,
71 'description' : 'Dr. Brule reports live from Wine Country with a special report on wines. \r\n Watch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim. \r\n\r\n ' ,
76 'id' : 'sY3cMUR_TbuE4YmdjzbIcQ' ,
77 'title' : 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine' ,
78 'description' : 'Dr. Brule reports live from Wine Country with a special report on wines. \r\n Watch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim. \r\n\r\n ' ,
83 def find_video_info ( collection
, slug
):
84 for video
in collection
. get ( 'videos' ):
85 if video
. get ( 'slug' ) == slug
:
89 def find_collection_by_linkURL ( collections
, linkURL
):
90 for collection
in collections
:
91 if collection
. get ( 'linkURL' ) == linkURL
:
95 def find_collection_containing_video ( collections
, slug
):
96 for collection
in collections
:
97 for video
in collection
. get ( 'videos' ):
98 if video
. get ( 'slug' ) == slug
:
99 return collection
, video
102 def _real_extract ( self
, url
):
103 mobj
= re
. match ( self
._ VALID
_U RL
, url
)
104 show_path
= mobj
. group ( 'show_path' )
105 episode_path
= mobj
. group ( 'episode_path' )
106 is_playlist
= True if mobj
. group ( 'is_playlist' ) else False
108 webpage
= self
._ download
_ webpage
( url
, episode_path
)
110 # Extract the value of `bootstrappedData` from the Javascript in the page.
111 bootstrapped_data
= self
._ parse
_ json
( self
._ search
_ regex
(
112 r
'var bootstrappedData = ({.*});' , webpage
, 'bootstraped data' ), episode_path
)
114 # Downloading videos from a /videos/playlist/ URL needs to be handled differently.
115 # NOTE: We are only downloading one video (the current one) not the playlist
117 collections
= bootstrapped_data
[ 'playlists' ][ 'collections' ]
118 collection
= self
. find_collection_by_linkURL ( collections
, show_path
)
119 video_info
= self
. find_video_info ( collection
, episode_path
)
121 show_title
= video_info
[ 'showTitle' ]
122 segment_ids
= [ video_info
[ 'videoPlaybackID' ]]
124 collections
= bootstrapped_data
[ 'show' ][ 'collections' ]
125 collection
, video_info
= self
. find_collection_containing_video ( collections
, episode_path
)
127 # Video wasn't found in the collections, let's try `slugged_video`.
128 if video_info
is None :
129 if bootstrapped_data
. get ( 'slugged_video' , {}). get ( 'slug' ) == episode_path
:
130 video_info
= bootstrapped_data
[ 'slugged_video' ]
132 raise ExtractorError ( 'Unable to find video info' )
134 show
= bootstrapped_data
[ 'show' ]
135 show_title
= show
[ 'title' ]
136 segment_ids
= [ clip
[ 'videoPlaybackID' ] for clip
in video_info
[ 'clips' ]]
138 episode_id
= video_info
[ 'id' ]
139 episode_title
= video_info
[ 'title' ]
140 episode_description
= video_info
[ 'description' ]
141 episode_duration
= video_info
. get ( 'duration' )
144 for part_num
, segment_id
in enumerate ( segment_ids
):
145 segment_url
= 'http://www.adultswim.com/videos/api/v0/assets?id= %s &platform=mobile' % segment_id
147 segment_title
= ' %s - %s ' % ( show_title
, episode_title
)
148 if len ( segment_ids
) > 1 :
149 segment_title
+= ' Part %d ' % ( part_num
+ 1 )
151 idoc
= self
._ download
_ xml
(
152 segment_url
, segment_title
,
153 'Downloading segment information' , 'Unable to download segment information' )
155 segment_duration
= float_or_none (
156 xpath_text ( idoc
, './/trt' , 'segment duration' ). strip ())
159 file_els
= idoc
. findall ( './/files/file' )
161 for file_el
in file_els
:
162 bitrate
= file_el
. attrib
. get ( 'bitrate' )
163 ftype
= file_el
. attrib
. get ( 'type' )
166 'format_id' : ' %s _ %s ' % ( bitrate
, ftype
),
167 'url' : file_el
. text
. strip (),
168 # The bitrate may not be a number (for example: 'iphone')
169 'tbr' : int ( bitrate
) if bitrate
. isdigit () else None ,
170 'quality' : 1 if ftype
== 'hd' else - 1
173 self
._ sort
_ formats
( formats
)
177 'title' : segment_title
,
179 'duration' : segment_duration
,
180 'description' : episode_description
186 'display_id' : episode_path
,
188 'title' : ' %s - %s ' % ( show_title
, episode_title
),
189 'description' : episode_description
,
190 'duration' : episode_duration