]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/plutotv.py
4 from . common
import InfoExtractor
18 class PlutoTVIE ( InfoExtractor
):
20 https?://(?:www\.)?pluto\.tv(?:/[^/]+)?/on-demand
21 /(?P<video_type>movies|series)
22 /(?P<series_or_movie_slug>[^/]+)
24 (?:/seasons?/(?P<season_no>\d+))?
25 (?:/episode/(?P<episode_slug>[^/]+))?
29 _INFO_URL
= 'https://service-vod.clusters.pluto.tv/v3/vod/slugs/'
30 _INFO_QUERY_PARAMS
= {
33 'clientID' : compat_str ( uuid
. uuid1 ()),
34 'clientModelNumber' : 'na' ,
35 'serverSideAds' : 'false' ,
36 'deviceMake' : 'unknown' ,
39 'deviceVersion' : 'unknown' ,
40 'sid' : compat_str ( uuid
. uuid1 ()),
44 'url' : 'https://pluto.tv/on-demand/series/i-love-money/season/2/episode/its-in-the-cards-2009-2-3' ,
45 'md5' : 'ebcdd8ed89aaace9df37924f722fd9bd' ,
47 'id' : '5de6c598e9379ae4912df0a8' ,
49 'title' : 'It \' s In The Cards' ,
50 'episode' : 'It \' s In The Cards' ,
51 'description' : 'The teams face off against each other in a 3-on-2 soccer showdown. Strategy comes into play, though, as each team gets to select their opposing teams’ two defenders.' ,
52 'series' : 'I Love Money' ,
58 'url' : 'https://pluto.tv/on-demand/series/i-love-money/season/1/' ,
61 'id' : '5de6c582e9379ae4912dedbd' ,
62 'title' : 'I Love Money - Season 1' ,
65 'url' : 'https://pluto.tv/on-demand/series/i-love-money/' ,
68 'id' : '5de6c582e9379ae4912dedbd' ,
69 'title' : 'I Love Money' ,
72 'url' : 'https://pluto.tv/on-demand/movies/arrival-2015-1-1' ,
73 'md5' : '3cead001d317a018bf856a896dee1762' ,
75 'id' : '5e83ac701fa6a9001bb9df24' ,
78 'description' : 'When mysterious spacecraft touch down across the globe, an elite team - led by expert translator Louise Banks (Academy Award® nominee Amy Adams) – races against time to decipher their intent.' ,
82 'url' : 'https://pluto.tv/en/on-demand/series/manhunters-fugitive-task-force/seasons/1/episode/third-times-the-charm-1-1' ,
83 'only_matching' : True ,
85 'url' : 'https://pluto.tv/it/on-demand/series/csi-vegas/episode/legacy-2021-1-1' ,
86 'only_matching' : True ,
90 def _to_ad_free_formats ( self
, video_id
, formats
, subtitles
):
91 ad_free_formats
, ad_free_subtitles
, m3u8_urls
= [], {}, set ()
93 res
= self
._ download
_ webpage
(
94 fmt
. get ( 'url' ), video_id
, note
= 'Downloading m3u8 playlist' ,
98 first_segment_url
= re
. search (
99 r
'^(https?://.*/)0\-(end|[0-9]+)/[^/]+\.ts$' , res
,
101 if first_segment_url
:
103 compat_urlparse
. urljoin ( first_segment_url
. group ( 1 ), '0-end/master.m3u8' ))
105 first_segment_url
= re
. search (
106 r
'^(https?://.*/).+\-0+\.ts$' , res
,
108 if first_segment_url
:
110 compat_urlparse
. urljoin ( first_segment_url
. group ( 1 ), 'master.m3u8' ))
113 for m3u8_url
in m3u8_urls
:
114 fmts
, subs
= self
._ extract
_ m
3u8_ formats
_ and
_ subtitles
(
115 m3u8_url
, video_id
, 'mp4' , 'm3u8_native' , m3u8_id
= 'hls' , fatal
= False )
116 ad_free_formats
. extend ( fmts
)
117 ad_free_subtitles
= self
._ merge
_ subtitles
( ad_free_subtitles
, subs
)
119 formats
, subtitles
= ad_free_formats
, ad_free_subtitles
121 self
. report_warning ( 'Unable to find ad-free formats' )
122 return formats
, subtitles
124 def _get_video_info ( self
, video_json
, slug
, series_name
= None ):
125 video_id
= video_json
. get ( '_id' , slug
)
126 formats
, subtitles
= [], {}
127 for video_url
in try_get ( video_json
, lambda x
: x
[ 'stitched' ][ 'urls' ], list ) or []:
128 if video_url
. get ( 'type' ) != 'hls' :
130 url
= url_or_none ( video_url
. get ( 'url' ))
132 fmts
, subs
= self
._ extract
_ m
3u8_ formats
_ and
_ subtitles
(
133 url
, video_id
, 'mp4' , 'm3u8_native' , m3u8_id
= 'hls' , fatal
= False )
135 subtitles
= self
._ merge
_ subtitles
( subtitles
, subs
)
137 formats
, subtitles
= self
._ to
_ ad
_ free
_ formats
( video_id
, formats
, subtitles
)
138 self
._ sort
_ formats
( formats
)
143 'subtitles' : subtitles
,
144 'title' : video_json
. get ( 'name' ),
145 'description' : video_json
. get ( 'description' ),
146 'duration' : float_or_none ( video_json
. get ( 'duration' ), scale
= 1000 ),
150 'series' : series_name
,
151 'episode' : video_json
. get ( 'name' ),
152 'season_number' : int_or_none ( video_json
. get ( 'season' )),
153 'episode_number' : int_or_none ( video_json
. get ( 'number' )),
157 def _real_extract ( self
, url
):
158 mobj
= self
._ match
_ valid
_u rl
( url
). groupdict ()
159 info_slug
= mobj
[ 'series_or_movie_slug' ]
160 video_json
= self
._ download
_ json
( self
._ INFO
_U RL
+ info_slug
, info_slug
, query
= self
._ INFO
_ QUERY
_ PARAMS
)
162 if mobj
[ 'video_type' ] == 'series' :
163 series_name
= video_json
. get ( 'name' , info_slug
)
164 season_number
, episode_slug
= mobj
. get ( 'season_number' ), mobj
. get ( 'episode_slug' )
167 for season
in video_json
[ 'seasons' ]:
168 if season_number
is not None and season_number
!= int_or_none ( season
. get ( 'number' )):
170 for episode
in season
[ 'episodes' ]:
171 if episode_slug
is not None and episode_slug
!= episode
. get ( 'slug' ):
173 videos
. append ( self
._ get
_ video
_ info
( episode
, episode_slug
, series_name
))
175 raise ExtractorError ( 'Failed to find any videos to extract' )
176 if episode_slug
is not None and len ( videos
) == 1 :
178 playlist_title
= series_name
179 if season_number
is not None :
180 playlist_title
+= ' - Season %d ' % season_number
181 return self
. playlist_result ( videos
,
182 playlist_id
= video_json
. get ( '_id' , info_slug
),
183 playlist_title
= playlist_title
)
184 return self
._ get
_ video
_ info
( video_json
, info_slug
)