2021-01-30 23:33:24 -06:00
# coding: utf-8
from __future__ import unicode_literals
from . common import InfoExtractor
2021-03-08 14:03:50 -06:00
from . . compat import compat_str
2021-03-08 14:24:00 -06:00
from . . utils import try_get
2021-01-30 23:33:24 -06:00
2021-02-13 19:36:31 -06:00
2021-01-30 23:33:24 -06:00
class Pac12IE ( InfoExtractor ) :
_VALID_URL = r ' https?://(?:[a-z]+ \ .)?pac-12.com/(?:embed/)?(?P<id>.*) '
2021-01-30 23:42:31 -06:00
_TESTS = [ {
2021-01-30 23:33:24 -06:00
' url ' : ' https://pac-12.com/videos/2020-pac-12-womens-basketball-media-day-arizona-cal-stanford ' ,
' md5 ' : ' b2e3c0cb99458c8b8e2dc22cb5ac922d ' ,
' info_dict ' : {
' id ' : ' vod-VGQNKGlo9Go ' ,
' ext ' : ' mp4 ' ,
2021-02-13 19:34:34 -06:00
' title ' : ' 2020 Pac-12 Women \' s Basketball Media Day - Arizona, Cal & Stanford ' ,
' description ' : ' During the 2020 Pac-12 Women \' s Basketball Media Day, Ros Gold-Onwude moderates a discussion with Arizona \' s Adia Barnes & Aari McDonald, Cal \' s Charmin Smith & Evelien Lutje Schipholt & Stanford \' s Tara VanDerveer & Kiana Williams. ' ,
2021-01-30 23:33:24 -06:00
}
2021-01-30 23:42:31 -06:00
} , {
' url ' : ' https://pac-12.com/article/2020/11/24/sonoran-dog-dish-presented-tums ' ,
' md5 ' : ' a7a8ac72273b9468924bc058cc220d37 ' ,
' info_dict ' : {
' id ' : ' vod-YLMKpNLZvR0 ' ,
' ext ' : ' mp4 ' ,
2021-02-13 19:34:34 -06:00
' title ' : ' Sonoran Dog | The Dish, presented by TUMS ' ,
2021-01-30 23:42:31 -06:00
' description ' : ' Pac-12 Networks introduces " The Dish, " presented by Tums. Jaymee Sire is bringing fans a closeup to game day treats from around the Conference with each treat connecting to a Pac-12 school, bringing the flavor and recipes fans know and love right to the dish! As Arizona and USC basketball seasons tip off, the first feature item from " The Dish " is the Sonoran Dog, a beloved treat by Trojans & Wildcat fans. ' ,
}
} ]
2021-01-30 23:33:24 -06:00
def _real_extract ( self , url ) :
video_id = self . _match_id ( url )
webpage = self . _download_webpage ( url , video_id )
2021-02-13 18:26:33 -06:00
drupal_settings = self . _parse_json (
self . _search_regex (
r ' <script[^>]+type= " application/json " [^>]*data-drupal-selector= " drupal-settings-json " >([^<]+)</script> ' ,
webpage , ' drupal settings ' ) , video_id )
2021-02-20 19:47:48 -06:00
cv = drupal_settings . get ( ' currentVideo ' )
2021-02-13 18:26:33 -06:00
2021-02-20 19:47:48 -06:00
if cv is False :
# May be an event page; look for the live stream.
2021-03-08 14:27:53 -06:00
network = try_get ( drupal_settings ,
lambda x : x [ ' pac12_react ' ] [
' pac12_react_event_widget ' ] [ ' event ' ] [
' broadcast_info ' ] [ ' broadcast_networks ' ] [ 0 ] [
' id ' ] , int )
2021-03-08 14:24:00 -06:00
if network is not None :
2021-03-08 14:27:53 -06:00
cv = try_get ( drupal_settings ,
lambda x : x [ ' pac12_react ' ] [ ' networks ' ] [
str ( network ) ] , dict )
2021-02-20 19:47:48 -06:00
if not cv or ' manifest_url ' not in cv :
# Video may be embedded one level deeper; look for embed URL.
2021-02-13 19:34:34 -06:00
vod_url = self . _search_regex (
2021-02-13 19:36:31 -06:00
r ' (https?://(?:embed \ .)?pac-12 \ .com/(?:embed/)?vod- \ w+) ' ,
2021-02-13 19:34:34 -06:00
webpage , ' url ' , default = None )
2021-01-30 23:33:24 -06:00
if vod_url is None :
2021-02-20 19:47:48 -06:00
# Failure; no video found.
2021-01-30 23:33:24 -06:00
return None
return self . url_result ( vod_url )
2021-02-13 19:34:34 -06:00
2021-01-30 23:33:24 -06:00
return {
2021-02-20 19:47:48 -06:00
# cv['id'] might be an integer, string, or missing.
2021-03-08 14:03:50 -06:00
' id ' : compat_str ( cv . get ( ' id ' ) or video_id ) ,
2021-02-13 19:49:58 -06:00
' title ' : ( cv . get ( ' title ' )
2021-02-20 19:47:48 -06:00
or self . _html_search_meta (
[ ' og:title ' , ' twitter:title ' ,
' branch.deeplink.title ' ] , webpage )
2021-02-13 19:49:58 -06:00
or self . _html_search_regex ( r ' <title>(.+?)</title> ' ,
webpage , ' title ' ) ) ,
2021-02-20 19:47:48 -06:00
' description ' : ( cv . get ( ' description ' )
or self . _html_search_meta (
[ ' og:description ' , ' twitter:description ' ,
' description ' ] , webpage , fatal = False ) ) ,
' url ' : cv [ ' manifest_url ' ] ,
2021-01-30 23:33:24 -06:00
' ext ' : ' mp4 ' ,
}