o
    i                     @   sP   d dl Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 G dd deZdS )	    N   )InfoExtractor   )	HTTPError)ExtractorErrorGeoRestrictedErrorfloat_or_nonetraverse_objtry_callc                
   @   s>   e Zd ZdZdddddddd	g d
ddgZdZdd ZdS )OnDemandChinaEpisodeIEzThttps?://www\.ondemandchina\.com/\w+/watch/(?P<series>[\w-]+)/(?P<id>ep-(?P<ep>\d+))zEhttps://www.ondemandchina.com/en/watch/together-against-covid-19/ep-1264394mp4g(\q@zEP 1 The Callingu   第1集 令出如山zZhttps://d2y2efdi5wgkcl.cloudfront.net/fit-in/256x256/media-io/2020/9/11/image.d9816e81.jpgu<   疫情严峻，党政军民学、东西南北中协同应考)zSocial HumanitiesDocumentaryMedicalSocial)idextdurationtitle	alt_title	thumbnaildescriptiontags)url	info_dicta  
        query Episode($programSlug: String!, $episodeNumber: Int!) {
            episode(
                programSlug: $programSlug
                episodeNumber: $episodeNumber
                kind: "series"
                part: null
            ) {
                id
                title
                titleEn
                titleKo
                titleZhHans
                titleZhHant
                synopsis
                synopsisEn
                synopsisKo
                synopsisZhHans
                synopsisZhHant
                videoDuration
                images {
                    thumbnail
                }
            }
        }c                    s    |ddd\}}} || jd|dditd j|t|dd	 d
d d }z jd|d  d|dddd}W n( t	yl } zt
|jtrb |jj |d }t|W Y d }~nd }~ww g i }	}
t|dD ]-}|ddkr |d|\}}|	|  j||
d qw d|d | qwt|d t|ddt|dp ddgt|dd pψ d!d"gpψ t|d#d$d%t|d&d'd(d)d*p g d+|	|
t fd,d-d.	S )/Nseriesr   epz'https://odc-graphql.odkmedia.io/graphqlzContent-typezapplication/jsonEpisode)programSlugepisodeNumber)operationNamequery	variables)headersdatar$   episodez(https://odkmedia.io/odc/api/v2/playback// odc)Authorizationzservice-name)r#   detail)sources.typehlsr   )targetzUnsupported format videoDurationi  )imagesr   zog:imageztwitter:imager   titleEnzog:titleztwitter:titletitleKotitleZhHanstitleZhHant
synopsisEn
synopsisKosynopsisZhHanssynopsisZhHant	synopisis)zog:descriptionztwitter:descriptionr   c                      s     ddS )Nkeywordsz, )_html_search_metasplit selfwebpager=   M/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/odkmedia.py<lambda>h   s    z6OnDemandChinaEpisodeIE._real_extract.<locals>.<lambda>)	r   r   r   r   r   r   formats	subtitlesr   )_match_valid_urlgroup_download_webpage_download_jsonjsondumps_QUERYintencoder   
isinstancecauser   _parse_jsonresponsereadr   r	   get#_extract_m3u8_formats_and_subtitlesextend_merge_subtitlesreport_warningstrr   r;   _html_extract_titler
   )r?   r   program_slug
display_id	ep_number
video_infosource_jsone
error_datarC   rD   sourcefmtssubsr=   r>   rA   _real_extract8   sl   






z$OnDemandChinaEpisodeIE._real_extractN)__name__
__module____qualname__
_VALID_URL_TESTSrK   rd   r=   r=   r=   rA   r      s    r   )rI   commonr   networking.exceptionsr   utilsr   r   r   r	   r
   r   r=   r=   r=   rA   <module>   s
    	