a
    hj5                     @   s   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 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 ddlmZ G d	d
 d
eZG dd deZdS )    N   )InfoExtractor   )HEADRequest)	HTTPError)ExtractorErrorOnDemandPagedList
clean_htmldetermine_extformat_fieldget_element_by_classget_elements_html_by_classint_or_none
orderedSetparse_countparse_durationparse_iso8601url_or_noneurlencode_postdataurljoin)traverse_objc                   @   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eddddddddddd
ddddddd ed!d"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/id0d1d2d3d4d2d3d5d2d3gZd6Zd7Zd8Z	d9d: Z
d?d;d<Zd=d> Zd/S )@
BitChuteIEzYhttps?://(?:(?: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/I5NgtHZn9vPj1VBwRfyNcKdXg      0@FkX)idexttitledescription	thumbnailuploaderupload_dateuploader_urlchannelchannel_urluploader_id
channel_id
view_countduration	timestamp)urlmd5	info_dictz+https://www.bitchute.com/video/Yti_j9A-UZ4/Z f10e6a8e787766235946d0868703f1d0zYti_j9A-UZ4zIsrael at War | Full Measurez$md5:e60198b89971966d6030d22b3268f08fZsharylattkissonZ20231106z.https://www.bitchute.com/profile/9K0kUWA9zmd9/z"Full Measure with Sharyl Attkissonz1https://www.bitchute.com/channel/sharylattkisson/Z9K0kUWA9zmd9ZNpdxoCRv3ZLbg     P@ij3Iez,https://www.bitchute.com/video/2s6B3nZjAk7R/Z 05c12397d5354bf24494885b08d24ed1Z2s6B3nZjAk7RiCzMSTYXHEXENHAMMER666 - Election Fraud, Clinton 2020, EU Armies, and Gun Controlz$md5:2029c7c212ccd4b040f52bb2d036ef4eZ20181113g     @bitchuteio
[)r&   r'   filesizer(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   tagsr4   check_formatsN)r5   r6   r7   paramsz+https://www.bitchute.com/embed/lbb5G1hjPhw/Tr5   Zonly_matchingzDhttps://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrentz+https://old.bitchute.com/video/UGlrF9o9b-Q/Fz$https://www.bitchute.com/profile/%s/z$https://www.bitchute.com/channel/%s/c                    s   t  fdddD }|D ]}z| jt||d| d}W nF ty } z.| | d|j  W Y d }~qW Y d }~n
d }~0 0 |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 N/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/extractor/bitchute.py	<genexpr>o   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_idnotez: URL is invalid, skipping: zContent-Length)r5   r9   )	r   Z_request_webpager   r   Z	to_screencauser   headersget)selfrC   rG   urlsr5   responseerD   rB   rE   _check_formatn   s    
"zBitChuteIE._check_formatc                 C   s   | dd }z>| jd| |d| dd| dt| dddd	W S  ty } z|t|jtr|jj	d
krd
t|jj  tjhddd dthf}|rd|v r| | |r | |j W Y d }~n
d }~0 0 d S )N/r   z"https://api.bitchute.com/api/beta/zDownloading z	 API JSONzUnable to download zapplication/json)AcceptContent-TypedatarJ   i  z. errorsc                 S   s   |d dkS )NcontextreasonrD   )_vrD   rD   rE   <lambda>       z&BitChuteIE._call_api.<locals>.<lambda>messagelocation)
rpartition_download_jsonjsondumpsencoder   
isinstancerI   r   statusjoinr   rN   readdecodeloadsstrZraise_geo_restrictedZreport_warningmsg)rL   ZendpointrU   Z
display_idfatalrH   rO   rV   rD   rD   rE   	_call_api   s(    

zBitChuteIE._call_apic           
      C   s  |  |}d|i}| d||d }g }t|dkrP|| j||dddd n8| d	d
urz| || }r|| n|d|i |s| jdd|d | jd||d
d}d }t	|ddt
hf }	r| jdd|	i|d
d}i t	|dt
hfdt
hfdthfddt
hfddt
hfddtdhfdt
hfdt| jdhtfdthfdthfddt
htttfdthfdd d! hfd"t	|dt
hfdt
hfd#t| jdhtfd$t
hfdt
hfdt| jdhtfd%||d&S )'NrG   zvideo/media	media_urlZm3u8r   ZhlsT)Zm3u8_idliver;   Fr5   ziVideo is unavailable. Please make sure this video is playable in the browser before reporting this issue.)expectedrG   video)rl   r.   r1   Z
video_namer)   Zthumbnail_urlZchannel_namer/   zhttps://www.bitchute.com/Z
profile_id)templateZdate_publishedr3   Zhashtags.r2   Zstate_idc                 S   s   | dkS )Nro   rD   )xrD   rD   rE   r[      r\   z*BitChuteIE._real_extract.<locals>.<lambda>)r(   r)   r*   r.   r1   r/   r0   r-   r4   r3   r:   r2   Zis_liveZurl_slugZprofile_name)r.   r1   r/   r+   r0   r-   )r&   formats)Z	_match_idrm   r
   extendZ_extract_m3u8_formats	get_paramrP   appendZraise_no_formatsr   rj   r   r   r   _UPLOADER_URL_TMPLfilterr   r   allr   _CHANNEL_URL_TMPL)
rL   r5   rG   rU   rn   rt   fmtrq   r.   r1   rD   rD   rE   _real_extract   sd    


zBitChuteIE._real_extract)T)__name__
__module____qualname__
_VALID_URLZ_EMBED_REGEXint_TESTSZ_GEO_BYPASSrx   r{   rP   rm   r}   rD   rD   rD   rE   r      s   K
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dddgd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d0d1 Zd2S )3BitChuteChannelIEzThttps?://(?:(?:www|old)\.)?bitchute\.com/(?P<type>channel|playlist)/(?P<id>[^/?#&]+)r"   r8   r   z$md5:2134c37d64fc3a4846787c402956adac)r&   r(   r)   r   r   r   r   r   r   r    r!      r#   r$   r%   )r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r3   r2   r0   r1   r4   )r6   r7   Tz-1)Zskip_downloadZplaylist_items)r5   r7   playlistr<   z/https://www.bitchute.com/playlist/wV9Imujxasw9/   ZwV9Imujxasw9z+Bruce MacDonald and "The Light of Darkness"z$md5:747724ef404eebdfc04277714f81863ez404 Not Found)r5   Zplaylist_mincountr7   skipz/https://old.bitchute.com/playlist/wV9Imujxasw9/r=   Z@zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7   zchannel-videos-containerzchannel-videos-titlezchannel-videos-text)	containerr(   r)   zplaylist-videor(   r)   )r.   r   c                 C   s   d| d|  dS )Nzhttps://old.bitchute.com/rQ   rD   )playlist_idplaylist_typerD   rD   rE   	_make_url  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  )Zcsrfmiddlewaretokennameoffsetz0application/x-www-form-urlencoded; charset=UTF-8ZXMLHttpRequestz
csrftoken=)rS   ZRefererzX-Requested-WithCookierT   successr   htmlz&<a\s[^>]*\bhref=["\']/video/([^"\'/]+)zvideo iddefaultzhttps://www.bitchute.com/video/Tr(   r)   zvideo-durationzvideo-views)Zurl_transparentr(   r)   r3   r2   )r   r`   r   _TOKEN	PAGE_SIZErK   HTML_CLASS_NAMESr   Z_search_regexZ
url_resultr   r	   r   r   r   )	rL   r   r   Zpage_numZplaylist_urlrU   classesZ
video_htmlrG   rD   rD   rE   _fetch_page  s<    


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&   r   )r)   zog:descriptionztwitter:descriptionz<span>(\d+)\s+videos?</span>zplaylist count)r(   r)   Zplaylist_count)Z_match_valid_urlgroupZ_download_webpager   	functoolspartialr   Zplaylist_resultr   r   Z_html_extract_titleZ_html_search_metar   Z_html_search_regex)rL   r5   r   r   ZwebpageZ	page_funcrD   rD   rE   r}   0  s    zBitChuteChannelIE._real_extractN)r~   r   r   r   r   r   r   r   r   staticmethodr   r   r}   rD   rD   rD   rE   r      sp   "
/
r   )r   ra   r>   commonr   Z
networkingr   Znetworking.exceptionsr   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Zutils.traversalr   r   r   rD   rD   rD   rE   <module>   s   D 3