U
    g&                     @   sx   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 G dd deZG d	d
 d
eZdS )    N   )InfoExtractor)
VHXEmbedIE   )ExtractorErrorOnDemandPagedList
clean_htmlextract_attributesget_element_by_classget_element_by_idget_elements_html_by_classint_or_nonetraverse_objunified_strdateurlencode_postdatac                   @   s   e Zd Z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gddddddd	ddd d!d"d#d"dd$dddd%dgdd&d'd(d)d*d	d+d,d-d.d/dddd0dgdgZd1d2 Zd3d4 Zd5d6 Z	d7S )8	DropoutIEzhttps://www.dropout.tv/loginZdropoutzAhttps?://(?:www\.)?dropout\.tv/(?:[^/]+/)*videos/(?P<id>[^/]+)/?$z=https://www.dropout.tv/game-changer/season:2/videos/yes-or-nozEpisode in a seriesZ 5e000fdfd8d8fa46ff40456f1c2af04aZ738153z	yes-or-noZmp4z	Yes or NozRAlly, Brennan, and Zac are asked a simple question, but is there a correct answer?Z20200508zYhttps://vhx.imgix.net/chuncensoredstaging/assets/351e3f24-c4a3-459a-8b79-dc80f1e5b7fd.jpgzGame Changerr   zSeason 2   i  Zuser80538407zhttps://vimeo.com/user80538407z
OTT Videos)id
display_idexttitledescriptionrelease_date	thumbnailseriesseason_numberseasonepisode_numberepisodedurationuploader_iduploader_urluploaderz2Ignoring subtitle tracks found in the HLS manifest)urlnotemd5	info_dictZexpected_warningszJhttps://www.dropout.tv/dimension-20-fantasy-high/season:1/videos/episode-1z*Episode in a series (missing release_date)Z 712caf7c191f1c47c8f1879520c2fa5cZ320562z	episode-1zThe Beginning BeginszdThe cast introduces their PCs, including a neurotic elf, a goblin PI, and a corn-worshipping cleric.zYhttps://vhx.imgix.net/chuncensoredstaging/assets/4421ed0d-f630-4c88-9004-5251b2b8adfa.jpgzDimension 20: Fantasy Highr   zSeason 1i  )r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   z;https://www.dropout.tv/videos/misfits-magic-holiday-specialzEpisode not in a seriesZ c30fa18999c5880d156339f13c953a26Z1915774zmisfits-magic-holiday-specialzMisfits & Magic Holiday SpecialzQThe magical misfits spend Christmas break at Gowpenny, with an unwelcome visitor.Z20211215zbhttps://vhx.imgix.net/chuncensoredstaging/assets/d91ea8a6-b250-42ed-907e-b30fb1c65176-8e24b8e5.jpgi-  )r   r   r   r   r   r   r   r   r    r!   r"   c                 C   s    | j | j|dd}| d|dS )NzGetting authenticity token)r$   z7name=["\']authenticity_token["\'] value=["\'](.+?)["\']authenticity_token)_download_webpage
_LOGIN_URLZ_html_search_regex)selfr   Zsignin_page r+   </tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/dropout.py_get_authenticity_token^   s       z!DropoutIE._get_authenticity_tokenc                 C   sx   |   \}}|sdS | j| j|ddt||| |ddd}| jd|ddd	}| d
kr`d S | dkrpdS dS d S )NTz
Logging inF)emailpasswordr'   utf8)r$   fataldataz(user_has_subscription:\s*["\'](.+?)["\']zsubscription statusnonedefaulttruefalsezAccount is not subscribedzIncorrect username/password)Z_get_login_infor(   r)   r   r-   _search_regexlower)r*   r   usernamer/   responseZuser_has_subscriptionr+   r+   r,   _logine   s4       	   zDropoutIE._loginc                 C   sj  |  |}d }| ddr*| ||}|r6d|krx| |}| ||}|rxd|krx|dkrl| jdd t|dd| d|d	}| |}t	d
|pd}t
td|}tdtd|}	t| jd|	pddd d}
dt t|d| d|d||| jd|dd|r|dd nd t
td||
|
r4|nd t| jd|	pFddd dt| jd|dd ddS ) Nzhttps://www.dropout.tv_sessionz<div id="watch-unauthorized"Tany)method)expectedzembed_url:\s*["\'](.+?)["\']z	embed urlz
watch-info zvideo-titlezsite-font-secondary-colortextzEpisode (\d+)r   r4   Zurl_transparentzembed\.vhx\.tv/videos/(.+?)\?r   r   F)r1   ?r   zseries-titlezSeason (\d+),r   zRdata-meta-field-name=["\']release_dates["\'] data-meta-field-value=["\'](.+?)["\']zrelease date)_typeie_keyr#   r   r   r   r   r   r   r   r   r   r   )	_match_idZ_get_cookiesgetr(   r<   Zraise_login_requiredr   r8   Z_og_search_thumbnailr   r   r
   r   r   rE   Z_smuggle_referrerZ_html_search_metasplitr   )r*   r#   r   webpageZ	login_errZ	embed_urlr   Z
watch_infor   Zseason_episoder   r+   r+   r,   _real_extract|   sb    


    
     zDropoutIE._real_extractN)
__name__
__module____qualname__r)   Z_NETRC_MACHINE
_VALID_URL_TESTSr-   r<   rJ   r+   r+   r+   r,   r      s   Er   c                	   @   sp   e Z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gZdd Zdd ZdS )DropoutSeasonIE   zVhttps?://(?:www\.)?dropout\.tv/(?P<id>[^\/$&?#]+)(?:/?$|/season:(?P<season>[0-9]+)/?$)z9https://www.dropout.tv/dimension-20-fantasy-high/season:1z.Multi-season series with the season in the urlz"dimension-20-fantasy-high-season-1z$Dimension 20 Fantasy High - Season 1)r   r   )r#   r$   Zplaylist_countr&   z0https://www.dropout.tv/dimension-20-fantasy-highz2Multi-season series with the season not in the urlz/https://www.dropout.tv/dimension-20-shriek-weekzSingle-season series   z!dimension-20-shriek-week-season-1z#Dimension 20 Shriek Week - Season 1z?https://www.dropout.tv/breaking-news-no-laugh-newsroom/season:3zCMulti-season series with season in the url that requires pagination   z(breaking-news-no-laugh-newsroom-season-3z*Breaking News No Laugh Newsroom - Season 3c                 #   s\   |d7 } j | d| |d| dhd} fddttd|d	thd
fD E d H  d S )Nr   z?page=zDownloading page i  )r$   Zexpected_statusc                    s   g | ]}  |tqS r+   )Z
url_resultr   ).0Zitem_urlr*   r+   r,   
<listcomp>   s     z/DropoutSeasonIE._fetch_page.<locals>.<listcomp>zbrowse-item-link.href)r(   r   r   r	   )r*   r#   	season_idpagerI   r+   rU   r,   _fetch_page   s        
zDropoutSeasonIE._fetch_pagec                 C   sd   |  |}| |dpd}|dd }| tt| j	||| j
| d| | d| S )Nr   r   - z-season-z
 - Season )rF   Z_match_valid_urlgroupreplacer   Zplaylist_resultr   	functoolspartialrZ   
_PAGE_SIZE)r*   r#   rX   Z
season_numZseason_titler+   r+   r,   rJ      s    
 zDropoutSeasonIE._real_extractN)rK   rL   rM   ra   rN   rO   rZ   rJ   r+   r+   r+   r,   rP      sB   


'rP   )r_   commonr   Zvimeor   utilsr   r   r   r	   r
   r   r   r   r   r   r   r   rP   r+   r+   r+   r,   <module>   s   4 