
    uki]                         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    W/home/cdr/jupyterlab/.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deeddddd	ddddddddddeeddd d!d"d	d#d$d%dd&d'd(d)ded*d+d,d-d.d/d	d0d1d2d3d+d,d4d5d6d7d5d6d8d5d6d9d5d6d:d5d6d;d5d6d<d5d6d=d5d6d>d5d6d?d5d6d@d5d6dAd5d6dBd5d6dCd5d6gZdDdEd	dFdGdHdIdJdKdLdg deedMddNdOdPidQdRdSdTd	dUedVdWedXdYdZdd[d\d]d^dd_d`d	edadbeddcddddedfdgg dhdidjdkdld	dmdndodpeeddqg ddrdsdtdidjdudvd	dwddxdyedddzd{d|d}ed~dgZdZ	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x5kesujmp4uJ   Office Christmas Party Review –  Jason Bateman, Olivia Munn, T.J. MillerzGOffice Christmas Party Review - Jason Bateman, Olivia Munn, T.J. Miller   zcount:5z"re:https?://s[12]\.dmcdn\.net/v/.+iUOY20170501Deadlinex1xm8rir   )idexttitledescriptiondurationtags	thumbnail	timestampupload_dateuploaderuploader_idr-   
view_count
like_count)url	info_dictz?https://geo.dailymotion.com/player.html?video=x89eyek&mute=truex89eyeku    En quête d'esprit du 27/03/2022z$md5:66542b9f4df2eb23f314fc097488e553i
  zcount:1iV@b20220327CNEWSx24vthzphttps://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.J   iT20150306IGNxijv66)ru   rv   rw   rx   ry   r{   r|   r}   r~   r   r-   r   z
video gone)r   md5r   skipznhttp://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,   )ru   rv   rw   r~   r-   z'http://www.dailymotion.com/video/xhza0oT)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x2vtgmm)ru   rv   rw   rx   ry   r|   r}   r~   r   r-   rz   r{   r   r   zNhttps://www.cycleworld.com/blogs/ask-kevin/ducati-continues-to-evolve-with-v4/ru   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x8u4owguH   À bord du « véloto », l’alternative à la voiture pour la campagnezLe Parisien20240309zcount:7z're:https?://www\.leparisien\.fr/.+\.jpgi*ex32f7bua   VIDÉO. Le « véloto », la voiture à pédales qui aimerait se faire une place sur les routesg     z@)ru   rv   rx   r   r~   r}   r   rz   r{   r|   r-   r   rw   ry   zNhttps://www.metatube.com/en/videos/546765/This-frogs-decorates-Christmas-tree/x8vu47wMetatube20240326i^fx2xpy74u&   Está lindas ranitas ponen su arbolito   zQue lindura)ru   rv   r   r~   r}   r   r{   r|   r-   r   rw   ry   rx   rz   zInvalid URL)r   r   r   zbhttps://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  iKg20250218)ru   rv   rw   rx   r~   r   r   r   r-   ry   rz   r{   r|   r}   zMhttps://forum.ionicframework.com/t/ionic-2-jw-player-dailymotion-player/83248xwr14qz2Macklemore & Ryan Lewis - Thrift Shop (feat. Wanz)z$md5:47fbe168b5a6ddc4a205e20dd6c841b2   i%P20130114zMacklemore Officialx19qlwr)ru   rv   rw   r-   rx   ry   r   rz   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/ru   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_urlsV  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 )GNru   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   errorrw   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-mpegURLrp   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   ru   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   rx   ry   created_time
screennameexplicitr,   rz   viewaudienceCountlike)ru   rw   rx   r   ry   r|   r~   r   r-   rz   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   rw   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_extractn  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   si   J  G D  EO  PQ  PR  ES  DT  TU  V  WL Bad>#%"$
& Q8A>#%#
& B1UL>#%#
 #( @1Y&
  9 C
 > ^ 6 B I Y h O M C A (WnFb \'#%($>
* `(
   we%%C##|
* `"%>#$=(
  ', t'YA2#>#%
  '* _IA>#%-$
kgNP 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   pager)  edger+  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partialr1  r-  playlist_result)r   r   r   entriess       r   r  z'DailymotionPlaylistBaseIE._real_extract  sQ    nnS)#I$5$5k%+,0OO=##[" 	"r   N)re   rf   rg   r-  r1  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=xl8v3qru   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  r,  r!  r   rj   r   r   r9  r9    sC    $G_JT'
   F  L8 8r   r9  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>[^/?#]+)/videosr;  z8http://www.dailymotion.com/search/king of turtles/videoszking of turtles)ru   rw   r   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_QUERYr;  )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 )r)  r*  .r+  rK   z"https://www.dailymotion.com/video/)rI  r   r   rl   )r   rH  r/  rH   rK   s        r   r1  zDailymotionSearchIE._fetch_page;  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_plusr3  r6  r   r4  r5  r1  r-  )r   r   rH  s      r   r  z!DailymotionSearchIE._real_extractA  s[    ||(()<=##i//0@0@$GY[_aeg 	gr   N)re   rf   rg   r   r  r-  r  rG  rI  r1  r  rj   r   r   rA  rA    sI    "G\JJI#&
  F pM(bgr   rA  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/nqtvru   nqtv   r   z,http://www.dailymotion.com/user/UnderProjectUnderProjecti  zTakes too long time)r   r   r   r   r-   r   )r   r   r   paramschannelN)re   rf   rg   r   r  r  r,  rj   r   r   rP  rP  G  ss     G TJ6&
 ! >.
 "% 7&
 !
	F. Lr   rP  )r4  r[   r   urllib.parserL  commonr   networking.exceptionsr   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rl   r$  r9  rA  rP  rj   r   r   <module>rZ     s      	  ! -   "I= IX~
0 ~
B" < ":85 8,+g3 +g\1 r   