
    VGhp^                         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  G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N   )InfoExtractor   )	HTTPError)ExtractorErrorOnDemandPagedListage_restricted
clean_htmlextract_attributesint_or_nonetraverse_objtry_getunescapeHTMLunsmuggle_url
update_urlurl_or_noneurlencode_postdatac                   N    e Zd ZdZdddZdZd Zed        Zd Z	d	 Z
d
 ZddZy)DailymotionBaseInfoExtractorNzapplication/jsonzhttps://www.dailymotion.com)zContent-TypeOrigindailymotionc                 $    | j                  d      S )Nzhttps://www.dailymotion.com/)_get_cookies)selfs    e/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/dailymotion.py_get_dailymotion_cookiesz5DailymotionBaseInfoExtractor._get_dailymotion_cookies!   s      !?@@    c                 B    | j                  |      }|r|j                  S y N)getvalue)cookiesnamecookies      r   _get_cookie_valuez.DailymotionBaseInfoExtractor._get_cookie_value$   s"    T"<< r   c                 *    | j                  d||       y )Nzwww.dailymotion.com)_set_cookie)r   r#   r!   s      r   _set_dailymotion_cookiez4DailymotionBaseInfoExtractor._set_dailymotion_cookie*   s    .e<r   c                     | j                         }| j                  |d      }|r|dk(  nt        d| j                  d            | _        | j                  d| j                  rd       y d       y )Nffon   	age_limitoff)r   r%   r	   	get_param_FAMILY_FILTERr(   )r   r"   r*   s      r   _real_initializez-DailymotionBaseInfoExtractor._real_initialize-   s`    //1##GT2,.bDjN2t~~VaGb4c$$T43F3F4RERr   c                 ~   | j                         }| j                  |d      xs | j                  |d      }|r|S ddd}| j                         \  }}|r|j                  d||d       nd|d	<   	 | j	                  d
d dt        |            d   }| j                  |rdnd|       |S # t        $ r}t        |j                  t              ri|j                  j                  dk(  rPt        | j                  |j                  j                  j                         j                         |      d   d       d }~ww xY w)Naccess_tokenclient_tokenf1a362d288c1b98099c7(eea605b96e01c796ff369935357eca920c5da4c5)	client_idclient_secretpassword)
grant_typer9   usernameclient_credentialsr:   z/https://graphql.api.dailymotion.com/oauth/tokenzDownloading Access Token)datai  error_descriptionTexpected)r   r%   _get_login_infoupdate_download_jsonr   r   
isinstancecauser   status_parse_jsonresponsereaddecoder(   )r   xidr"   tokenr=   r;   r9   es           r   
_get_tokenz'DailymotionBaseInfoExtractor._get_token3   sW   //1&&w?r4CYCYZacqCrL 0G
 "113(KK($$  "6D		''A0'- ( / 0>?E 	$$x^^UZ[  	!''9-!''..C2G$T%5%5GG$$))+224c&;;N&PZ^` `		s   1!B* *	D<3BD77D<c                 l   | j                   j                  d      s!d| j                  |       | j                   d<   | j                  d||t	        j
                  dd|d|d|rd|z   nd	d
|d	i      j                         | j                         }|d   |   }|st        |d   d   d   d      |S )NAuthorizationBearer $https://graphql.api.dailymotion.com/queryz{
  z(xid: ""z,  z) {
    z
  }
}r=   headersr=   errorsr   messageTr?   )_HEADERSr    rN   rC   jsondumpsencoder   )r   object_typerK   object_fieldsnotefilter_extrarespobjs           r   	_call_apiz&DailymotionBaseInfoExtractor._call_apiS   s    }}  1/6ts7K6L-MDMM/*""2CDJJ 	S$-2E}	VP E vx # 0 6l;' h!29!=MM
r   r   )__name__
__module____qualname__r0   rZ   _NETRC_MACHINEr   staticmethodr%   r(   r1   rN   rd    r   r   r   r      sK    N*/H #NA    
=S@r   r   c                   $    e Zd ZdZdZdedd  dgZddd	d
ddddddddeeg dddddddd
ddddddd deed!gd"ddd#d$d%d
d&d'd(d)d*d+d,d-ded.d/d0d1d2d3d
d4d5d6d7d8id9d:d;d<d=d
d>d?d@dAd/d0dBd8dCdDd8dCdEd8dCdFd8dCdGd8dCdHd8dCdId8dCdJd8dCdKd8dCdLd8dCdMd8dCdNd8dCdOd8dCdPd8dCgZdQdRd
dSdTdUdVdWdXdYdg eedZd[d\d]d^d_id`dadbdcd
edddedfedgddhdidjdkg dldmd\dndod
edpdqdredsddtdudvdwg dmd\dxdyd
dzd{d|d}eedd~dg dddd\gZdZ	dZ
e fd       Zd Z xZS )DailymotionIEa  (?ix)
                    (?:https?:)?//
                    (?:
                        dai\.ly/|
                        (?:
                            (?:(?:www|touch|geo)\.)?dailymotion\.[a-z]{2,3}|
                            (?:www\.)?lequipe\.fr
                        )/
                        (?:
                            swf/(?!video)|
                            (?:(?:crawler|embed|swf)/)?video/|
                            player(?:/[\da-z]+)?\.html\?(?:video|(?P<is_playlist>playlist))=
                        )
                    )
                    (?P<id>[^/?_&#]+)(?:[\w-]*\?playlist=(?P<playlist_id>x[0-9a-z]+))?
    r   zl(?ix)<(?:(?:embed|iframe)[^>]+?src=|input[^>]+id=[\'"]dmcloudUrlEmissionSelect[\'"][^>]+value=)["\'](?P<url>   N)zphttp://www.dailymotion.com/video/x5kesuj_office-christmas-party-review-jason-bateman-olivia-munn-t-j-miller_news 074b95bdee76b9e3654137aee9c79dfex5kesujmp4uJ   Office Christmas Party Review –  Jason Bateman, Olivia Munn, T.J. MillerzGOffice Christmas Party Review - Jason Bateman, Olivia Munn, T.J. Miller   iUOY20170501Deadlinex1xm8rir   )	hollywoodceleb	celebritymoviesz
red carpetz:re:https://(?:s[12]\.)dmcdn\.net/v/K456B1cmt4ZcZ9KiM/x1080)idexttitledescriptionduration	timestampupload_dateuploaderuploader_idr-   
view_count
like_counttags	thumbnail)urlmd5	info_dictz?https://geo.dailymotion.com/player.html?video=x89eyek&mute=true e2f9717c6604773f963f069ca53a07f8x89eyeku    En quête d'esprit du 27/03/2022z$md5:66542b9f4df2eb23f314fc097488e553i
  iV@b20220327CNEWSx24vthen_quete_d_espritz:re:https://(?:s[12]\.)dmcdn\.net/v/Tncwi1clTH6StrxMP/x1080zphttps://www.dailymotion.com/video/x2iuewm_steam-machine-models-pricing-listed-on-steam-store-ign-news_videogames 2137c41a8e78554bb09225b8eb322406x2iuewmz>Steam Machine Models, Pricing Listed on Steam Store - IGN Newsz/Several come bundled with the Steam Controller.zre:^https?:.*\.(?:jpg|png)$J   iT20150306IGNxijv66)rz   r{   r|   r}   r   r~   r   r   r   r   r-   r   z
video gone)r   r   r   skipzFhttp://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musizRoar (Official)USUV71301934z
Katy Perry20130905)r|   rz   r{   r   r   skip_downloadTz(VEVO is only available in some countries)r   r   paramsr   znhttp://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband 0d667a7b9cebecc3c89ee93099c4159dxyh2zzzBLeanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]HotWaves1012r,   )rz   r{   r|   r   r-   z'http://www.dailymotion.com/video/xhza0o)r   only_matchingzqhttp://www.dailymotion.com/video/x20su5f_the-power-of-nightmares-1-the-rise-of-the-politics-of-fear-bbc-2004_newsz,http://www.dailymotion.com/swf/video/x3n92nfzLhttp://www.dailymotion.com/swf/x3ss1m_funny-magic-trick-barry-and-stuart_funz$https://www.lequipe.fr/video/x791memz0https://www.lequipe.fr/video/k7MtHciueyTcrFtFKA2z7https://www.dailymotion.com/video/x3z49k?playlist=xv4bwzGhttps://geo.dailymotion.com/player/x86gw.html?video=k46oCapRs4iikoz9DWyzhttps://geo.dailymotion.com/player/xakln.html?video=x8mjju4&customConfig%5BcustomParams%5D=%2Ffr-fr%2Ftennis%2Fwimbledon-mens-singles%2Farticles-videoz=https://geo.dailymotion.com/player/xf7zn.html?playlist=x7wdsjz;https://geo.dailymotion.com/player/xmyye.html?video=x93blhiz1https://www.dailymotion.com/crawler/video/x8u4owgz/https://www.dailymotion.com/embed/video/x8u4owgzhttps://dai.ly/x94cnnkzhttps://www.financialounge.com/video/2024/08/01/borse-europee-in-rosso-dopo-la-fed-a-milano-volano-mediobanca-e-tim-edizione-del-1-agosto/x93blhizOnAir - 01/08/24rU      iYf20240801Financialoungex2vtgmmz2re:https://\w+.dmcdn.net/v/WnEY61cmvMxt2Fi6d/x1080)rz   r{   r|   r}   r~   r   r   r   r   r-   r   r   r   r   )r   r   zNhttps://www.cycleworld.com/blogs/ask-kevin/ducati-continues-to-evolve-with-v4/rz   x7wdsj2   r   r   playlist_mincountzhttps://www.leparisien.fr/environnement/video-le-veloto-la-voiture-a-pedales-qui-aimerait-se-faire-une-place-sur-les-routes-09-03-2024-KCYMCPM4WFHJXMSKBUI66UNFPU.phpx8u4owgzLe Parisienzhttps://www.leparisien.fr/resizer/ho_GwveeYftNkLwg_cEta--5Bv4=/1200x675/cloudfront-eu-central-1.images.arcpublishing.com/leparisien/BFXJNEBN75EUNHGYJLORUC3TX4.jpg20240309i*ex32f7bua   VIDÉO. Le « véloto », la voiture à pédales qui aimerait se faire une place sur les routesg     z@uH   À bord du « véloto », l’alternative à la voiture pour la campagne)biclouu   vélou   vélotocampagnevoitureenvironnementu   véhicules intermédiaires)rz   r{   r   r   r   r   r   r   r-   r   r|   r~   r}   r   zNhttps://www.metatube.com/en/videos/546765/This-frogs-decorates-Christmas-tree/x8vu47wMetatubez2re:https://\w+.dmcdn.net/v/W1G_S1coGSFTfkTeR/x108020240326i^fx2xpy74u&   Está lindas ranitas ponen su arbolito   zQue lindurazbhttps://lcp.fr/programmes/avant-la-catastrophe-la-naissance-de-la-dictature-nazie-1933-1936-346819k2Y4Mjp7krAF9iCuINMzBAvant la catastrophe la naissance de la dictature nazie 1933 -1936z$md5:7b620d5e26edbe45f27bbddc1c0257c1u   LCP Assemblée nationalexbz33di  z.https://s1.dmcdn.net/v/Xvumk1djJBUZfjj2a/x1080iKg20250218)rz   r{   r|   r}   r   r   r   r   r-   r~   r   r   r   r   FzIdescription
      geoblockedCountries {
        allowed
      }
      xidc              #     K   t         	|   ||      E d {    t        j                  d|      D ]  }d|j	                  d      z     t        j                  d|      D ]  }t        |j	                  d            }t        |j                  d            }|s:|j                  dd      }|j                  d	      rd
| }|j                  d      x}rd| }n|j                  d      x}rd| }nt        ||        y 7 w)NzS(?s)DM\.player\([^,]+,\s*{.*?video[\'"]?\s*:\s*["\']?(?P<id>[0-9a-zA-Z]+).+?}\s*\);z(https://www.dailymotion.com/embed/video/rz   z`(?s)<script [^>]*\bsrc=(["\'])(?:https?:)?//[\w-]+\.dailymotion\.com/player/(?:(?!\1).)+\1[^>]*>r   srcz.jsz.htmlz//zhttps:z
data-videozvideo=zdata-playlistz	playlist=rS   )super_extract_embed_urlsrefinditergroupr   r   r    replace
startswithr   )
clsr   webpagemobjattrs
player_urlvideo_idquery_stringplaylist_id	__class__s
            r   r   z!DailymotionIE._extract_embed_urlsR  s      7.sG<<<KKfhoq 	PD<tzz$?OOO	P KKsu|~ 	=D&tzz!}5E$UYYu%56J#++E7;J$$T*%j\2
 99\22x2!'z2 %		/ :::!*;-8Z|<<	=	 	=s   DD
C3Dc                   " t        |      \  }}| j                  |      j                  ddd      \  }}}|r|}d }| j                  ||      r| j	                  d| d|      S | j                  d      }| j                  d|d| j                  d	| j                  d
d|r dj                  | j                  d            nd       }|d   }| j                  d|z   |dt        |d      xs ddi      }	|	j                  d      }
|
rm|
j                  d      xs |
d   }|
j                  d      dk(  r%t        |d t              }| j                  ||       t        | j                    d| d      |	d   }|j                  d      }g }i }|	d   j#                         D ]  \  }}|D ]  }|j                  d       }|j                  d!      }|r|d"k(  r-|d#k(  r?| j%                  ||d$|d%d&'      \  }}|j'                  |       | j)                  ||(       q|d)|z   d*}t+        j,                  d+|      }|r7t/        t0        |j3                               \  }}}|j5                  |||d,       |j7                  |         |D ]H  }|d    j9                  d-      d.   |d <   |j                  d/      r/|d0   j;                  d1      sDd2|d/<   J t        |	d3 t<              xs i }|j#                         D ]*  \  }}|j                  d4g       D cg c]  }d |i c}||<   , t        |	d5t<        j"                  hd6 d.t0        hfd.t>        hfd7d8f      }|	j                  d9      xs i } |j                  d:      xs i ""fd;}!||tA        |j                  d<            |t1        |	j                  d=            xs d t1        |	j                  d>            | j                  d?      | j                  d      xs |	j                  d?      |	j                  d@      rdAnd.|	j                  dB       |!dC      xs t1        |j                  dD             |!dE      |||dFS c c}w )GNrz   is_playlistr   z$http://www.dailymotion.com/playlist/DailymotionPlaylistvideopasswordmediaz... on Video {
      z
      stats {
        likes {
          total
        }
        views {
          total
        }
      }
    }
    ... on Live {
      z(
      audienceCount
      isOnAir
    }zDownloading media JSON metadatazpassword: "{}"rK   z2https://www.dailymotion.com/player/metadata/video/zDownloading metadata JSONrS   appzcom.dailymotion.neonr   errorr|   raw_messagecodeDM007c                     | d   d   S )NgeoblockedCountriesallowedrj   xs    r   <lambda>z-DailymotionIE._real_extract.<locals>.<lambda>  s    Q?T=UV_=` r   )msg	countriesz said: Tr?   isOnAir	qualitiesr   typez#application/vnd.lumberjack.manifestzapplication/x-mpegURLrq   hlsF)livem3u8_idfatal)targetzhttp-)r   	format_idz/H264-(\d+)x(\d+)(?:-(60)/)?)fpsheightwidth#r   r   r   z@60<   c                     | d   d   S )N	subtitlesr=   rj   r   s    r   r   z-DailymotionIE._real_extract.<locals>.<lambda>  s    Q{^F5K r   urls)posters
thumbnailsc                     t        |d         S )Nr   )r   )_vs     r   r   z-DailymotionIE._real_extract.<locals>.<lambda>  s    +aPQdBS r   r   )r   rz   r   ownerstatsc                 6     t        t         fd            S )Nc                     | dz      d   S )Nstotalrj   )yr   s    r   r   z?DailymotionIE._real_extract.<locals>.<lambda>.<locals>.<lambda>  s    1QW:gCV r   )r   r   )r   r   s   `r   r   z-DailymotionIE._real_extract.<locals>.<lambda>  s    k'%9V*WX r   r}   r~   created_time
screennameexplicitr,   r   viewaudienceCountlike)rz   r|   r}   r   r~   r   r   r   r-   r   r   r   formatsr   is_live)!r   _match_valid_urlr   _yes_playlist
url_resultr/   rd   _COMMON_MEDIA_FIELDSformatrC   r   r    r   listraise_geo_restrictedr   IE_NAMEitems#_extract_m3u8_formats_and_subtitlesextend_merge_subtitlesr   searchmapr   groupsrB   appendsplitendswithdictstrr
   )#r   r   smuggled_datar   r   r   r9   r   rK   metadatar   r|   allowed_countriesr   r   r   quality
media_listm	media_url
media_typefmtsubsfr   r   r   subtitles_datasubtitle_langsubtitlesubtitle_urlr   r   	get_countr   s#                                     @r   _real_extractzDailymotionIE._real_extractj  s   *3/]-1-B-B3-G-M-MdTacp-q*+{"KHk84??6{mD%{4 4 >>/2X %%t'@'@ B DeHP##DNN?$CDVZ#\$ El&&@3F,}g6Y5BX:Y ' [
 W%IIg&>%*>Eyy G+$+E3`bf$g!))e?P)Q <<.w/$@ @ !))I&	#+K#8#>#>#@ 	&GZ &EE%L	UU6]
 J2W$W!88 $ H H!8U%W\ !I !^ICNN3'))$y)A  )%,w%6A 		"A9MA-0ahhj-I*vs#&&,%*" 
 NN1%/&	&2  	Ax~~c*1-AeH55<AkN$;$;E$B%	
 !+KTRXVX'5';';'= 	<#M8 #+,,vr":(< |) (<Im$	<
 "(%

|5S{m,3%jV- 
 W%+		'"(bX	 %eii&>?$#HLL$<=E$X\\.%AB		,/ 99T?Hhll<.H'||J7QLL(#F+V{599_;U/V#F+"
 	
(<s   Q )re   rf   rg   
_VALID_URLr  _EMBED_REGEXint_TESTS_WEBPAGE_TESTS_GEO_BYPASSr  classmethodr   r%  __classcell__)r   s   @r   rl   rl   e   sa   J  G D  EO  PQ  PR  ES  DT  TU  V  WL B1ad#%"$OV
( Q17A#%#()V
( B1UL7#%#
 #( X& $%
 T
 ;  @1Y&
  9 C
 > ^ 6 B I Y h O M C A (w~FB \'#%($N
* `(
   w% ~%##|ex
* `"N%#$=(
* t'YA2#I#%
ASNh K = =.u
r   rl   c                       e Zd ZdZd Zd Zy)DailymotionPlaylistBaseIEd   c              #     K   |dz  }| j                  | j                  |d| j                  rdnd| j                  |fz  d|       d   }|d   D ]4  }|d   }| j	                  |d	   t
        j                         |d
          6 y w)Nr   zvideos(allowExplicit: %s, first: %d, page: %d) {
      edges {
        node {
          xid
          url
        }
      }
    }falsetruezDownloading page videosedgesnoder   rK   )rd   _OBJECT_TYPEr0   
_PAGE_SIZEr  rl   ie_key)r   r   pager4  edger6  s         r   _fetch_pagez%DailymotionPlaylistBaseIE._fetch_page  s     	{	 **GNO  v&
( )1
2 7O 	BD<D//U]113T%[B B	Bs   BBc                     | j                  |      }t        t        j                  | j                  |      | j
                        }| j                  ||      S r   )	_match_idr   	functoolspartialr<  r8  playlist_result)r   r   r   entriess       r   r%  z'DailymotionPlaylistBaseIE._real_extract  sQ    nnS)#I$5$5k%+,0OO=##[" 	"r   N)re   rf   rg   r8  r<  r%  rj   r   r   r/  r/    s    JB$"r   r/  c                   :    e Zd ZdZdZdddiddgZdZed	        Zy
)DailymotionPlaylistIEzdailymotion:playlistzK(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>x[0-9a-z]+)zChttp://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3qrz   xv4bw   r   
collectionc           	   #      K   t        j                  d|      D ]<  }t        j                  dt        |j	                  d                  D ]	  }d|   > y w)Nzf<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.[a-z]{2,3}/widget/jukebox\?.+?)\1zlist\[\]=/playlist/([^/]+)/r   z//dailymotion.com/playlist/)r   r   findallr   r   )r   r   r   r   ps        r   r   z)DailymotionPlaylistIE._extract_embed_urls  s_      KKy 	8D ZZ >TZZX]M^@_` 83A3778	8s   AAN)	re   rf   rg   r  r&  r)  r7  r,  r   rj   r   r   rD  rD    sC    $G_JT'
   F  L8 8r   rD  c                   B    e Zd ZdZdZdZddddddgZd	Zd
 Zd Z	d Z
y)DailymotionSearchIEzdailymotion:searchzHhttps?://(?:www\.)?dailymotion\.[a-z]{2,3}/search/(?P<id>[^/?#]+)/videosrF  z8http://www.dailymotion.com/search/king of turtles/videoszking of turtles)rz   r|   Z   r   zquery SEARCH_QUERY( $query: String! $page: Int $limit: Int ) { search { videos( query: $query first: $limit page: $page ) { edges { node { xid } } } } } c                    | j                   j                  d      s!d| j                  |       | j                   d<   | j                  dd |t	        j
                  d| j                  d||dd      j                         | j                         }t        |d	d
t        hf      }|s"t        t        |dddt        hf      xs d      |S )NrP   rQ   rR   SEARCH_QUERYrF  )limitr:  rS   )operationNamerS   	variablesrV   r=   r  rX   r   rY   zCould not fetch search data)rZ   r    rN   rC   r[   r\   _SEARCH_QUERYr]   r   r  r   r  )r   termr:  r`   rb   rc   s         r   _call_search_apiz$DailymotionSearchIE._call_search_api#  s    }}  1/6tt7L6M-NDMM/*""2D$TZZ!/++ !Q F vx # 	0 4&(TF!;< THaSE#BCdGdf f 
r   c              #      K   |dz  }| j                  ||d| d|       }t        |d      D ]  }| j                  d| t        |         y w)Nr   zSearching "z" page )r4  r5  .r6  rK   z"https://www.dailymotion.com/video/)rU  r   r  rl   )r   rT  r:  rH   rK   s        r   r<  zDailymotionSearchIE._fetch_page7  sf     	((t{4&PTv5VW*QR 	bC//$Fse"Lm]`aa	bs   AAc                     t         j                  j                  | j                  |            }| j	                  t        t        j                  | j                  |      | j                        ||      S r   )
urllibparseunquote_plusr>  rA  r   r?  r@  r<  r8  )r   r   rT  s      r   r%  z!DailymotionSearchIE._real_extract=  s[    ||(()<=##i//0@0@$GY[_aeg 	gr   N)re   rf   rg   r  r&  r8  r)  rS  rU  r<  r%  rj   r   r   rL  rL    sI    "G\JJI#&
   F pM(bgr   rL  c                   N    e Zd ZdZdZdddiddddd	id
dddddidddidgZdZy)DailymotionUserIEzdailymotion:userzhttps?://(?:www\.)?dailymotion\.[a-z]{2,3}/(?!(?:embed|swf|#|video|playlist|search|crawler)/)(?:(?:old/)?user/)?(?P<id>[^/?#]+)z%https://www.dailymotion.com/user/nqtvrz   nqtv   r   z,http://www.dailymotion.com/user/UnderProjectUnderProjecti  zTakes too long time)r   r   r   r      r-   r   )r   r   r   r   channelN)re   rf   rg   r  r&  r)  r7  rj   r   r   r\  r\  C  ss     G TJ6&
 ! >.
 "% 7&
 !
	F. Lr   r\  )r?  r[   r   urllib.parserX  commonr   networking.exceptionsr   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rl   r/  rD  rL  r\  rj   r   r   <module>rf     s      	  ! -   "I= IXz
0 z
z" < ":85 8,+g3 +g\1 r   