
    VGh.0                     f    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 ddlmZ  G d d	e      Zy)
    N   )InfoExtractor   )	HTTPError)ExtractorErrorjwt_decode_hs256parse_codecstry_geturl_or_noneurlencode_postdata)traverse_objc                      e Zd ZdZdZdZdddddd	d
dddddgdgd
ddiddddddgdd
dddiddddddd d
d!d"g d#d$ddid%dd&dddgdd
dddid'dgZd(Zd)Zd*Z	d+Z
d,Zd-Zd.d/d0d1ed2Zd3Zd4Zd3Zed5        Zd6 Zd7 Zd=d8Zd9 Zd: Zd; Zd< Zy3)>DigitalConcertHallIEzDigitalConcertHall extractorz}https?://(?:www\.)?digitalconcerthall\.com/(?P<language>[a-z]+)/(?P<type>film|concert|work)/(?P<id>[0-9]+)-?(?P<part>[0-9]+)?digitalconcerthallzPlaylist with only one videoz3https://www.digitalconcerthall.com/en/concert/53201z53201-1mp4z
Kurt Weillz[Magic Night]zAre:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$20210624i`i
  z&Members of the Berliner Philharmonikeru   Simon Rössler)
idextcomposertitle	thumbnailupload_date	timestampdurationalbum_artists	composersskip_downloadm3u8)noteurl	info_dictparamsz+Concert with several works and an interviewz3https://www.digitalconcerthall.com/en/concert/5378553785zBerliner PhilharmonikerzKirill Petrenkoz5Kirill Petrenko conducts Mendelssohn and Shostakovich)r   r   r   r      )r   r    r!   r"   playlist_countz.https://www.digitalconcerthall.com/en/film/388388z6The Berliner Philharmoniker and Frank Peter Zimmermannz$md5:cfe25a7044fa4be13743e5089b5b5eb220220714i b)zFrank Peter ZimmermannzBenedikt von BernstorffzJakob von Bernstorff)r   r   r   descriptionr   r   r   r   )r    r!   r"   z2https://www.digitalconcerthall.com/en/work/53785-1r   zUse  --username token --password ACCESS_TOKEN  where ACCESS_TOKEN is the "access_token_production" from your browser local storagezOor else use a "refresh_token" with  --username refresh --password REFRESH_TOKENz2https://api.digitalconcerthall.com/v2/oauth2/tokenz
dch.webappz
2ySLN+2FwbzuMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15application/jsonz/application/x-www-form-urlencoded;charset=UTF-8z"https://www.digitalconcerthall.comz#https://www.digitalconcerthall.com/)AcceptzContent-TypeOriginReferer
User-AgentNr   c                 \    | j                   dz
  t        t        j                               k  S )N   )_access_token_expiryinttimeselfs    l/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/digitalconcerthall.py_access_token_is_expiredz-DigitalConcertHallIE._access_token_is_expiredZ   s#    ((2-TYY[1AAA    c                 V    || _         t        |t        hdt        hf      xs d| _        y )Nexpr   )_access_tokenr   r   r1   r0   )r4   values     r5   _set_access_tokenz&DigitalConcertHallIE._set_access_token^   s.    "$0:J9KUUXTY8Z$[$`_`!r7   c                    | j                   j                  | j                  d| j                  | j                  d       y )Ntokens)access_tokenrefresh_token)cachestore_NETRC_MACHINEr:   _refresh_tokenr3   s    r5   _cache_tokensz"DigitalConcertHallIE._cache_tokensb   s5    

,,h ..!009
 	r7   c                    |r"| j                  d       | j                  d        | j                  sy | j                  s;| j                  d        | j	                          t        d| j                   d      | j                  xsT | j                  | j                  d ddt        ddd	d	| j                  d
d| j                  d      | j                        d   }	 | j                  | j                  d ddt        d| j                  | j                  | j                  d      i | j                  dd| i      }| j                  |d          t%        |dt&        hf      x}r| j)                  d       || _        | j	                          y # t
        $ rn}t        |j                  t               rN|j                  j"                  dk(  r5| j                  d        d | _        | j	                          t        dd       d }~ww xY w)Nz!Access token has been invalidatedzyAccess token has expired or been invalidated. Get a new "access_token_production" value from your browser and try again, TexpectedzObtaining initial tokenzUnable to obtain initial tokennonedeviceunknown
berlinphilz1.95.0)	affiliate
grant_typedevice_vendordevice_modelapp_idapp_distributorapp_versionclient_secret)dataheadersr?   zRefreshing tokenzUnable to refresh tokenr@   )rN   r@   	client_idrT   AuthorizationBearer   z!Your tokens have been invalidatedzNew refresh token granted)report_warningr<   r6   rD   rE   r   _REFRESH_HINTr:   _download_json
_OAUTH_URLr   
_CLIENT_ID_CLIENT_SECRET_OAUTH_HEADERS
isinstancecauser   statusr   strwrite_debug)r4   
invalidatebearer_tokenresponseer@   s         r5   _fetch_new_tokensz&DigitalConcertHallIE._fetch_new_tokensh   s    CD""4(,,""""4(  ""&"4"4!57AEG G )) =T-@-@OOT#<>^##&!* !*//#/'!%!4!4%  ++ .A .- .<.=	**'9;T'"1%)%8%8!%%)%8%8	) 
))#w|n%= + 
H& 	x78(OcU3KLL=L89"/D  	!''9-!''..C2G&&t,&*#""$$%HSWXX	s   A F 	HA)H  Hc                    | j                          |dk(  r|| _        | j                          |dk(  rLt        |t        h      st        d| j                   d      | j                  |       | j                          |dv r2| j                  d      dur|dk(  rd	nd}| j                  d
| d       y |dk7  r't        d| j                   d| j                   d      | j                  j                  | j                  di       }| j                  |j                  d             |j                  d      | _        | j                   sy | j                  d       y )Nrefreshtokenz0The access token passed to yt-dlp is not valid. TrG   )rm   rn   cachedirFaccesszYour zr token has been cached to disk. To use the cached token next time, pass  --username cache  along with any passwordrA   zGLogin with username and password is no longer supported for this site. , r>   )defaultr?   r@   rg   )report_loginrD   rk   r   r   r   _LOGIN_HINTr<   rE   	get_param	to_screenr\   rA   loadrC   getr6   )r4   usernamepassword
token_typecached_tokenss        r5   _perform_loginz#DigitalConcertHallIE._perform_login   sp   y "*D""$w+;*<=$FtGWGWFXYdhj j""8, ++~~j)6)1W)<X)
zl 3b  b cw ""&"2"2!32d6H6H5IKUY[ [
 

(;(;XrR}00@A+//@,, 	$/r7   c                 x    | j                   s.| j                  d| j                   d| j                   d        y y )NzAAll content on this site is only available for registered users. rq   )method)r:   raise_login_requiredru   r\   r3   s    r5   _real_initializez%DigitalConcertHallIE._real_initialize   sH    !!%%S##$Bt'9'9&:<DH & J "r7   c              +   2  K   |D ]  }|d   }dD ]_  }| j                  |        	 | j                  | j                  |d   d   d         |dd| j                   || j                  d	
      } n g }
t        dddddt        hf      D ]'  }|
j                  | j                  ||ddd             ) |
D ]F  }|j                  d      s|j                  d      dk(  s*|j                  t!        |d                H ||j                  d      |j                  d      |
|j                  d      t        |d      |j                  d      xs |j                  d      d|d|j                  d      rE|dk(  r@|d   D cg c]1  }|j                  d       t#        |d!       |j                  d"      d#3 c}nd i  y # t
        $ rA}	|r9t        |	j                  t              r|	j                  j                  dk(  rY d }	~	 d }	~	ww xY wc c}w w)$Nr   )TFrs   _linksstreamshrefr)   rY   )r*   rX   Accept-Languager-   rV   rZ   channel.streamr    r   hlsF)m3u8_idfatalformat_notevcodecrI   r   name_composerduration_total)date	publishedshort_description)r   r   r   formatsr   r   r(   chapters	cuepointsconcertr2   c                     | d   | d   z   S )Nr2   r    xs    r5   <lambda>z/DigitalConcertHallIE._entries.<locals>.<lambda>   s    1V9q};T r7   text)
start_timeend_timer   )rk   r]   _proto_relative_urlr:   _USER_AGENTr   rb   rc   r   rd   r   r   extend_extract_m3u8_formatsry   updater	   r
   )r4   itemslanguagetype_kwargsitemvideo_idshould_retrystream_infoerrorr   m3u8_urlfmtchapters                 r5   _entrieszDigitalConcertHallIE._entries   sM     (	DDzH - &&l2B&C"&"5"500h	1J61RSU]&8/6t7I7I6J-K/7*.*:*:	h #6 #K   G(y#xQTV[^i]j6kl rt99(He]bjo9pqr A77=)cggh.?6.IJJ|C,>?@A
 '* HH_5" HH%56)$0EF#xx(;<dPc@d   8<xx7LQVZcQck!2	4  #*++f"5 '1T U$[[0 4 jn 5(	 & #
5;;	(Ju{{OaOaehOh *4sO   $HAG/AHH!B!H6H
8H	H5H
H	H

HHc           
         | j                  |      j                  dddd      \  }}}}|sd}|dk(  rdn|}| j                  d| d	| |d
|| j                  d      }|dk(  r|gnt	        |d      }|dk(  r|t        |      dz
     g}t	        |ddddt        hf      }	t	        |dd| j                  ht        hd ht        f      }
d||j                  d      | j                  ||||
|	      |
|	dS )Nr   typer   partenworkr   z&https://api.digitalconcerthall.com/v2//r)   )r*   r   r-   r   film)	_embedded..r   r   artist.nameimagec                 (    | j                  dd      S )Nr   )widthheight)formatr   s    r5   r   z4DigitalConcertHallIE._real_extract.<locals>.<lambda>  s    qxxax2 r7   playlistr   )r   r   )_typer   r   entriesr   r   )_match_valid_urlgroupr]   r   r   r1   re   r   r   anyry   r   )r4   r    r   r   r   r   api_typevid_infovideosr   r   s              r5   _real_extractz"DigitalConcertHallIE._real_extract   s>   *.*?*?*D*J*J:W]_cek*l'%4H %9U&&4XJazJH,#+".._ '   %(LKb4cF?SY]+,F$X(CRUQV/WX S4334{m23S,: ;	
  \\'*}}%9M % ["*
 	
r7   )F)__name__
__module____qualname__IE_DESC
_VALID_URLrC   _TESTSru   r\   r^   r_   r`   r   ra   r:   r0   rD   propertyr6   r<   rE   rk   r~   r   r   r   r   r7   r5   r   r      sy   ,G RJ)N.D$$]%#FHXY&
 #F+" >D79JKL]	
 #F+ @MA]%#j	
 #F+ >C79JKL]	
 #F+Q3FhVKeMEJJ!N JK$I68!N MNB Ba8t"0HJ)V
r7   r   )r2   commonr   networking.exceptionsr   utilsr   r   r	   r
   r   r   utils.traversalr   r   r   r7   r5   <module>r      s+     ! -  +E
= E
r7   