]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/adultswim.py 
8157da2cb63af8a7079fda8c388be3108281a7ad
   2  from  __future__ 
import  unicode_literals
   6  from  . common 
import  InfoExtractor
  15  class  AdultSwimIE ( InfoExtractor
):   16      _VALID_URL 
=  r
'https?://(?:www\.)?adultswim\.com/videos/(?P<is_playlist>playlists/)?(?P<show_path>[^/]+)/(?P<episode_path>[^/?#]+)/?'   19          'url' :  'http://adultswim.com/videos/rick-and-morty/pilot' ,   22                  'md5' :  '247572debc75c7652f253c8daa51a14d' ,   24                      'id' :  'rQxZvXQ4ROaSOqq-or2Mow-0' ,   26                      'title' :  'Rick and Morty - Pilot Part 1' ,   27                      'description' :  "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "   31                  'md5' :  '77b0e037a4b20ec6b98671c4c379f48d' ,   33                      'id' :  'rQxZvXQ4ROaSOqq-or2Mow-3' ,   35                      'title' :  'Rick and Morty - Pilot Part 4' ,   36                      'description' :  "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "   41              'id' :  'rQxZvXQ4ROaSOqq-or2Mow' ,   42              'title' :  'Rick and Morty - Pilot' ,   43              'description' :  "Rick moves in with his daughter's family and establishes himself as a bad influence on his grandson, Morty. "   45          'skip' :  'This video is only available for registered users' ,   47          'url' :  'http://www.adultswim.com/videos/playlists/american-parenting/putting-francine-out-of-business/' ,   50                  'md5' :  '2eb5c06d0f9a1539da3718d897f13ec5' ,   52                      'id' :  '-t8CamQlQ2aYZ49ItZCFog-0' ,   54                      'title' :  'American Dad - Putting Francine Out of Business' ,   55                      'description' :  'Stan hatches a plan to get Francine out of the real estate business.Watch more American Dad on [adult swim].'   60              'id' :  '-t8CamQlQ2aYZ49ItZCFog' ,   61              'title' :  'American Dad - Putting Francine Out of Business' ,   62              'description' :  'Stan hatches a plan to get Francine out of the real estate business.Watch more American Dad on [adult swim].'   65          'url' :  'http://www.adultswim.com/videos/tim-and-eric-awesome-show-great-job/dr-steve-brule-for-your-wine/' ,   68                  'md5' :  '3e346a2ab0087d687a05e1e7f3b3e529' ,   70                      'id' :  'sY3cMUR_TbuE4YmdjzbIcQ-0' ,   72                      'title' :  'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine' ,   73                      '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 ' ,   78              'id' :  'sY3cMUR_TbuE4YmdjzbIcQ' ,   79              'title' :  'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine' ,   80              '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 ' ,   84              'skip_download' :  True ,   89      def  find_video_info ( collection
,  slug
):   90          for  video 
in  collection
. get ( 'videos' ):   91              if  video
. get ( 'slug' ) ==  slug
:   95      def  find_collection_by_linkURL ( collections
,  linkURL
):   96          for  collection 
in  collections
:   97              if  collection
. get ( 'linkURL' ) ==  linkURL
:  101      def  find_collection_containing_video ( collections
,  slug
):  102          for  collection 
in  collections
:  103              for  video 
in  collection
. get ( 'videos' ):  104                  if  video
. get ( 'slug' ) ==  slug
:  105                      return  collection
,  video
 108      def  _real_extract ( self
,  url
):  109          mobj 
=  re
. match ( self
._ VALID
_U RL
,  url
)  110          show_path 
=  mobj
. group ( 'show_path' )  111          episode_path 
=  mobj
. group ( 'episode_path' )  112          is_playlist 
=  True if  mobj
. group ( 'is_playlist' )  else False  114          webpage 
=  self
._ download
_ webpage
( url
,  episode_path
)  116          # Extract the value of `bootstrappedData` from the Javascript in the page.  117          bootstrapped_data 
=  self
._ parse
_ json
( self
._ search
_ regex
(  118              r
'var bootstrappedData = ({.*});' ,  webpage
,  'bootstraped data' ),  episode_path
)  120          # Downloading videos from a /videos/playlist/ URL needs to be handled differently.  121          # NOTE: We are only downloading one video (the current one) not the playlist  123              collections 
=  bootstrapped_data
[ 'playlists' ][ 'collections' ]  124              collection 
=  self
. find_collection_by_linkURL ( collections
,  show_path
)  125              video_info 
=  self
. find_video_info ( collection
,  episode_path
)  127              show_title 
=  video_info
[ 'showTitle' ]  128              segment_ids 
= [ video_info
[ 'videoPlaybackID' ]]  130              collections 
=  bootstrapped_data
[ 'show' ][ 'collections' ]  131              collection
,  video_info 
=  self
. find_collection_containing_video ( collections
,  episode_path
)  132              # Video wasn't found in the collections, let's try `slugged_video`.  133              if  video_info 
is None :  134                  if  bootstrapped_data
. get ( 'slugged_video' , {}). get ( 'slug' ) ==  episode_path
:  135                      video_info 
=  bootstrapped_data
[ 'slugged_video' ]  137                      raise  ExtractorError ( 'Unable to find video info' )  139              show 
=  bootstrapped_data
[ 'show' ]  140              show_title 
=  show
[ 'title' ]  141              stream 
=  video_info
. get ( 'stream' )  142              clips 
= [ stream
]  if  stream 
else  video_info
. get ( 'clips' )  144                  raise  ExtractorError (  145                      'This video is only available via cable service provider subscription that'  146                      ' is not currently supported. You may want to use --cookies.'  147                      if  video_info
. get ( 'auth' )  is True else  'Unable to find stream or clips' ,  149              segment_ids 
= [ clip
[ 'videoPlaybackID' ]  for  clip 
in  clips
]  151          episode_id 
=  video_info
[ 'id' ]  152          episode_title 
=  video_info
[ 'title' ]  153          episode_description 
=  video_info
[ 'description' ]  154          episode_duration 
=  video_info
. get ( 'duration' )  157          for  part_num
,  segment_id 
in  enumerate ( segment_ids
):  158              segment_url 
=  'http://www.adultswim.com/videos/api/v0/assets?id= %s &platform=desktop'  %  segment_id
 160              segment_title 
=  ' %s  -  %s '  % ( show_title
,  episode_title
)  161              if  len ( segment_ids
) >  1 :  162                  segment_title 
+=  ' Part  %d '  % ( part_num 
+  1 )  164              idoc 
=  self
._ download
_ xml
(  165                  segment_url
,  segment_title
,  166                  'Downloading segment information' ,  'Unable to download segment information' )  168              segment_duration 
=  float_or_none (  169                  xpath_text ( idoc
,  './/trt' ,  'segment duration' ). strip ())  172              file_els 
=  idoc
. findall ( './/files/file' )  or  idoc
. findall ( './files/file' )  176              for  file_el 
in  file_els
:  177                  media_url 
=  file_el
. text
 178                  if not  media_url 
or  determine_ext ( media_url
) ==  'f4m' :  180                  if  file_el
. text 
not in  unique_urls
:  181                      unique_urls
. append ( file_el
. text
)  182                      unique_file_els
. append ( file_el
)  184              for  file_el 
in  unique_file_els
:  185                  bitrate 
=  file_el
. attrib
. get ( 'bitrate' )  186                  ftype 
=  file_el
. attrib
. get ( 'type' )  187                  media_url 
=  file_el
. text
 188                  if  determine_ext ( media_url
) ==  'm3u8' :  189                      formats
. extend ( self
._ extract
_ m
3u8_ formats
(  190                          media_url
,  segment_title
,  'mp4' ,  preference
= 0 ,  191                          m3u8_id
= 'hls' ,  fatal
= False ))  194                          'format_id' :  ' %s _ %s '  % ( bitrate
,  ftype
),  195                          'url' :  file_el
. text
. strip (),  196                          # The bitrate may not be a number (for example: 'iphone')  197                          'tbr' :  int ( bitrate
)  if  bitrate
. isdigit ()  else None ,  200              self
._ sort
_ formats
( formats
)  204                  'title' :  segment_title
,  206                  'duration' :  segment_duration
,  207                  'description' :  episode_description
 213              'display_id' :  episode_path
,  215              'title' :  ' %s  -  %s '  % ( show_title
,  episode_title
),  216              'description' :  episode_description
,  217              'duration' :  episode_duration