U
    g<                     @   sd   d dl Z d dl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 ddlmZ G dd deZdS )	    N   )InfoExtractor   )ExtractorError
clean_htmlextract_attributesget_element_by_classget_element_html_by_idjoin_nonemptyparse_durationunified_timestamp)traverse_objc                	   @   s<   e Zd ZdZdddddddd	d
dgZdd Zdd ZdS )LearningOnScreenIEzFhttps?://learningonscreen\.ac\.uk/ondemand/index\.php/prog/(?P<id>\w+)zNhttps://learningonscreen.ac.uk/ondemand/index.php/prog/005D81B2?bcast=22757013Z005D81B2Zmp4zPlanet Earthg      @g   yZAZ20061126zjhttps://stream.learningonscreen.ac.uk/trilt-cover-images/005D81B2-Planet-Earth-2006-11-26T190000Z-BBC4.jpg)idexttitleduration	timestampZupload_dateZ	thumbnail)urlZ	info_dictc                 C   s"   |  dds| jdd d d S )Nhttps://learningonscreen.ac.uk/zPHPSESSID-BOB-LIVEzUse --cookies for authentication. See  https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp  for how to manually pass cookies)method)Z_get_cookiesgetZraise_login_required)self r   E/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/learningonscreen.py_real_initialize!   s
    z#LearningOnScreenIE._real_initializec           
   	   C   sN  |  |}| ||}t|ttdhttjdhdthftt	dhttj
dhdthftt	dhththfdf}|dd pt|ttd	hthd
thf}| jd||dddddd}|stdt|dkr:|dd }t|ddD ].\}}	|	| t|||	d< t|||	d< q| j||||dS |d |||dS )Nzprogramme-detailsz<h2>([^<]+)</h2>r   zbroadcast-datez([^<]+)zprog-running-time)r   r   r   r   zadd-to-existing-playlistzdata-record-titlez%https://stream.learningonscreen.ac.ukZhlsZdashzhttps://learningonscreen.ac.ukr   )ZOriginZReferer)Zm3u8_idZmpd_id_headerszNo video foundr   )startr   )r   r   )r   r   )Z	_match_idZ_download_webpager   	functoolspartialr	   researchr   r   matchr   r   popr   Z_parse_html5_media_entriesr   len	enumerateupdater
   Zplaylist_result)
r   r   Zvideo_idZwebpagedetailsr   entriesr   idxentryr   r   r   _real_extract(   sX    
         
z LearningOnScreenIE._real_extractN)__name__
__module____qualname__Z
_VALID_URLZ_TESTSr   r+   r   r   r   r   r      s   r   )r   r    commonr   utilsr   r   r   r   r	   r
   r   r   Zutils.traversalr   r   r   r   r   r   <module>   s
   (
