o
    i                     @   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pi S )
Nz.https://cpage.api.hungama.com/v2/page/content//z/detailweba1)deviceplatformstoreId)fatalquerydata)r   _download_jsondict)selfpath
content_idr    r   L/home/ubuntu/.local/lib/python3.10/site-packages/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/ 687c5f1e9f832f3b59f44ed0eb1f120a39349649mp4zKrishna Chants 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/ 2278463f5dc9db9054d0c02602d44666	102524179Adiraz$md5:df20cd4d41eabb33634f06de1025a4b4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/   r0   z1https://www.hungama.com/movie/kahaani-2/44129919/T)r2   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|}i 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rhd|d ddgidS d dS ) Nz!https://www.hungama.com/index.phpr   z0application/x-www-form-urlencoded; charset=UTF-8XMLHttpRequest)zContent-TypezX-Requested-Withcommonget_video_mdn_url)cm)r   headersr   
stream_urlr$   hls)r(   m3u8_idmovieheadr   r)   miscr*   r,   releasedate	playcountimagekeywords.)r)   r*   r,   r-   r.   r/   r0   	sub_titleenvtt)r2   r(   )r'   formats	subtitles)	_match_idr   r
   _extract_m3u8_formatsr   r   strintr   r   r	   get)r   r2   video_id
video_jsonrM   metadatar   r   r   _real_extractG   sH   

	


zHungamaIE._real_extractN)r   r   r    
_VALID_URLrR   _TESTSrW   r   r   r   r   r!      sJ    
%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/ 964f46828e8b250aa35e5fdcfdcac3672931166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/   r1   zWhttps://un.hungama.com/song/tum-kya-mile-from-rocky-aur-rani-kii-prem-kahaani/103553672	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)   r^   r_   albumr`   r/   c              
   C   s   |  |}| jd| |ddidd }|d }|d}g }| |dp)|d	 |}t|d
d t}t|dd t}	|rH|||	d|	d |rQ| d| n|}
|dp\|d}||
||||dphd t|d|dS )Nz0https://www.hungama.com/audio-player-data/track/_countryIN)r       	song_namesinger_namefilepreview_linkc                 S      | d d S )Nresponse	media_urlr   xr   r   r   <lambda>       z-HungamaSongIE._real_extract.<locals>.<lambda>c                 S   rj   )Nrk   typer   rm   r   r   r   ro      rp   none)r2   r(   vcodecacodecz - img_srcalbum_image
album_namedate)r'   r)   r/   r^   r_   rb   r`   rM   )rO   r   rS   r   rQ   appendr   )r   r2   audio_idr   r^   r_   rM   
media_jsonrl   
media_typer)   r/   r   r   r   rW      s>   

zHungamaSongIE._real_extractNr   r   r    rX   rY   rW   r   r   r   r   rZ   j   s6    rZ   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'   69481490)r2   playlist_mincountr4   z@https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/!   123063z\https://un.hungama.com/album/what-jhumka-%3F-from-rocky-aur-rani-kii-prem-kahaani/103891805/r   	103891805c                    sH    |dd\}}jt|d|dd  fdd}| |S )Nr'   r   sT)r   c               	   3   s4    t  ddddddthfD ]	} | tV  qd S )Nbodyrows.r   rE   share)r   r	   
url_resultrZ   )song_urlr   r   r   r   entries   s   z5HungamaAlbumPlaylistIE._real_extract.<locals>.entries)_match_valid_urlgroupr   r   playlist_result)r   r2   playlist_idr   r   r   r   r   rW      s   z$HungamaAlbumPlaylistIE._real_extractNr}   r   r   r   r   r~      s&    r~   N)r;   r   utilsr   r   r   r   r   r	   r
   r   r!   rZ   r~   r   r   r   r   <module>   s    $RA