2019-04-25 13:07:14 -07:00
# coding: utf-8
from __future__ import unicode_literals
from . common import InfoExtractor
from . . utils import (
2019-05-07 17:17:43 -07:00
ExtractorError ,
2019-04-25 13:07:14 -07:00
urljoin ,
2019-04-25 13:19:22 -07:00
int_or_none ,
url_or_none ,
try_get ,
2019-05-07 17:17:43 -07:00
js_to_json ,
2019-04-25 13:07:14 -07:00
)
2019-04-25 16:46:07 -07:00
class EarthCamIE ( InfoExtractor ) :
2019-04-25 16:21:02 -07:00
_VALID_URL = r ' https?://(?:www \ .)?earthcam \ .com/.* \ ?.*cam=(?P<id> \ w+) '
2019-05-07 17:17:43 -07:00
_TESTS = [ {
2019-04-25 13:07:14 -07:00
' url ' : ' https://www.earthcam.com/usa/newyork/timessquare/?cam=tsrobo1 ' ,
' info_dict ' : {
' id ' : ' tsrobo1 ' ,
' ext ' : ' mp4 ' ,
' title ' : ' Times Square, NYC ' ,
' description ' : ' EarthCam brings you an HD, panoramic view of Times Square looking up, down, and across 7th Avenue and Broadway. See why Times Square is called the " Crossroads of the World! " ' ,
' view_count ' : int ,
' is_live ' : True ,
2019-04-25 16:21:02 -07:00
' thumbnail ' : r ' re:^https?://.* \ .(jpg|png)$ ' ,
2019-05-07 17:17:43 -07:00
} ,
} , {
' url ' : ' https://www.earthcam.com/usa/louisiana/neworleans/bourbonstreet/?cam=catsmeowkaraoke ' ,
' info_dict ' : {
' id ' : ' catsmeowkaraoke ' ,
' ext ' : ' mp4 ' ,
' title ' : ' New Orleans, LA ' ,
' description ' : ' Get a front row seat to all the wild and crazy stage performances happening at the Cat \' s Meow Karaoke Bar! Over the years, thousands of guests have enjoyed their moment singing in the spotlight at this popular local spot! ' ,
' view_count ' : int ,
' is_live ' : True ,
' thumbnail ' : r ' re:^https?://.* \ .(jpg|png)$ ' ,
}
} ]
2019-04-25 13:07:14 -07:00
def _real_extract ( self , url ) :
video_id = self . _match_id ( url )
webpage = self . _download_webpage ( url , video_id )
2019-05-07 17:17:43 -07:00
json_str = self . _html_search_regex ( r ' var \ s+json_base \ s*= \ s*(?P<json_str> { \ s* " cam " \ s*: \ s* { .*}.*}); ' , webpage , ' json ' , group = ' json_str ' , default = ' {} ' )
json_base = self . _parse_json ( js_to_json ( json_str ) , video_id )
video_info = jsonn_base [ ' cam ' ] [ video_id ]
domain = video_info [ ' html5_streamingdomain ' ]
path = video_info [ ' html5_streampath ' ]
2019-04-25 13:07:14 -07:00
m3u8_url = urljoin ( domain , path )
2019-05-07 17:17:43 -07:00
formats = self . _extract_m3u8_formats ( m3u8_url , video_id , ' mp4 ' , ' m3u8_native ' )
2019-04-25 13:07:14 -07:00
2019-05-07 17:17:43 -07:00
title = video_info . get ( ' long_title ' ) or self . _og_search_title ( webpage )
description = video_info . get ( ' description ' ) or self . _og_search_description ( webpage )
thumbnail = url_or_none ( video_info . get ( ' thumbimage ' ) ) or self . _og_search_thumbnail ( webpage )
view_count = int_or_none ( video_info . get ( " streamviews " ) )
2019-04-25 13:07:14 -07:00
return {
' id ' : video_id ,
2019-05-07 17:17:43 -07:00
' formats ' : formats ,
' title ' : title ,
' description ' : description ,
2019-04-25 13:07:14 -07:00
' view_count ' : view_count ,
' is_live ' : True ,
2019-05-07 17:17:43 -07:00
' thumbnail ' : thumbnail ,
2019-04-25 13:07:14 -07:00
}