
    VGh                     Z    d dl Z d dlZddlmZ ddlmZmZmZmZm	Z	m
Z
mZ  G d de      Zy)    N   )InfoExtractor   )ExtractorErrorint_or_nonejwt_decode_hs256str_or_nonetraverse_objtry_callurl_or_nonec                       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i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/gZd0Zd0Zd6d1Zd2 Z	d3 Z
d4 Zd5 Zy0)7QDanceIEqdancezGhttps?://(?:www\.)?q-dance\.com/network/(?:library|live)/(?P<id>[\w-]+)vodz1https://www.q-dance.com/network/library/146542138	146542138mp4zASound Rush [LIVE] | Defqon.1 Weekend Festival 2022 | Friday | REDz<sound-rush-live-v3-defqon-1-weekend-festival-2022-friday-redub   Relive Defqon.1 - Primal Energy 2022 with the sounds of Sound Rush LIVE at the RED on Friday! 🔥zDefqon.1 Weekend Festival 202231840632zDefqon.131840378zZhttps://images.q-dance.network/1674829540-20220624171509-220624171509_delio_dn201093-2.jpgpremium_onlyi%  )idexttitle
display_iddescriptionseason	season_idseries	series_id	thumbnailavailabilitydurationskip_downloadm3u8)noteurl	info_dictparams
livestreamz.https://www.q-dance.com/network/live/149170353	149170353z!re:^Defqon\.1 2023 - Friday - REDzdefqon-1-2023-friday-redz$md5:3c73fbbd4044e578e696adfc64019163zDefqon.1 Weekend Festival 2023	141735599z=https://images.q-dance.network/1686849069-area-thumbs_red.pngsubscriber_onlyis_livezqdancenetwork.video_149170353)r   r   r   r   r   r   r   r   r   r   r    live_status
channel_idzCompleted livestream)r$   r%   r&   skipzvod with alphanumeric idz>https://www.q-dance.com/network/library/WhDleSIWSfeT3Q9ObBKBeAWhDleSIWSfeT3Q9ObBKBeAz;Aftershock I Defqon.1 Weekend Festival 2023 I Sunday I BLUEz4naam-i-defqon-1-weekend-festival-2023-i-dag-i-podiumuD   Relive Defqon.1 Path of the Warrior with Aftershock at the BLUE 🔥i  zOhttps://images.q-dance.network/1698158361-230625-135716-defqon-1-aftershock.jpg)r   r   r   r   r   r   r   r   r   r!   r    r   z>https://www.q-dance.com/network/library/-uRFKXwmRZGVnve7av9uqAT)r%   only_matchingNc           
         | j                  dd |dddddt        j                  |d      j                         d	 
      }t	        |ddt
        hfdt
        hfdt
        hfdf      }|j                  d      sKdj                  t	        |ddt
        hf            }d|vrt        d| d      d|v rdnd}t        |d      |j                         D ]  \  }}| j                  d||        y )Nz'https://members.id-t.com/api/auth/loginzapplication/jsonr   zhttps://www.q-dance.comhttps://www.q-dance.com/)zcontent-typebrandoriginreferer),:)
separatorsc                      y)NT xs    `/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/qdance.py<lambda>z*QDanceIE._call_login_api.<locals>.<lambda>Z   s        )headersdataexpected_statusrB   accessTokenrefreshTokenidToken)_id-t-accounts-token_id-t-accounts-refreshz_id-t-accounts-id-tokenrG   z: error)codemessagevalidation_errorzQ-Dance API said ""emailzInvalid username or passwordzRefresh token has expiredTexpectedz.q-dance.com)_download_jsonjsondumpsencoder
   strgetjoinr   items_set_cookie)	selfrB   r$   logintokensrI   msgnamevalues	            r>   _call_login_apizQDanceIE._call_login_apiR   s   ##5tT 2!35	L
 JJt
;BBD* $ , ef%2SE$:'5u&=(1C5'9/
 &  zz01IIl57<ORUQV2WXYE!.$'9%%BCC4;tO0IdC t44!<<> 	:KD%^T59	:r@   c                 ,    | j                  ||d       y )N)rN   password)r`   )rZ   usernamerb   s      r>   _perform_loginzQDanceIE._perform_loginl   s    xXFGr@   c                     | j                  d      t        fd      | _        t        fd      | _        | j                  s| j	                          y y )Nr3   c                  "     d   j                   S )NrH   r_   cookiess   r>   r?   z+QDanceIE._real_initialize.<locals>.<lambda>q   s    w7O/P/V/V r@   c                  "     d   j                   S )NrG   rg   rh   s   r>   r?   z+QDanceIE._real_initialize.<locals>.<lambda>r   s    g6L.M.S.S r@   )_get_cookiesr   _refresh_token_access_tokenraise_login_required)rZ   ri   s    @r>   _real_initializezQDanceIE._real_initializeo   sJ    ##$>?&'VW%&ST!!%%' "r@   c                     t         fd      xs dt        t        j                         dz
        k  rF j                  st	        d       j                  d j                  id        j                          d j                  iS )	Nc                  4    t         j                        d   S )Nexp)r   rm   rZ   s   r>   r?   z$QDanceIE._get_auth.<locals>.<lambda>w   s    -d.@.@A%H r@   r   x   zLCannot refresh access token, login with yt-dlp or refresh cookies in browserrE   zRefreshing access token)r$   Authorization)r   inttimerl   r   r`   ro   rm   rs   s   `r>   	_get_authzQDanceIE._get_authv   s    HINQSVW[W`W`WbehWhSii&&$bd d  .$2E2E!FMf g!!#!3!344r@   c                      j                  |      } j                  ||      } j                  ||d      } fd}t        |dt        j
                  hfdt        j
                  hfdt        hfdt        hfdt        ht        fd	d
|hfdd hfddt        hfddt        j
                  hfddt        hfddt        j
                  hfddt        hfddt        hfd      } j                  d| d| j                         d      }t        |ddt        hf      }|st        |d      dk(  rt        dd      |r j                  ||d d!      ng }	|	s+ j                  d"t        |j!                  d#                   i |||	d$S )%N)rB   r   rB   )traversec                 V    t        |       xs d} j                  | dk\  | dk\  d      S )Nr         T)needs_premiumneeds_subscription
needs_auth)r   _availability)levelrZ   s    r>   extract_availabilityz4QDanceIE._real_extract.<locals>.extract_availability   s<    &+!E%%${"Z^ & ` `r@   r   r   slugr   durationInSecondssubscriptionr   typec                 (    | j                         dk(  S )Nlive)lowerr<   s    r>   r?   z(QDanceIE._real_extract.<locals>.<lambda>   s    1779+> r@   acts.eventr   eventEditionpubnubchannelName)r   r   r   r   r!   r    r,   artistr   r   r   r   r.   z8https://dc9h6qmsoymbq.cloudfront.net/api/content/videos/z/urli  )rA   rC   rB   r%   )rI   rJ   unauthorizedz1Your account does not have access to this contentTrO   F)fatalr   zNo active streams foundr,   )r   formats)	_match_id_download_webpage_search_nuxt_datar
   rU   stripr   r   filterr	   rQ   rx   r   _extract_m3u8_formatsraise_no_formatsboolrV   )
rZ   r%   video_idwebpagerB   r   infostreamm3u8_urlr   s
   `         r>   _real_extractzQDanceIE._real_extract   s   >>#&((h7%%gxBU%V	`
 D		{+)CII;7!C5/%}5,{mVD+W7K6LM!> ?@sSE*#))5!4+7%w<($>#]SE:#
   $$FxjPTUdnn. % E  (FGL1BC~U !T_cdd <D ,,he$ - 8IK 	!!";d488T]K^F_!`


 	
r@   )z
Logging in)__name__
__module____qualname___NETRC_MACHINE
_VALID_URL_TESTSrm   rl   r`   rd   ro   rx   r   r;   r@   r>   r   r      s   N[JBXX6# #u*
 #F+#& ?94A6$ #X-$9
 '%( +O*RPa #6$*j
 #F+#& Po:Fx MN:4H(5+
r@   r   )rR   rw   commonr   utilsr   r   r   r	   r
   r   r   r   r;   r@   r>   <module>r      s+      !  [
} [
r@   