U
    gNB                    @   s$  d dl Z d dlZd dlZd dlZd dlZ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mZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  G dd de	Z!G d	d
 d
e!Z"G dd de	Z#G dd de	Z$G dd de	Z%G dd de%Z&G dd de%Z'G dd de$Z(dS )    N   )InfoExtractor   )	HTTPError)ExtractorErrorOnDemandPagedList
clean_htmldict_getfloat_or_noneget_element_by_classint_or_nonejoin_nonempty
js_to_jsonparse_durationparse_iso8601parse_qsstrip_or_nonetraverse_objtry_getunescapeHTMLunified_timestampurl_or_noneurlencode_postdataurljoinc                   @   sD  e Zd ZdZdZdZde dZdgZdZdZ	d	Z
d
dgZdZddddddddiddddddddddiddddddd d!dddid"dd#d$dd%d&d'dddid"dd(d)dd*d+d,dddiddd-d.d/dd0d1d2dddid3d4d5d6dd7d8d9dddid3d:d;dd<d=d>dddid?dd@dAddBdCd>dDddid?ddEdFddGdHdddidIddJdKddLdLdddiddMddNdOddNdPddNdQddNdRddNdSddNdTddNdUddNgZdVdW ZG dXdY dYeZdZd[ Zd\d] Zd^d_ Zd`da Zdbdc Zddde Zdfdg ZdydidjZdkdl Zdmdn Zdodp Zdqdr ZdzdsdtZdudv Zdwdx ZdhS ){	BBCCoUkIEz	bbc.co.ukzBBC iPlayerz#(?:[pbml][\da-z]{7}|w[\da-z]{7,14})a  (?x)
                    https?://
                        (?:www\.)?bbc\.co\.uk/
                        (?:
                            programmes/(?!articles/)|
                            iplayer(?:/[^/]+)?/(?:episode/|playlist/)|
                            music/(?:clips|audiovideo/popular)[/#]|
                            radio/player/|
                            events/[^/]+/play/[^/]+/
                        )
                        (?P<id>z8)(?!/(?:episodes|broadcasts|clips))
                    zLsetPlaylist\("(?P<url>https?://www\.bbc\.co\.uk/iplayer/[^/]+/[\da-z]{8})"\)zhttps://account.bbc.com/signinbbczRhttps://open.live.bbc.co.uk/mediaselector/6/select/version/2.0/mediaset/%s/vpid/%sziptv-allpcz"http://bbc.co.uk/2008/emp/playlistz(http://www.bbc.co.uk/programmes/b039g8p7Zb039d07mflvzKaleidoscope, Leonard Cohenz@The Canadian poet and songwriter reflects on his musical career.)idexttitledescriptionskip_downloadTurl	info_dictparamszYhttp://www.bbc.co.uk/iplayer/episode/b00yng5w/The_Man_in_Black_Series_3_The_Printed_Name/Zb00yng1dz,The Man in Black: Series 3: The Printed Namez}Mark Gatiss introduces Nicholas Pierpan's chilling tale of a writer's devilish pact with a mysterious man. Stars Ewan Bailey.i  )r   r   r    r!   durationz3Episode is no longer available on BBC iPlayer Radior$   r%   r&   skipzVhttp://www.bbc.co.uk/iplayer/episode/b03vhd1f/The_Voice_UK_Series_3_Blind_Auditions_5/z)The Voice UK: Series 3: Blind Auditions 5zEmma Willis and Marvin Humes present the fifth set of blind auditions in the singing competition, as the coaches continue to build their teams based on voice alone.i  zHCurrently BBC iPlayer TV programmes are available to play in the UK onlyzrhttp://www.bbc.co.uk/iplayer/episode/p026c7jt/tomorrows-worlds-the-unearthly-history-of-science-fiction-2-invasionZb03k3pb7z;Tomorrow's Worlds: The Unearthly History of Science Fictionz2. Invasioni  z(http://www.bbc.co.uk/programmes/b04v20dwZb04v209vz)Pete Tong, The Essential New Tune Specialz@Pete has a very special mix - all of 2014's Essential New Tunes!i0*  z)http://www.bbc.co.uk/music/clips/p022h44bZAudioZp022h44jz5BBC Proms Music Guides, Rachmaninov: Symphonic DanceszSIn this Proms Music Guide, Andrew McGregor looks at Rachmaninov's Symphonic Dances.   )r$   Znoter%   r&   z)http://www.bbc.co.uk/music/clips/p025c0zzZVideoZp025c103zIReading and Leeds Festival, 2014, Rae Morris - Closer (Live on BBC Three)z8Rae Morris performs Closer for BBC Three at Reading 2014   z\http://www.bbc.co.uk/iplayer/episode/b054fn09/ad/natural-world-20152016-2-super-powered-owlsZp02n76xfz/Natural World, 2015-2016: 2. Super Powered Owlsz$md5:e4db5c937d0e95a7c6b5e654d429183di  geolocationzMhttp://www.bbc.co.uk/iplayer/episode/b05zmgwn/royal-academy-summer-exhibitionZb05zmgw1zKirsty Wark and Morgan Quaintance visit the Royal Academy as it prepares for its annual artistic extravaganza, meeting people who have come together to make the show unique.zRoyal Academy Summer Exhibition)r   r   r!   r    r'   z(http://www.bbc.co.uk/programmes/b06rkn85Zb06rkms3zKBest of the Mini-Mixes 2015: Part 3, Annie Mac's Friday Night - BBC Radio 1zUAnnie has part three in the Best of the Mini-Mixes 2015, plus the year's Most Played!zNow it's really geo-restrictedz/http://www.bbc.co.uk/programmes/p028bfkf/playerZp028bfkjzHExtract from BBC documentary Look Stranger - Giant Leeks and Magic Brewsz.http://www.bbc.co.uk/iplayer/playlist/p01dvks4r$   Zonly_matchingz)http://www.bbc.co.uk/music/clips#p02frcc3zEhttp://www.bbc.co.uk/iplayer/cbeebies/episode/b0480276/bing-14-atchooz*http://www.bbc.co.uk/radio/player/p03cchwfz7https://www.bbc.co.uk/music/audiovideo/popular#p055bc55z(http://www.bbc.co.uk/programmes/w3csv1y9z)https://www.bbc.co.uk/programmes/m00005xnz0https://www.bbc.co.uk/programmes/w172w4dww1jqt5sc           	   	   C   s   |  | jd d}| |}|||d t| j| jd|d| jdd}| j|d dt|d| jid	\}}| j|jkrt	t
d
|}|rtd| ddtdd S )NzDownloading signin page)usernamepasswordz&<form[^>]+action=(["\'])(?P<url>.+?)\1zpost urlr$   defaultgroupz
Logging inZReferer)dataheaderszform-messagezUnable to login: TexpectedzUnable to log in)_download_webpage
_LOGIN_URLZ_hidden_inputsupdater   _search_regexZ_download_webpage_handler   r$   r   r   r   )	selfr.   r/   Z
login_pageZ
login_formZpost_urlresponseZurlherror r>   8/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/bbc.py_perform_login   s@      

      
 zBBCCoUkIE._perform_loginc                   @   s   e Zd Zdd ZdS )zBBCCoUkIE.MediaSelectionErrorc                 C   s
   || _ d S N)r   )r;   Zerror_idr>   r>   r?   __init__  s    z&BBCCoUkIE.MediaSelectionError.__init__N)__name__
__module____qualname__rB   r>   r>   r>   r?   MediaSelectionError  s   rF   c                 C   s(   |  |d|d}dd |dD S )NhrefzDownloading ASX playlistc                 S   s   g | ]}| d qS )rG   get).0refr>   r>   r?   
<listcomp>  s     z3BBCCoUkIE._extract_asx_playlist.<locals>.<listcomp>z./Entry/ref)_download_xmlrI   findall)r;   
connectionprogramme_idasxr>   r>   r?   _extract_asx_playlist  s    zBBCCoUkIE._extract_asx_playlistc                 C   s   | d| j dS )N./{z}item)rN   _EMP_PLAYLIST_NS)r;   playlistr>   r>   r?   _extract_items  s    zBBCCoUkIE._extract_itemsc                 C   s&   | d}|rt|| dp$g S )Nresultmedia)rI   r   rF   )r;   media_selectionr=   r>   r>   r?   _extract_medias  s    

zBBCCoUkIE._extract_mediasc                 C   s   | dpg S )NrO   rH   )r;   rX   r>   r>   r?   _extract_connections#  s    zBBCCoUkIE._extract_connectionsc                 C   sj   i }|  |D ]V}t|d}|s&q| j||ddd}t|tjjjsJq|dddg|d<  qfq|S )NrG   zDownloading captionsFfatalZttml)r$   r   en)	r[   r   rI   rM   
isinstancexmletreeElementTreeElement)r;   rX   rP   	subtitlesrO   Zcc_urlcaptionsr>   r>   r?   _get_subtitles&  s&       zBBCCoUkIE._get_subtitlesc                 C   s   t | j d|j ddd S )N returned error: Tr5   )r   IE_NAMEr   )r;   Zmedia_selection_errorr>   r>   r?   _raise_extractor_error9  s    z BBCCoUkIE._raise_extractor_errorc           	      C   s   d }g i  }}| j D ]}z:| | j||f |\}}|| |rP| j||d W q tjk
r } z$|jdkr||}W Y q| | W 5 d }~X Y qX q|r|s|r| 	| j
 d|j  n
| | ||fS )N)target)Z
notukerrorr,   Zselectionunavailablerg   )_MEDIA_SETS_download_media_selector_url_MEDIA_SELECTOR_URL_TEMPLextendZ_merge_subtitlesr   rF   r   ri   Zreport_warningrh   )	r;   rP   Zlast_exceptionformatsrd   Z	media_setfmtssubser>   r>   r?   _download_media_selector>  s*    

 


z"BBCCoUkIE._download_media_selectorNc                 C   s   | j ||ddd}| ||S )Nz Downloading media selection JSONi    )Zexpected_status)_download_json_process_media_selector)r;   r$   rP   rY   r>   r>   r?   rl   T  s      z&BBCCoUkIE._download_media_selector_urlc                 C   s  g }d }g }|  |D ]}|d}|dkrt|d}|d}	t|d}
t|d}t|d}| |D ]N}|d}||krq||r|| |d}|d	}|d
}|d}|p|p|}|dkrt| ||D ]$\}}||d| d| d qq||dkr>|| j|||dd q||dkrz| j	||dd|dd}W nN t
k
r } z.t|jd tr|jd jdks g }W 5 d }~X Y nX || q||dkr|| j|||dd q||s|r|d| 7 }||d}|dkr&||
|||	d n|||	dd  |d!krR|d"|i np|d#kr||d$d%}|d&}|d'}|d(}|| d)| d*| d+| || d+| d,d-dd.d/ nq||| q|q|d0kr| ||}q||fS )1Nkind)videoaudiobitrateencodingwidthheightZmedia_file_sizerG   protocolsupplierZtransferFormatrQ   rK   _)r$   	format_idZdashF)Zmpd_idr]   Zhlsmp4Zm3u8_native)r   Zentry_protocolZm3u8_idr]   r   rt   Zhds)Zf4m_idr]   -)r   filesizery   )r}   r~   tbrvcodecnone)ZabrZacodecr   )httphttpsr$   ZrtmpapplicationZondemandZ
authString
identifierserverz:///?zhttp://www.bbc.co.ukz[http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swfr   )r$   Z	play_pathZapppage_urlZ
player_urlZ	rtmp_liver   re   )rZ   rI   r   r[   append	enumeraterR   rn   Z_extract_mpd_formatsZ_extract_m3u8_formatsr   r_   exc_infor   statusZ_extract_f4m_formatsr9   Zextract_subtitles)r;   rY   rP   ro   rd   urlsrX   rx   r{   r|   r}   r~   	file_sizerO   rG   Z	conn_kindr   r   Ztransfer_formatr   irK   rp   rr   fmtr   Zauth_stringr   r   r>   r>   r?   rw   Z  s    










   

    

   



 




z!BBCCoUkIE._process_media_selectorc              
   C   sZ  z
|  d| d|d}g }i }|dg D ]}|d }|d }|d }|d D ]}	|	d	 }
|
d
krhqR|	d}t|	d}| |\}}|d }|D ],}d||d< tdd |D rd|d< q||7 }|pi  D ]\}}||g | qqRq.||||||fW S  t	k
rN } z"t
|jtr<|jjdks> W 5 d }~X Y nX | |S )Nz http://www.bbc.co.uk/programmes/z/playlist.jsonzDownloading playlist JSONZallAvailableVersionsZ	smpConfigr    summaryitemsrx   	programmeZradioProgrammevpidr'   typesz, Zformat_notec                 s   s   | ]}d |kV  qdS )ZAudioDescribedNr>   )rJ   xr>   r>   r?   	<genexpr>  s     z/BBCCoUkIE._download_playlist.<locals>.<genexpr>iZlanguage_preferenceru   )rv   rI   r   rs   joinanyr   
setdefaultrn   r   r_   causer   r   _process_legacy_playlist)r;   playlist_idrU   ro   rd   versionZ
smp_configr    r!   itemrx   rP   r'   Zversion_formatsZversion_subtitlesr   ftagZ
subformatseer>   r>   r?   _download_playlist  s@    
 

zBBCCoUkIE._download_playlistc                 C   s   |  ||}| ||S rA   )_download_legacy_playlist_url_extract_from_legacy_playlist)r;   r$   
display_idrU   r>   r>   r?   _process_legacy_playlist_url  s    z&BBCCoUkIE._process_legacy_playlist_urlc                 C   s   |  d| |S )Nz&http://www.bbc.co.uk/iplayer/playlist/r   )r;   r   r>   r>   r?   r     s     z"BBCCoUkIE._process_legacy_playlistc                 C   s   |  ||dS )NzDownloading legacy playlist XML)rM   )r;   r$   r   r>   r>   r?   r     s
      z'BBCCoUkIE._download_legacy_playlist_urlc                    s@  | d j d}|d k	r|d}|dkr<d| d}n<|dkrRd| d}n&|d	krhd| d
}nd| d| }t|dd |D ]}|d}|dkrq| d j dj}| d j d}	|	d k	r|	jnd }
 fdd}||}t|d}|r |\}}q ||\}}|}q|||
|||fS )NrS   z}noItemsreasonZpreAvailabilityzEpisode z is not yet availableZpostAvailabilityz is no longer availableZnoMediaz is not currently availablez is not available: Tr5   rx   r   z}titlez}summaryc                    s8   dd }||  |  d j d}|d k	r4||S d S )Nc                 S   s0   dD ]&}|  |}|rtd|r|  S qd S )N)r   r2   z^[pb][\da-z]{7}$)rI   rematch)r   pvaluer>   r>   r?   get_from_attributes   s    
z^BBCCoUkIE._extract_from_legacy_playlist.<locals>.get_programme_id.<locals>.get_from_attributesrS   z	}mediator)findrT   )r   r   Zmediatorr;   r>   r?   get_programme_id  s
    zABBCCoUkIE._extract_from_legacy_playlist.<locals>.get_programme_idr'   )	r   rT   rI   r   rV   textr   rs   rw   )r;   rU   r   Zno_itemsr   msgr   rx   r    Zdescription_elr!   r   rP   r'   ro   rd   r>   r   r?   r     s4    

z'BBCCoUkIE._extract_from_legacy_playlistc                 C   s,  |  |}| ||d}| jd|dd d}|r:t|ddd }d }| jd|dd d}|r| ||di }t|d	}|d
}|s| jd| j d|d
dd d}|r| |\}	}
| j	|d dp| 
d|d}| jd|dd d}|s| d|}n| |\}}}}}	}
|||| j|d d||	|
dS )NzDownloading video pagezP<div\b[^>]+\bclass=["\'](?:smp|playout)__message delta["\'][^>]*>\s*([^<]+?)\s*<r=   r1   Tr5   z6mediator\.bind\(({.+?})\s*,\s*document\.getElementByIdplayerr'   r   z"vpid"\s*:\s*"()"F)r]   r1   )z)<h2[^>]+id="parent-title"[^>]*>(.+?)</h2>z,<div[^>]+class="info"[^>]*>\s*<h1>(.+?)</h1>r    )z3<p class="[^"]*medium-description[^"]*">([^<]+)</p>z2<div[^>]+class="info_+synopsis"[^>]*>([^<]+)</div>r!   )r   r    r!   	thumbnailr'   ro   rd   )	_match_idr7   r:   r   _parse_jsonrI   r   	_ID_REGEXrs   _og_search_title_html_search_regexZ_html_search_metar   Z_og_search_thumbnail)r;   r$   group_idwebpager=   rP   r'   Z	tviplayerr   ro   rd   r    r!   r>   r>   r?   _real_extract  sl    
    
       zBBCCoUkIE._real_extract)N)N) rC   rD   rE   rh   IE_DESCr   
_VALID_URLZ_EMBED_REGEXr8   Z_NETRC_MACHINErm   rk   rT   _TESTSr@   	ExceptionrF   rR   rV   rZ   r[   rf   ri   rs   rl   rw   r   r   r   r   r   r   r>   r>   r>   r?   r   "   sr  
 	 	 	 	 	 	 	 	     7
_$
,r   c                %       s  e Zd ZdZdZdZddgZdddd	d
ddddddd
dddddddd
dddddddddd d!d"d#d$id%d&d'dd(d)d*d+d,d#d$id-d.d/d0d1dd2d2d3d4d5d6d#d$id%d7d8dd9d:d9d;d#d$id<d.d=d>dd?d@dAdBdCdDdEdFdGdHddIdJdKdLd,dMdNdOdPddQdRdSdTdUdVdWdNdXdYddZd[d\d]d^d_d`dFdadbdcddd
deddadfddgdhdidjdkdldmd$id%dndodpdqdrdsddtd$dudvdwddxdydzd{d|d}d~dFddddddzdddd~dFddddddzdddd~dFdd$dudddddddzddFddddddddd<dNddddddde gddddddddddddFddddddddddddg ddFdd$dudd$dugZ	e
 fddZdd Zdd Zdd Z  ZS )BBCIEr   ZBBCa  (?x)
        https?://(?:www\.)?(?:
            bbc\.(?:com|co\.uk)|
            bbcnewsd73hkzno2ini43t4gblxvycyac5aw4gnv7t2rccijh7745uqd\.onion|
            bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad\.onion
        )/(?:[^/]+/)+(?P<id>[^/#?]+)r   zmobile-tablet-mainz-http://www.bbc.com/news/world-europe-32668511zworld-europe-32668511z8Russia stages massive WW2 parade despite Western boycottz$md5:00ff61976f6081841f759a08bf78cc9cr   r    r!   r   )r$   r%   playlist_countz)http://www.bbc.com/news/business-28299555zbusiness-28299555z%Farnborough Airshow: Video highlightsz<BBC reports and video highlights at the Farnborough Airshow.	   z	Save time)r$   r%   r   r)   zRhttp://www.bbc.co.uk/blogs/adamcurtis/entries/3662a707-0af9-3149-963f-47bea720b460z$3662a707-0af9-3149-963f-47bea720b460ZBUGGERzdre:BUGGER  The recent revelations by the whistleblower Edward Snowden were fascinating. .{211}\.{3}$   z-http://www.bbc.com/news/world-europe-32041533Zp02mprgbr   z#Germanwings crash site aerial videozZre:(?s)Aerial video showed the site where the Germanwings flight 4U 9525, .{156} BFM TV\.$/   i*UZ20150324zShttps://ichef.bbci.co.uk/news/1024/media/images/81879000/jpg/_81879090_81879089.jpg)r   r   r    r!   r'   	timestampupload_dater   r"   Tr#   zFhttp://www.bbc.com/turkce/haberler/2015/06/150615_telabyad_kentin_coguZ150615_telabyad_kentin_coguu*   YPG: Tel Abyad'ın tamamı kontrolümüzdez$md5:33a4805a855c9baf7115fcbde57e7025i*UZ20150615)r   r   r    r!   r   r   znow SIMORGH_DATA with no videor(   zehttp://www.bbc.com/mundo/video_fotos/2015/06/150619_video_honduras_militares_hospitales_corrupcion_awZ39275083Z8150619_video_honduras_militares_hospitales_corrupcion_awuF   Honduras militariza sus hospitales por nuevo escándalo de corrupcióni6UZ20150619zhttps://a.files.bbci.co.uk/worldservice/live/assets/images/2015/06/19/150619132146_honduras_hsopitales_militares_640x360_aptn_nocredit.jpg)r   r   r   r    r!   r   r   r   z9http://www.bbc.com/news/video_and_audio/must_see/33376376Zp02w6qjczYJudge Mindy Glazer: "I'm sorry to see you here... I always wondered what happened to you"8   )r   r   r    r'   r!   z404 Not Foundz@http://www.bbc.com/travel/story/20150625-sri-lankas-spicy-secretZp02q6gc4z#Tasting the spice of life in JaffnauY   re:(?s)BBC Travel Show’s Henry Golding explores the city of Jaffna .{151} aftertaste\.$ibZ20220228   z6https://ichef.bbci.co.uk/images/ic/1920xn/p02vxvkn.jpg)r   r   r    r!   r   r   r'   r   )r$   r%   z:http://www.bbc.com/autos/story/20130513-hyundais-rock-starZp018zqqgz!Hyundai Santa Fe Sport: Rock starz$md5:b042a26142c4154a6e472933cf20793di4ldTZ20141113zredirects to TopGear home page)r$   r%   r)   z1http://www.bbc.co.uk/sport/live/olympics/36895975Zp041vhd0z#Nigeria v Japan - Men's First RoundzDLive coverage of the first round from Group B at the Amazonia Arena.i,  z	BBC SportZ	bbc_sport)r   r   r    r!   r'   uploaderuploader_idzVideo no longer in pagez,http://www.bbc.com/sport/0/football/33653409Zp02xycnpz%Ronaldo to Man Utd, Arsenal to spend?zXre:(?s)BBC Sport\'s David Ornstein rounds up the latest transfer reports, .{359} here\.$iSUZ20150724zTre:https?://.+/.+media/images/69320000/png/_69320754_mmgossipcolumnextraaugust18.png   )r   r   r    r!   r   r   r   r'   z,http://www.bbc.com/sport/0/football/34475836Z34475836z=Jurgen Klopp: Furious football from a witty and winning coachzrFast-paced football, wit, wisdom and a ready smile - why Liverpool fans should come to love new boss Jurgen Klopp.   Zp034ppnvz'All you need to know about Jurgen KloppiVZ20151008g     ^@zWhttps://ichef.bbci.co.uk/onesport/cps/976/cpsprodpb/7542/production/_85981003_klopp.jpg)r   r   r    r   r   r'   r   Z
noplaylistz*http://www.bbc.co.uk/schoolreport/35744779Z35744779z.School which breaks down barriers in Jerusalemr   r    r   zTredirects to Young Reporter home page https://www.bbc.co.uk/news/topics/cg41ylwv43ptz,http://www.bbc.com/weather/features/33601775r-   z6http://www.bbc.co.uk/news/science-environment-33661876Zp02xzws1z"Pluto may have 'nitrogen glaciers'z$md5:6a95b593f528d7a5f2605221bc56912fzre:https?://.+/.+\.jpgi۲UZ20150725i   )r   r   r    r!   r   r   r   r'   z1https://www.bbc.com/news/av/world-europe-59468682Zp0b779gcz/Why France is making this woman a national herozjre:(?s)France is honouring the US-born 20th Century singer and activist Josephine .{208} Second World War.i/aZ20211129}   z$https://www.bbc.com/news/uk-68546268Zp0hj0lq7z5Nasser Hospital doctor describes his treatment by IDFzXre:(?s)Doctor Abu Sabha said he was detained by Israeli forces after .{276} hostages\."$ifeZ20240311h   z*http://www.bbc.co.uk/sport/rowing/35908187zHhttps://www.bbc.co.uk/bbcthree/clip/73d0bbd0-abc3-4cea-b3c0-cdae21905eb1Zp06556y7z8Things Not To Say to people that live on council estatesuL  From being labelled a 'chav', to the presumption that they're 'scroungers', people who live on council estates encounter all kinds of prejudices and false assumptions about themselves, their families, and their lifestyles. Here, eight people discuss the common statements, misconceptions, and clichés that they're tired of hearing.ih  )r   r   r    r!   r'   r   z)https://www.bbc.co.uk/radio/play/b0b9z4ylZb0b9z4vzz,Prom 6: An American in Paris and Turangalilaz$md5:51cf7d6f5c8553f197e58203bc78dff8zRadio 3Zbbc_radio_three)r   r   r    r!   r   r   zIhttp://www.bbc.co.uk/learningenglish/chinese/features/lingohack/ep-181227Zp06w9twsz$md5:2fabf12a726603193a2879a055f72514z/Learn English words and phrases from this storyz8https://ichef.bbci.co.uk/images/ic/1200x675/p06pq9gk.jpg)r   r   r    r!   r   )r$   r%   add_iezWhttps://www.bbc.com/reel/video/p07c6sb6/how-positive-thinking-is-harming-your-happinessZp07c6sb9z"The downsides of positive thinking   z)re:https?://.+/p07c9dsr\.(?:jpg|webp|png)Z20220223i\b)r   r   r    r!   r'   r   r   r   z*https://www.bbc.co.uk/sounds/play/w3ct5rgxZp0hrw4nrz%Are our coastlines being washed away?zNre:(?s)Around the world, coastlines are constantly changing .{2000,} Images\)$i@"fZ20240419i4  z3https://ichef.bbci.co.uk/images/ic/raw/p0hrnxbl.jpgzWorld ServiceZbbc_world_serviceZCrowdScience)r   r   r    r!   r   r   r'   r   r   r   serieschapterszhhttps://www.bbcnewsd73hkzno2ini43t4gblxvycyac5aw4gnv7t2rccijh7745uqd.onion/news/av/world-europe-63208576zehttps://www.bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion/sport/av/football/63195681c                    s4   t ttttf}t fdd|D r(dS t  S )Nc                 3   s   | ]}|  V  qd S rA   )suitable)rJ   Zier$   r>   r?   r     s     z!BBCIE.suitable.<locals>.<genexpr>F)r   BBCCoUkArticleIEBBCCoUkIPlayerEpisodesIEBBCCoUkIPlayerGroupIEBBCCoUkPlaylistIEr   superr   )clsr$   Z
EXCLUDE_IE	__class__r   r?   r     s    
zBBCIE.suitablec           
      C   s|   | d}|r$dd | D g fS | d}|r<| |S | d}|rt| |}| ||\}}}}}}	||	fS g g fS )NZsourceFilesc              
   S   sJ   g | ]B\}}| d r|d  || dt| ddt| ddqS )r$   r|   r{     r   )r$   r   r   r   r   )rI   r
   r   )rJ   r   r   r>   r>   r?   rL     s    
z2BBCIE._extract_from_media_meta.<locals>.<listcomp>
externalIdrG   )rI   r   rs   r   r   )
r;   
media_metavideo_idZsource_filesrP   rG   rU   r   ro   rd   r>   r>   r?   _extract_from_media_meta  s     




zBBCIE._extract_from_media_metac           
      C   s,   |  ||\}}}}}}	|||||||	dS )N)r   r    r!   r'   r   ro   rd   r   )
r;   r$   r   r   rP   r    r!   r'   ro   rd   r>   r>   r?   _extract_from_playlist_sxml  s    
z!BBCIE._extract_from_playlist_sxmlc           O         s   ji d}|d|dpZtddjddd pZd }|dprjd d}st	j
dd	d
gdd dg td}|td |rЇfdd|D td}|r|D ]\}}jt|dd}	|	sq|	di }
|
r|
di }|r|d}|rt|tr|d }|d}t|d d}|d d}|\}}||||||d q|	di di }|rd }dD ]}|| d}|sqz<|}|s |}n|d |d< |d |d  W nL tk
rl } z,t|jtrZ|jjd krZW Y 
qƂ W 5 d }~X Y nX q|r| qr||S j
d!j d"d#d d}|r̈d$| tS j
d%j d&d'j d&d(j d)gdd d}|r|\}}jj
d*d+d,d|dd}|d-i d.i }|d/p\}|dpr}t	|d0p|||||d1S jjd2d3d,d4d5dd}|rt|d6d7 t pi }|d8pi }t|d9d7 t pi }|d:} | r|d }| \}}|d;}!|d<}"|d=}#| |||d>|!r`|!!d?d@nd |dpv|dA|"r|"!dBdnd |t|d|#r|#gnd dC
S j"dDdEdFi dG}$|$rt#|$dHdIdJdKdLt hfD ]}%t#|%dMdNt$ht%f}|sq|\}}||%dp&dOt#|%dt$hfddPt&hfdQt$hfdRt$hfdS||dT  S jt#|$dUdd}&t#|&dVd7 dWfD ]}'|'dr|'d }(|(\}}|(||dX}n |'dY }(jd$|( t|(dZd[}|'dt#|$dHd\d]d^d_t	hfit#|'d`t(ht%fdat$ht%fdt&hfdb |'dcrN)|(sN|  S | qrt#|$dHd\d]ddt$hfp||}||S j"dedft*i dgt#dhdit hf})t#|)djt$hf}|r|)dkdlkrt#|)dmdnt$ht%fp|}|\}}|||dot#|)dpdqt$ht%fdrdsd7 hfddtthfdudvt$hfdudjt$hfdwt	ht%fdmdxt$hfdy|t#dzd{d|d7 dmd}d7 hfd~dt+hfd~dt+hfdfdS t#ddfdd7ddt$ht%f  rt#dd dt$hf}(|(rnt#dd fdd7t%f}*fdd}!|(\}}dj|(it#dd dt$hfdt$ht%fd|!hfdthfdf||t#|*d<t	hfdS jd$  t ||dS jj
ddd,dt*ddpi }+|+dpi },|,	r|,dpi }-|-d}.|-d}/|.	r.|/	r.|.\}}|.|/t,|-d|-dt&|-d||dS t|,dd7 t }0|0	r|0d	pR|}|0d;}1g |0d D ]@}2|2d:}|	s	qj|\}}|||1||d 	qj||S fdd}3dd }4j
ddd d}|d k
rj
ddfd,d}nj|
pddd}j|dd}|r8t#|dd]d|4dfD ]D}'t#|'dd|4ddd|4ddt ht%f	}5|3|5}|
rD| 
qD
r||S fdd}6t#|ddd7 fD ]f}7|7d }8|8dk
r|6t|7dd7 t  n8|8d]k
rt#|7ddd|4dddt hfD ]}9|6|9 q
q||S j"ddi d}:|:rd};t#|:dd\dd|4ddfD ]4}'t#|'dd|4ddd|4ddt ht%f	}5|'dk dkr|3|5}nt#|5dt$hfd  }t#|:dddfdd7hf}<t#|<ddd7 dt(hfdt$hfdt-j.tddhfdf}|r|t#|:dddt$hfdt#|5dt$hfdfdd7hfdpdqt$ht%fdt-j.tddhfd}dZ};|r| |;rp qqpr||S fddĄ}=t#j/i ddŃ}>t#|>dJd|4ddd|4ddd|4dǃdt ht%f}5|5rz|3|5 }rz|ds`t#|>dJd|4dddt-j.tddht%f|d< | ||S dȈj dɝ}?g |=dʃD ]6}@|@di d̡}A|Art0|?|Ar|A qtd|? dΝ r
fddD ||S |=dЃ}B|Bsjj
dшdd d}C|Crjj|Cdd}Dg }B|Ddi 1 D ]}E|B|E1  qT|Bs
dӈdԡ}Fg }G|FD ]H}H|Hd}I|Isq|G|I |Hdi d֡kr|Ig}B qؐq|Bs|G}Bg t2|Bdd؍D ]\}J}K3|K\}}|s"4d١s"q|Kdڡ}(|(sRt5|BdkrDn dB|J }(|Kdۡ}|st5|Bdkrt|n| d|J }t|Kdݡpt&|Kd}g }L|Kdi 1 D ]}M|L|M1  qd|Kkr|L|Kd  dd |LD }N|(||N|||d q||S )Nr   r   r    z(.+)\s*-\s*BBC.*?$z\1 r!   zA<meta[^>]+property="article:published_time"[^>]+content="([^"]+)"z/itemprop="datePublished"[^>]+datetime="([^"]+)"z"datePublished":\s*"([^"]+)datez.<param[^>]+name="playlist"[^>]+value="([^"]+)"z&data-media-id="([^"]+/playlist\.sxml)"c                    s   g | ]} | qS r>   )r   )rJ   playlist_url)r   r;   r   r>   r?   rL     s   z'BBCIE._real_extract.<locals>.<listcomp>zdata-playable=(["\'])({.+?})\1Fr\   settingsZplaylistObjectr   r   r   r'   r   )r   r    r!   r   r'   ro   rd   ZotherSettingsrU   )Z	streamingZprogressiveDownloadUrlro   i  z6<div[^>]+\bclass=["\']video["\'][^>]+\bdata-pid=["\']()zgroup idz!https://www.bbc.co.uk/programmes/z#data-(?:video-player|media)-vpid="(r   z1<param[^>]+name="externalIdentifier"[^>]+value="(zvideoId\s*:\s*["\'](z)["\']z#var\s+digitalData\s*=\s*({.+?});?\nzdigital dataz{}pageZpageInfoZpageNameZpublicationDate)r   r    r!   r   ro   rd   zP<script[^>]+id=(["\'])initial-data\1[^>]+data-json=(["\'])(?P<json>(?:(?!\2).)+)zinitial datajsonr0   c                 S   s   | d d d S )NZinitDatar   r   r>   r   r>   r>   r?   <lambda>5      z%BBCIE._real_extract.<locals>.<lambda>ZsmpDatac                 S   s   | d d S )Nr   r   r>   r   r>   r>   r?   r   7  r   Z	versionIDZholdingImageURLZdisplayDateZ
topicTitleZ
shortTitle$reciperawZshortSummaryr   )
r   r    ro   Z	alt_titler   r!   r   rd   r'   
categoriesz$\bMorph\s*\.\s*setPayload\s*\([^,]+,zmorph payloadz?{(?s:(?:(?!</script>).)+(?:"leadMedia"|\\"videoData\\")\s*:.+)})Zcontains_patternr1   body
components.propsZ	leadMediaZidentifiers)r   ZplayablePidr   )ZrawDurationZformattedDurationZspokenDurationZmasterBrandZmid)r!   r'   r   r   )ro   rd   )r  contentarticler  c                 S   s   |d d S )N	videoDatapidr>   r   vr>   r>   r?   r   i  r   r  r   ro   rd   r  T)Zurl_transparentr  r  ZdateTimeInfoZdateTime)Z
iChefImageimage)r    caption)r   r    r'   ZisLeadZheadlinez(window\.__(?:PWA_)?PRELOADED_STATE__\s*=zpreload state)transform_sourcer1   Z
programmescurrentr   typeZplayable_itemtitles)tertiary	secondary)r   r    ro   synopseslongmediumshort	image_urlc                 S   s   t | ddS )N{recipe}r   r   replaceur>   r>   r?   r     r   r   networkZshort_title))Zavailabilityfrom)releaser   primary)r!   r   r'   r   r   r   r   Z	tracklistZtracksc                 S   s   t |d d S )Noffsetstart)floatr  r>   r>   r?   r     r   c                 S   s   t dddd| dS )Nr!  r  r  z - )delim	from_dict)r   r   r>   r>   r?   r     s       r"  r#  end)r    
start_timeZend_time)rd   r   entitiesZarticlesc                    s   |  ddd  kS )Nr   r   )rsplit)kr   )r   r>   r?   r     r   
assetVideoZvideosc                    s   |d d  kS )Nr-  r   r>   r  )asset_idr>   r?   r     r   c                    s   t  dd| ddd hfS )Nr)  imagesr$   c                 S   s   t | ddS Nr   r   r  r  r>   r>   r?   r     r   z8BBCIE._real_extract.<locals>.image_url.<locals>.<lambda>)r   )Zimage_id)preload_stater>   r?   r    s       z&BBCIE._real_extract.<locals>.image_url)ZsynopsisLongZsynopsisMediumZsynopsisShort)r    r!   r   r'   )ro   rd   r   )r   r!   z((?s)bbcthreeConfig\s*=\s*({.+?})\s*;\s*<zbbcthree config)r  r]   payloadZcurrentClip)ZposterimageUrl)r   r    r   r!   r'   ro   rd   c                 S   s   | d d d S )Nr  ZbbcMediarU   r>   r   r>   r>   r?   r     r   )r   r    r   r   ro   rd   c                    s   t | dddthf}|sdS  |\}}|||dt | dthfdfdd	hfd
dthdd	 htfdddthfdddtjtddhfdS )z)Extract single video from model structureversionsr   Z	versionIdNr
  r    r3  c                    s   t  | ddS r0  r   r  r  r   r>   r?   r     r   z:BBCIE._real_extract.<locals>.parse_model.<locals>.<lambda>r  r  c                 S   s   | pd S rA   r>   r   r>   r>   r?   r     r   r'   ZavailableFromr   Zscale)r    r   r!   r'   r   )r   strrs   r   int	functoolspartialr   )modelitem_idro   rd   )r;   r$   r>   r?   parse_model  s     z(BBCIE._real_extract.<locals>.parse_modelc                     s    fddS )Nc                    s   |d  kS )Nr  r>   r  r   r>   r?   r     r   z6BBCIE._real_extract.<locals>.is_type.<locals>.<lambda>r>   r>  r>   r>  r?   is_type  s    z$BBCIE._real_extract.<locals>.is_typez,window\.__INITIAL_DATA__\s*=\s*("{.+?}")\s*;zquoted preload statez*window\.__INITIAL_DATA__\s*=\s*({.+?})\s*;z"{}"ZstoresZarticleBodyContentry   r;  blocksZ	aresMediaZaresMediaMetadatac                    s  | sd S t | dd tpg D ]}|d}|d}|r|s>q|\}}d }t | dd t}|rg }|D ]"}	t |	dd t}
|
rl||
 ql|rd|}d }t | dd tpg D ](}t |d	d d
krt|d} qq |||d|||t|t	|dd qd S )Nc                 S   s   | d d S )NrX   r   r>   r   r>   r>   r?   r   +  r   z:BBCIE._real_extract.<locals>.parse_media.<locals>.<lambda>r   r    c                 S   s   | d d S )Nr   r@  r>   r   r>   r>   r?   r   2  r   c                 S   s   | d d S )Nr;  r   r>   r   r>   r>   r?   r   6  r   z

c                 S   s   | d d S )Nmetadatar   r>   r   r>   r>   r?   r   <  r   c                 S   s   | d S )Nlabelr>   r   r>   r>   r?   r   =  r   Z	Publishedr   ZholdingImageUrlr'   )r   r    r   ro   rd   r   r!   r'   )
r   listrI   rs   r7  r   r   r   r   r   )rX   r   r<  Z
item_titlero   rd   Z	item_descr@  r   blockr   Z	item_timemeta)entriesr;   r>   r?   parse_media(  sB    


z(BBCIE._real_extract.<locals>.parse_mediar3   c                 S   s   |d S )Nnamer>   r  r>   r>   r?   r   K  r   rH  zmedia-experiencec                 S   s   | d d d S )Nr3   ZinitialItemZ	mediaItemr>   r   r>   r>   r?   r   N  r   )N)r  r;  rX   zwindow\s*\.\s*SIMORGH_DATA\s*=zsimorgh dataZpageDataZlegacyMediaZblockIdZpromoc                    s   | d  kr| S d S )Nr   r>   r   )block_idr>   r?   r   i  r   c                 S   s   t |d S )Nr$   )r   r  r>   r>   r?   r   j  r   r$   formatr{   r   r6  )r$   r   r   )r   r   ro   r!   r3  c                    s   t  | ddS r0  r5  r  r   r>   r?   r   w  r   ZfirstPublished)r    r   r!   r   c                    s&   t td  fddt| D S )Nc                 3   s   | ]}j | d dV  qdS )Fr\   N)r   )rJ   s)r   r;   r>   r?   r     s   z;BBCIE._real_extract.<locals>.extract_all.<locals>.<genexpr>)rC  filterr   rN   )pattern)r   r;   r   r>   r?   extract_all  s    
z(BBCIE._real_extract.<locals>.extract_all)r  Z	pagePropsr   contentsZmediaMetadataz*https?://(?:www\.)?bbc\.co\.uk/(?:[^/]+/)+z(?:\b[^"]+)?znew\s+SMP\(({.+?})\)ZplayerSettingsZexternalEmbedUrlzsetPlaylist\("(z)"\)c                    s   g | ]}  |d qS )BBCCoUk
url_result)rJ   Zentry_r   r>   r?   rL     s     zdata-media-meta='({[^']+})'z$mediaAssetPage\.init\(\s*({.+?}), "/zmedia assetzW<script[^>]+class="vxp-playlist-data"[^>]+type="application/json"[^>]*>([^<]+)</script>zplaylist dataZadvertZassetIdr   )r#  Zignore_no_formatsr   r  z	 - Video ZdurationInSecondsr/  r  c                 S   s2   g | ]*}| d t| dt| ddqS )rG   r}   r~   )r$   r}   r~   )rI   r   )rJ   r  r>   r>   r?   rL     s
   )r   r    
thumbnailsr'   r   ro   rd   )6r   r7   Z_search_json_ldrI   r   subZ_generic_titlestrip_og_search_descriptionr   r:   rN   rn   r   r   r_   rC  r   rs   r   r   r   r   r   r   playlist_resultr   rR  r   r   r   r   dictr  Z_search_jsonr   r7  r   r   r9   r   Z_yes_playlistr   r
   r	   r9  r:  Z_search_nextjs_datar   valuesr   r   	get_paramlen)Or;   r$   Zjson_ld_infoZplaylist_titleZplaylist_descriptionZ	playlistsZdata_playablesr   Zdata_playable_jsonZdata_playabler   Zplaylist_objectr   r    r!   r'   rP   ro   rd   rU   entrykeyr   inforr   r   Zdigital_dataZ	page_infoZinitial_dataZ	init_dataZsmp_dataZ	clip_data
version_idr  Zdisplay_dateZtopic_titleZmorph_payloadZ
lead_mediar  Z
video_datar   Zcurrent_programmer  Zbbc3_configr2  ZclipZ	clip_vpidZ
clip_titleZbbc3_playlistr   Z	bbc3_itemr=  r?  r;  rG  resprH  rD  Zsimorgh_datadoneZ
media_datarN  Z	next_dataZ	EMBED_URLr   Z	embed_urlZmediasZmedia_assetZmedia_asset_pagery   Zvxp_playlistZplaylist_mediasr   rX   numr   r/  r  rS  r>   )	r.  rI  rF  r   r1  r;   r   r$   r   r?   r     s   

      


  
         
      



        

         


           




	  

  
     
  

       

	 

     
     
         #

    
                
  


                

   
      



 
 

zBBCIE._real_extract)rC   rD   rE   rh   r   r   rk   r   ie_keyr   classmethodr   r   r   r   __classcell__r>   r>   r   r?   r   I  s   	   	
     *r   c                   @   s8   e Zd ZdZdZdZdddddd	d
gdZdd ZdS )r   zGhttps?://(?:www\.)?bbc\.co\.uk/programmes/articles/(?P<id>[a-zA-Z0-9]+)zbbc.co.uk:articlezBBC articleszhttp://www.bbc.co.uk/programmes/articles/3jNQLTMrPlYGTBn0WV6M2MS/not-your-typical-role-model-ada-lovelace-the-19th-century-programmerZ3jNQLTMrPlYGTBn0WV6M2MSz}Calculating Ada: The Countess of Computing - Not your typical role model: Ada Lovelace the 19th century programmer - BBC FourzXHannah Fry reveals some of her surprising discoveries about Ada Lovelace during filming.r      rP  )r$   r%   r   r   c                    sX     |} ||} |} | } fddtd|D } ||||S )Nc                    s   g | ]}  |qS r>   rQ  )rJ   Zprogramme_urlr   r>   r?   rL     s     z2BBCCoUkArticleIE._real_extract.<locals>.<listcomp>z-<div[^>]+typeof="Clip"[^>]+resource="([^"]+)")r   r7   r   rV  rU  r   rN   rW  )r;   r$   r   r   r    r!   rF  r>   r   r?   r     s    

 zBBCCoUkArticleIE._real_extractN)rC   rD   rE   r   rh   r   Z_TESTr   r>   r>   r>   r?   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )BBCCoUkPlaylistBaseIEc                 c   s   dt jt j|jk}tdD ]|}t| j	t
j |D ]}| | j| t
 V  q<|rd d S | jd|dd dd}|s q| t j|||d| |}q$d S )Nr   r   zW<li[^>]+class=(["\'])pagination_+next\1[^>]*><a[^>]+href=(["\'])(?P<url>(?:(?!\2).)+)\2znext page urlr$   r0   zDownloading page )urllibparser   urlparsequery	itertoolscountr   rN   _VIDEO_ID_TEMPLATEr   r   rR  _URL_TEMPLATErc  r:   r7   r   )r;   r   r$   r   Zsingle_pageZpage_numr   Z	next_pager>   r>   r?   _entries  s:    
       zBBCCoUkPlaylistBaseIE._entriesc                 C   s>   |  |}| ||}| |\}}| | ||||||S rA   )r   r7   _extract_title_and_descriptionrW  rp  )r;   r$   r   r   r    r!   r>   r>   r?   r   *  s    
  z#BBCCoUkPlaylistBaseIE._real_extractN)rC   rD   rE   rp  r   r>   r>   r>   r?   rg    s   rg  c                   @   s@   e Zd Zdej dZedddZdd Zdd	 Z	d
d Z
dS )BBCCoUkIPlayerPlaylistBaseIEz1https?://(?:www\.)?bbc\.co\.uk/iplayer/%s/(?P<id>r   r1   c                    s   t |  fddS )Nc                    s   |    S rA   r>   r   default_keyr]  r>   r?   r   ;  r   z;BBCCoUkIPlayerPlaylistBaseIE._get_default.<locals>.<lambda>)r   )episoder]  rt  r>   rs  r?   _get_default9  s    z)BBCCoUkIPlayerPlaylistBaseIE._get_defaultc                 C   s   | | jpi }t|dS )N)Zlarger  small)rI   _DESCRIPTION_KEYr	   )r;   r3   synopsisr>   r>   r?   _get_description=  s    z-BBCCoUkIPlayerPlaylistBaseIE._get_descriptionc                 c   s   |  | |||d |}|D ]}| |}|d}|s<qd }	| |}
|
rZ|
dd}	| |dd}d|| |dd	| |	| ||r|gnd | |d
t	
 d	V  qd S )Nr   r   r  r   labelscategoryr$   Zsubtitlez&https://www.bbc.co.uk/iplayer/episode/r    )	_typer   r    r$   r   r!   r   r   rc  )_get_elements	_call_api_get_episoderI   _get_episode_imager  rv  _get_episode_fieldrz  r   rc  )r;   rP   per_page	series_idr   elementselementru  Z
episode_idr   r  r|  r>   r>   r?   _fetch_pageA  s4       




z(BBCCoUkIPlayerPlaylistBaseIE._fetch_pagec           
      C   s   |  |}t|}|dd gd }|dd gd }|r>dn| j}t| j|||}|rj|t|d n
t|| j}| 	| 
|d}	| ||| |	| |	S )NZseriesIdr   r   $   r   )r   r   rI   
_PAGE_SIZEr9  r:  r  r8  r   _get_playlist_datar  rW  _get_playlist_titlerz  )
r;   r$   r  qsr  r   r  
fetch_pagerF  Zplaylist_datar>   r>   r?   r   Z  s    
   z*BBCCoUkIPlayerPlaylistBaseIE._real_extractN)r1   )rC   rD   rE   r   r   _VALID_URL_TMPLstaticmethodrv  rz  r  r   r>   r>   r>   r?   rr  6  s   rr  c                	   @   s   e Zd ZdZejd Zddddddd	d
dddddd	ddddddd	ddddddd	ddddddd	gZdZdZ	dd Z
dd Zedd Zed d! Zd)d#d$Zed%d& Zd'd( Zd"S )*r   zbbc.co.uk:iplayer:episodesZepisodesz.http://www.bbc.co.uk/iplayer/episodes/b05rcz9vb05rcz9vzThe Disappearancez$md5:58eb101aee3116bad4da05f91179c0cbr      r$   r%   Zplaylist_mincountz=https://www.bbc.co.uk/iplayer/episodes/b094m5t9/doctor-fosterZb094m5t9zDoctor Fosterz$md5:5aa9195fad900e8e14b52acd765a9fd6
   zOhttps://www.bbc.co.uk/iplayer/episodes/b094m5t9/doctor-foster?seriesId=b094m6nv   z:https://www.bbc.co.uk/iplayer/episodes/m0004c4v/beechgroveZm0004c4vZ
BeechgrovezLGardening show that celebrates Scottish horticulture and growing conditions.%   zAhttps://www.bbc.co.uk/iplayer/episodes/m0004c4v/beechgrove?page=2r   d   ry  c                 C   s   |  |dS )Nr  rv  r;   ru  r>   r>   r?   r    s    z+BBCCoUkIPlayerEpisodesIE._get_episode_imagec                 C   s   |  ||S rA   r  r;   ru  fieldr>   r>   r?   r    s    z+BBCCoUkIPlayerEpisodesIE._get_episode_fieldc                 C   s   | d d S )Nr)  resultsr>   r3   r>   r>   r?   r~    s    z&BBCCoUkIPlayerEpisodesIE._get_elementsc                 C   s   |  dpi S )Nru  rH   r  r>   r>   r?   r    s    z%BBCCoUkIPlayerEpisodesIE._get_episodeNc              	   C   sF   |||d}|r||d< | j d|dditd|d dd	 d
 S )N)r   r   ZperPageZsliceIdz https://graph.ibl.api.bbc.co.uk/zContent-Typezapplication/jsonZ 5692d93d5aac8d796a0305e895e61551)r   	variables)r4   r3   r3   r   )rv   r   dumpsencode)r;   r  r  r   r  r  r>   r>   r?   r    s*      
z"BBCCoUkIPlayerEpisodesIE._call_apic                 C   s   | S rA   r>   r  r>   r>   r?   r    s    z+BBCCoUkIPlayerEpisodesIE._get_playlist_datac                 C   s   |  |dS Nr    r  r;   r3   r>   r>   r?   r    s    z,BBCCoUkIPlayerEpisodesIE._get_playlist_title)r   NrC   rD   rE   rh   rr  r  r   r   r  rx  r  r  r  r~  r  r  r  r  r>   r>   r>   r?   r   h  sd   

-



r   c                   @   s   e Zd ZdZejd Zddddddd	d
dddddd	ddddddd	gZdZdZ	dd Z
dd Zedd Zedd Zd#ddZedd  Zd!d" ZdS )$r   zbbc.co.uk:iplayer:groupr2   z+http://www.bbc.co.uk/iplayer/group/p02tcc32Zp02tcc32zBohemian Iconsz$md5:683e901041b2fe9ba596f2ab04c4dbe7r   r  r  z,https://www.bbc.co.uk/iplayer/group/p081d7j7Zp081d7j7zMusic in Scotlandz?Perfomances in Scotland and programmes featuring Scottish acts.r   z3https://www.bbc.co.uk/iplayer/group/p081d7j7?page=2      r  c                 C   s   |  |ddS )Nr/  standardr  r  r>   r>   r?   r    s    z(BBCCoUkIPlayerGroupIE._get_episode_imagec                 C   s
   | |S rA   rH   r  r>   r>   r?   r    s    z(BBCCoUkIPlayerGroupIE._get_episode_fieldc                 C   s   | d S )Nr  r>   r  r>   r>   r?   r~    s    z#BBCCoUkIPlayerGroupIE._get_elementsc                 C   s   | S rA   r>   r  r>   r>   r?   r    s    z"BBCCoUkIPlayerGroupIE._get_episoder   Nc                 C   s"   | j d| d|||ddd S )Nz'http://ibl.api.bbc.co.uk/ibl/v1/groups/z	/episodes)r   r  )rk  Zgroup_episodes)rv   )r;   r  r  r   r  r>   r>   r?   r    s    
zBBCCoUkIPlayerGroupIE._call_apic                 C   s   | d S )Nr2   r>   r  r>   r>   r?   r    s    z(BBCCoUkIPlayerGroupIE._get_playlist_datac                 C   s
   | dS r  rH   r  r>   r>   r?   r    s    z)BBCCoUkIPlayerGroupIE._get_playlist_title)r   Nr  r>   r>   r>   r?   r     sH   




r   c                   @   s   e Zd ZdZdej dZdZdZdddd	d
ddddddd
ddddddd
dddddddddddgZ	dd Z
dS )r   zbbc.co.uk:playlistz1https?://(?:www\.)?bbc\.co\.uk/programmes/(?P<id>z)/(?:episodes|broadcasts|clips)z"http://www.bbc.co.uk/programmes/%szdata-pid=["\'](%s)z.http://www.bbc.co.uk/programmes/b05rcz9v/clipsr  z$The Disappearance - Clips - BBC Fourz0French thriller serial about a missing teenager.r      r  z5http://www.bbc.co.uk/programmes/b00mfl7n/clips?page=1Zb00mfl7nzFrozen Planet - Clips - BBC Onez$md5:65dcbf591ae628dafe32aa6c4a4a0d8c   z.http://www.bbc.co.uk/programmes/b00mfl7n/clips   z;http://www.bbc.co.uk/programmes/b05rcz9v/broadcasts/2016/06Tr-   z8http://www.bbc.co.uk/programmes/b055jkys/episodes/playerc                 C   s    | j |dd}| |}||fS )NFr\   )r   rV  )r;   r   r    r!   r>   r>   r?   rq  +  s    
z0BBCCoUkPlaylistIE._extract_title_and_descriptionN)rC   rD   rE   rh   r   r   r   ro  rn  r   rq  r>   r>   r>   r?   r     sH   

%r   ))r9  rl  r   r   urllib.parserh  xml.etree.ElementTreer`   commonr   Znetworking.exceptionsr   utilsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg  rr  r   r   r   r>   r>   r>   r?   <module>   s6   X    +       6 2Y@