U
    g                     @   st   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 deZ
G dd de
ZG dd	 d	eZG d
d de
ZdS )   )InfoExtractor   )int_or_none
remove_endtraverse_objtry_getunified_timestampurl_or_noneurlencode_postdatac                   @   s   e Zd ZdddZdS )HungamaBaseIEFc              	   C   s8   t | jd| d| d||dddddd	thfp6i S )
Nz.https://cpage.api.hungama.com/v2/page/content//z/detailZweba1)ZdeviceplatformZstoreId)fatalquerydata)r   _download_jsondict)selfpath
content_idr    r   </tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/hungama.py	_call_api   s     zHungamaBaseIE._call_apiN)F)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   sj   e Zd ZdZdddddddd	d
eddd
dddddddddeddd	dddddddgZdd ZdS ) 	HungamaIEaI  (?x)
                    https?://
                        (?:www\.|un\.)?hungama\.com/
                        (?:
                            (?:video|movie|short-film)/[^/]+/|
                            tv-show/(?:[^/]+/){2}\d+/episode/[^/]+/
                        )
                        (?P<id>\d+)
                    z5http://www.hungama.com/video/krishna-chants/39349649/Z 687c5f1e9f832f3b59f44ed0eb1f120aZ39349649mp4zKrishna Chants Z20180829i  i [zVhttps://images1.hungama.com/tr:n-a_169_m/c/1/0dc/2ca/39349649/39349649_350x197.jpg?v=8zcount:6)
idexttitledescriptionupload_dateduration	timestamp
view_count	thumbnailtagsurlmd5	info_dictz2https://un.hungama.com/short-film/adira/102524179/Z 2278463f5dc9db9054d0c02602d44666Z	102524179ZAdiraz$md5:df20cd4d41eabb33634f06de1025a4b4Z20230417i <dzWhttps://images1.hungama.com/tr:n-a_23_m/c/1/197/ac9/102524179/102524179_350x525.jpg?v=1zcount:7)	r!   r"   r#   r$   r%   r'   r(   r)   r*   z1https://www.hungama.com/movie/kahaani-2/44129919/T)r,   Zonly_matchingzxhttps://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/c                 C   s   |  |}| jd|td|iddddddd	}| j|d
 |ddd}| d|}t|dddthfddthfdthfdthfddt	hfdt
hfdddthfdf|||drd|d ddgind dS ) Nz!https://www.hungama.com/index.phpr   z0application/x-www-form-urlencoded; charset=UTF-8ZXMLHttpRequest)zContent-TypezX-Requested-WithcommonZget_video_mdn_url)cm)r   headersr   Z
stream_urlr   Zhls)r"   Zm3u8_idZmovieheadr   r#   miscr$   r&   ZreleasedateZ	playcountimagekeywords.)r#   r$   r&   r'   r(   r)   r*   Z	sub_titleenZvtt)r,   r"   )r!   formatsZ	subtitles)	_match_idr   r
   Z_extract_m3u8_formatsr   r   strintr   r   r	   get)r   r,   Zvideo_idZ
video_jsonr8   metadatar   r   r   _real_extractG   sD    
 
	

	zHungamaIE._real_extractN)r   r   r   
_VALID_URLr;   _TESTSr>   r   r   r   r   r      sH   
%r   c                   @   sR   e Zd ZdZdddddddd	d
ddddddddddddddgZdd ZdS )HungamaSongIEz;https?://(?:www\.|un\.)?hungama\.com/song/[^/]+/(?P<id>\d+)z:https://www.hungama.com/song/kitni-haseen-zindagi/2931166/Z 964f46828e8b250aa35e5fdcfdcac367Z2931166Zmp3z Lucky Ali - Kitni Haseen ZindagizKitni Haseen Zindagiz	Lucky Alii  zHhttps://stat2.hungama.ind.in/assets/images/default_images/da-200x200.png)r!   r"   r#   trackartistrelease_yearr)   r+   zWhttps://un.hungama.com/song/tum-kya-mile-from-rocky-aur-rani-kii-prem-kahaani/103553672Z	103553672z$md5:5ebeb1e10771b634ce5f700ce68ae5f4z5Tum Kya Mile (From "Rocky Aur Rani Kii Prem Kahaani")zFPritam Chakraborty, Arijit Singh, Shreya Ghoshal, Amitabh Bhattacharyai  zFhttps://images.hungama.com/c/1/7c2/c7b/103553671/103553671_200x200.jpg)r!   r"   r#   rB   rC   albumrD   r)   c              
   C   s   |  |}| jd| |ddidd }|d }|d}g }| |dpR|d	 |}t|d
d t}t|dd t}	|r|||	d|	d |r| d| n|}
|dp|d}||
||||dpd t|d|dS )Nz0https://www.hungama.com/audio-player-data/track/Z_countryIN)r       Z	song_nameZsinger_namefileZpreview_linkc                 S   s   | d d S )Nresponse	media_urlr   xr   r   r   <lambda>       z-HungamaSongIE._real_extract.<locals>.<lambda>c                 S   s   | d d S )NrI   typer   rK   r   r   r   rM      rN   none)r,   r"   ZvcodecZacodecz - Zimg_srcZalbum_imageZ
album_namedate)r!   r#   r)   rB   rC   rE   rD   r8   )r9   r   r<   r   r:   appendr   )r   r,   Zaudio_idr   rB   rC   r8   Z
media_jsonrJ   
media_typer#   r)   r   r   r   r>      s@    
 
zHungamaSongIE._real_extractNr   r   r   r?   r@   r>   r   r   r   r   rA   j   s4   rA   c                   @   sF   e Zd ZdZddddiddddd	idd
dddidgZdd ZdS )HungamaAlbumPlaylistIEzPhttps?://(?:www\.|un\.)?hungama\.com/(?P<path>playlists|album)/[^/]+/(?P<id>\d+)z?https://www.hungama.com/album/bhuj-the-pride-of-india/69481490/   r!   Z69481490)r,   Zplaylist_mincountr.   z@https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/!   Z123063z\https://un.hungama.com/album/what-jhumka-%3F-from-rocky-aur-rani-kii-prem-kahaani/103891805/r   Z	103891805c                    sH    |dd\}}jt|d|dd  fdd}| |S )Nr!   r   sT)r   c               	   3   s2   t  ddddddthfD ]} | tV  qd S )NbodyZrows.r   r4   Zshare)r   r	   Z
url_resultrA   )Zsong_urlr   r   r   r   entries   s    z5HungamaAlbumPlaylistIE._real_extract.<locals>.entries)Z_match_valid_urlgroupr   r   Zplaylist_result)r   r,   Zplaylist_idr   r[   r   rZ   r   r>      s    z$HungamaAlbumPlaylistIE._real_extractNrT   r   r   r   r   rU      s*      rU   N)r/   r   utilsr   r   r   r   r   r	   r
   r   r   rA   rU   r   r   r   r   <module>   s
   $RA