
    uki1                     j    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 ddlmZ  G d d	e      Zy)
    N   )InfoExtractor   )	HTTPError)ExtractorErrordetermine_ext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    ^/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/yt_dlp/extractor/digitalconcerthall.py_access_token_is_expiredz-DigitalConcertHallIE._access_token_is_expired[   s#    ((2-TYY[1AAA    c                 V    || _         t        |t        hdt        hf      xs d| _        y )Nexpr   )_access_tokenr   r	   r2   r1   )r5   values     r6   _set_access_tokenz&DigitalConcertHallIE._set_access_token_   s.    "$0:J9KUUXTY8Z$[$`_`!r8   c                    | j                   j                  | j                  d| j                  | j                  d       y )Ntokens)access_tokenrefresh_token)cachestore_NETRC_MACHINEr;   _refresh_tokenr4   s    r6   _cache_tokensz"DigitalConcertHallIE._cache_tokensc   s5    

,,h ..!009
 	r8   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 tokenrA   )rO   rA   	client_idrU   AuthorizationBearer   z!Your tokens have been invalidatedzNew refresh token granted)report_warningr=   r7   rE   rF   r   _REFRESH_HINTr;   _download_json
_OAUTH_URLr   
_CLIENT_ID_CLIENT_SECRET_OAUTH_HEADERS
isinstancecauser   statusr   strwrite_debug)r5   
invalidatebearer_tokenresponseerA   s         r6   _fetch_new_tokensz&DigitalConcertHallIE._fetch_new_tokensi   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. TrH   )rn   ro   cachedirFaccesszYour zr token has been cached to disk. To use the cached token next time, pass  --username cache  along with any passwordrB   zGLogin with username and password is no longer supported for this site. , r?   )defaultr@   rA   rh   )report_loginrE   rl   r   r	   r   _LOGIN_HINTr=   rF   	get_param	to_screenr]   rB   loadrD   getr7   )r5   usernamepassword
token_typecached_tokenss        r6   _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+//@,, 	$/r8   c                 x    | j                   s.| j                  d| j                   d| j                   d        y y )NzAAll content on this site is only available for registered users. rr   )method)r;   raise_login_requiredrv   r]   r4   s    r6   _real_initializez%DigitalConcertHallIE._real_initialize   sH    !!%%S##$Bt'9'9&:<DH & J "r8   c              +     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 ]  }t        |      }|dk(  rs| j                  ||ddd      }|D ]F  }|j                  d      s|j                  d      dk(  s*|j                  t!        |d                H |
j#                  |       |dk(  r%|
j#                  | j%                  ||dd             | j'                  d| d        ||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 }	~	K d }	~	ww xY wc c}w w)*Nr   )TFrt   _linksstreamshrefr*   rZ   )r+   rY   Accept-Languager.   rW   r[   channel.streamr!   r   r   hlsF)m3u8_idfatalformat_notevcodecrJ   mpddash)mpd_idr   z'Skipping unsupported format extension ""r   name_composerduration_total)date	publishedshort_description)r   r   r   formatsr   r   r)   chapters	cuepointsconcertr3   c                     | d   | d   z   S )Nr3   r    xs    r6   <lambda>z/DigitalConcertHallIE._entries.<locals>.<lambda>   s    1V9q};T r8   text)
start_timeend_timer   )rl   r^   _proto_relative_urlr;   _USER_AGENTr   rc   rd   r   re   r   r   r   _extract_m3u8_formatsrz   updater
   extend_extract_mpd_formatsr\   r   )r5   itemslanguagetype_kwargsitemvideo_idshould_retrystream_infoerrorr   fmt_urlr   fmtsfmtchapters                   r6   _entrieszDigitalConcertHallIE._entries   s     /	DDzH - &&l2B&C"&"5"500h	1J61RSU]&8/6t7I7I6J-K/7*.*:*:	h #6 #K   G'ihPSUZ]h\i5jk Z#G,&=55gxX]ej5kD# I77=1cggh6G66QJJ|C4F'GHI NN4(E\NN4#<#<WhW]ej#<#kl''*QRUQVVW(XYZ '* 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 C/	 & #
5;;	(Ju{{OaOaehOh 84sO   $I)AH/AI)I) C4I)6I$

I)	I! 5II)II!!I)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    r6   r   z4DigitalConcertHallIE._real_extract.<locals>.<lambda>  s    qxxax2 r8   playlistr   )r   r   )_typer   r   entriesr   r   )_match_valid_urlgroupr^   r   r   r2   rf   r   r   anyrz   r   )r5   r!   r   r   r   r   api_typevid_infovideosr   r   s              r6   _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 % ["*
 	
r8   )F)__name__
__module____qualname__IE_DESC
_VALID_URLrD   _TESTSrv   r]   r_   r`   ra   r   rb   r;   r1   rE   propertyr7   r=   rF   rl   r   r   r   r   r   r8   r6   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0d
r8   r   )r3   commonr   networking.exceptionsr   utilsr   r   r	   r
   r   r   r   utils.traversalr   r   r   r8   r6   <module>r      s0     ! -   +L
= L
r8   