U
    g.                     @   s   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 G dd deZG d	d
 d
eZdS )    N   )InfoExtractor   )HEADRequest)ExtractorErrorOnDemandPagedList
clean_htmlextract_attributesget_element_by_classget_element_by_idget_element_html_by_classget_elements_html_by_classint_or_none
orderedSetparse_countparse_durationtraverse_objunified_strdateurlencode_postdataurljoinc                   @   s   e Zd ZdZde 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d d
dd!dddd"d#d$id%d&d'dd(d)d*d+id,d-d.d+d/d0d+d/d1d+d/gZd2Zd3d4d5Zd6d7 Zd8d9 Z	e
d:d; Zd<d= Zd$S )>
BitChuteIEzWhttps?://(?:(?:www|old)\.)?bitchute\.com/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)z,<(?:script|iframe)[^>]+\bsrc=(["\'])(?P<url>)z+https://www.bitchute.com/video/UGlrF9o9b-Q/ 7e427d7ed7af5a75b5855705ec750e2bUGlrF9o9b-Qmp4&This is the first video on #BitChute !$md5:a0337e7b1fe39e32336974af8173a034re:^https?://.*\.jpg$BitChute20170103.https://www.bitchute.com/profile/I5NgtHZn9vPj/*https://www.bitchute.com/channel/bitchute/)
idexttitledescription	thumbnailuploaderupload_dateuploader_urlchannelchannel_url)urlmd5	info_dictz+https://www.bitchute.com/video/Yti_j9A-UZ4/Z f10e6a8e787766235946d0868703f1d0zYti_j9A-UZ4zIsrael at War | Full Measurez$md5:38cf7bc6f42da1a877835539111c69efZsharylattkissonZ20231106z.https://www.bitchute.com/profile/9K0kUWA9zmd9/z"Full Measure with Sharyl Attkissonz1https://www.bitchute.com/channel/sharylattkisson/z,https://www.bitchute.com/video/2s6B3nZjAk7R/Z 05c12397d5354bf24494885b08d24ed1Z2s6B3nZjAk7RiCzMSTYXHEXENHAMMER666 - Election Fraud, Clinton 2020, EU Armies, and Gun Controlz$md5:228ee93bd840a24938f536aeac9cf749Z20181113)r"   r#   filesizer$   r%   r&   r'   r(   r)   r*   r+   check_formatsN)r,   r-   r.   paramsz,https://www.bitchute.com/video/WEnQU7XGcTdl/ZWEnQU7XGcTdlz4Impartial Truth - Ein Letzter Appell an die Vernunft)r"   r#   r$   skip_downloadTzGeorestricted in DE)r,   r.   r1   skipz+https://www.bitchute.com/embed/lbb5G1hjPhw/r,   Zonly_matchingzDhttps://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrentz+https://old.bitchute.com/video/UGlrF9o9b-Q/FzxMozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.57 Safari/537.36zhttps://www.bitchute.com/)z
User-AgentRefererc                    s   t  fdddD }|D ]}z"| jt||d| | jd}W n@ tk
r } z"| | d|j  W Y qW 5 d }~X Y nX |t|j	dd  S d S )	Nc                 3   s"   | ]}t d d|  V  qdS )z((^https?://)(seed\d+)(?=\.bitchute\.com)z\g<1>N)resub).0host	video_url =/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/bitchute.py	<genexpr>j   s   z+BitChuteIE._check_format.<locals>.<genexpr>)z\g<2>Zseed122Zseed125Zseed126Zseed128Zseed132Zseed150Zseed151Zseed152Zseed153Zseed167Zseed171Zseed177Zseed305Zseed307Z	seedp29xbzzb10-7gsop1v78z	Checking )video_idZnoteheadersz: URL is invalid, skipping: zContent-Length)r,   r/   )
r   Z_request_webpager   _HEADERSr   Z	to_screencauser   r@   get)selfr;   r?   urlsr,   responseer<   r:   r=   _check_formati   s"       
zBitChuteIE._check_formatc                 C   s>   t td|pd}td|r:t td|p.|}| | d S )Nz
page-title z(?:Channel|Video) Restrictedzpage-detail)r   r
   r6   	fullmatchr   Zraise_geo_restricted)rD   webpageZ
page_titlereasonr<   r<   r=   _raise_if_restricted|   s    zBitChuteIE._raise_if_restrictedc                 C   s"   t td| pdd}td|S )NZsparI   hrefzhttps://www.bitchute.com)r	   r   rC   r   )htmlpathr<   r<   r=   	_make_url   s    zBitChuteIE._make_urlc                 C   s8  |  |}| jd| || jd}| | ttd|}| |||}g }t|dD ]B}| ddk	r|	| 
|d|pi  d|krqV|| qV|s| jdd	|d
 td|pd}td|pd}	td|pd}
|| |p| || j|d d| |t|	| |	t|
| |
t| jd|ddd|d
S )Nzhttps://old.bitchute.com/video/)r@   zvideo-publish-date)r   formats.r0   Fr,   ziVideo is unavailable. Please make sure this video is playable in the browser before reporting this issue.T)expectedr?   detailsrI   Zcreatornamedefaultzat \d+:\d+ UTC on (.+?)\.zupload date)fatal)
r"   r$   r%   r&   r'   r)   r*   r+   r(   rR   )Z	_match_id_download_webpagerA   rM   r   r
   Z_parse_html5_media_entriesr   	get_paramupdaterH   popappendZraise_no_formatsr   _html_extract_titleZ_og_search_titleZ_og_search_descriptionZ_og_search_thumbnailrQ   r   _search_regex)rD   r,   r?   rK   Zpublish_dateentriesrR   Zformat_rT   Zuploader_htmlZchannel_htmlr<   r<   r=   _real_extract   sR    
  
    zBitChuteIE._real_extract)__name__
__module____qualname__
_VALID_URLZ_EMBED_REGEX_TESTSZ_GEO_BYPASSrA   rH   rM   staticmethodrQ   ra   r<   r<   r<   r=   r      s   E
r   c                   @   s   e Zd ZdZdddddddd	d
ddddddddeddgddddddddddddddgZdZdZd d!d"d#d$d%d&d#d'Ze	d(d) Z
d*d+ Zd,d- Zd.S )/BitChuteChannelIEzThttps?://(?:(?:www|old)\.)?bitchute\.com/(?P<type>channel|playlist)/(?P<id>[^/?#&]+)r!   Zbitchuter   z$md5:2134c37d64fc3a4846787c402956adac)r"   r$   r%   r   r   r   r   r   r   r   r       )r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   duration
view_count)r-   r.   Tz-1)r2   Zplaylist_items)r,   r.   playlistr1   z/https://www.bitchute.com/playlist/wV9Imujxasw9/   ZwV9Imujxasw9z+Bruce MacDonald and "The Light of Darkness"z$md5:747724ef404eebdfc04277714f81863e)r,   Zplaylist_mincountr.   z/https://old.bitchute.com/playlist/wV9Imujxasw9/r4   Z@zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7   zchannel-videos-containerzchannel-videos-titlezchannel-videos-text)	containerr$   r%   zplaylist-videor$   r%   )r*   rl   c                 C   s   d| d|  dS )Nzhttps://old.bitchute.com//r<   )playlist_idplaylist_typer<   r<   r=   rQ      s    zBitChuteChannelIE._make_urlc           	      c   s   |  ||}| j| d|d| t| jd|| j dd|dd| j dd	}|d
s`d S | j| }t|d |dD ]r}| jd|dd d}|sq~| j	d| t
|dtt|d |tt|d |ttd|tttd|dV  q~d S )Nzextend/zDownloading page rI   )ZcsrfmiddlewaretokenrU   offsetz0application/x-www-form-urlencoded; charset=UTF-8ZXMLHttpRequestz
csrftoken=)zContent-Typer5   zX-Requested-WithCookie)datar@   successro   rO   z&<a\s[^>]*\bhref=["\']/video/([^"\'/]+)zvideo idrV   zhttps://www.bitchute.com/video/Tr$   r%   zvideo-durationzvideo-views)Zurl_transparentr$   r%   rj   rk   )rQ   Z_download_jsonr   _TOKEN	PAGE_SIZErC   HTML_CLASS_NAMESr   r_   Z
url_resultr   r   r
   r   r   )	rD   rq   rr   Zpage_numZplaylist_urlru   classesZ
video_htmlr?   r<   r<   r=   _fetch_page   sL      


      zBitChuteChannelIE._fetch_pagec                 C   s~   |  |dd\}}| | |||}t| j||}| jt|| j	|| j
|d d| jd|d dt| jd|dd ddS )Ntyper"   rV   )r%   zog:descriptionztwitter:descriptionz<span>(\d+)\s+videos?</span>zplaylist count)r$   r%   Zplaylist_count)Z_match_valid_urlgrouprY   rQ   	functoolspartialr{   Zplaylist_resultr   rx   r^   Z_html_search_metar   Z_html_search_regex)rD   r,   rr   rq   rK   Z	page_funcr<   r<   r=   ra     s&    
      zBitChuteChannelIE._real_extractN)rb   rc   rd   re   intrf   rw   rx   ry   rg   rQ   r{   ra   r<   r<   r<   r=   rh      sh   	+
rh   )r~   r6   commonr   Z
networkingr   utilsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   rh   r<   r<   r<   r=   <module>   s   H 