U
    y^N5                     @   s   d dl mZ d dl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 G dd de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G dd deZdS )    )unicode_literalsN   )InfoExtractor   )
clean_htmlExtractorErrorstrip_jsonpunescapeHTMLc                   @   s   e Zd Zd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dddddddddddd id!gZd"dd#d$d%d&dd'd(d%d)d*d+d,d-Zed.d/ Z	d0d1 Z
d2S )3	QQMusicIEqqmusicu   QQ音乐z9https?://y\.qq\.com/n/yqq/song/(?P<id>[0-9A-Za-z]+)\.htmlz/https://y.qq.com/n/yqq/song/004295Et37taLD.htmlZ 5f1e6cea39e182857da7ffc5ef5e6bb8Z004295Et37taLDmp3u   可惜没如果Z20141227	   林俊杰z$md5:d85afb3051952ecc50a1ee8a286d1eaczre:^https?://.*\.jpg$)idexttitlerelease_datecreatordescription	thumbnail)urlmd5	info_dictz)There is no mp3-320 version of this song.z/https://y.qq.com/n/yqq/song/004MsGEo3DdNxV.htmlZ fa3926f0c585cda0af8fa4f796482e3eZ004MsGEo3DdNxVu   如果Z20050626u	   李季美z$md5:46857d5ed62bc4ba84607a805dccf437)noter   r   r   zlyrics not in .lrc formatz/https://y.qq.com/n/yqq/song/001JyApY11tIp6.htmlZ001JyApY11tIp6zShadows Over TransylvaniaZ19970225zDark Funeralz$md5:c9b20210587cbcd6836a1c597bab4525skip_downloadT)r   r   r   paramsZM800(   i@  )prefixr   
preferenceabrZM500      ZC200m4a
   )r   r   r   )zmp3-320zmp3-128r!   c                  C   s0   t t d d } t tt d |  d S )Ni  ig    _B)inttimeroundrandom)ZcurMs r'   OC:\Users\TaGoRe\Desktop\beinconnect-dl\binaries\youtube_dl\extractor\qqmusic.pym_r_get_ruinG   s    zQQMusicIE.m_r_get_ruinc              
   C   s  |  |}| jd| |dddd}| d|d}| jd|d	d d
}|rR|dd}| jd|dd d
}| jd|dd d
}|r|dd}d }| jddg|dd d
}	|	rd|	dd |	d |	f }|  }
| jd|
 |ddtdd }g }| j	 D ]>\}}|
d|d ||d  ||
f |||d! |d"d# q| || | | dd$d% td&|D }|||||||d'}|rd(d)|d*gi|d+< |S ),NzUhttp://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=%s&play=0zDownload song detail infozUnable to get song detail infogbk)r   errnoteencodingzsongname:\s*'([^']+)'z	song nameu"   发行时间：(\d{4}-\d{2}-\d{2})zpublish timedefault- zsinger:\s*'([^']+)singerz:<div class="content" id="lrc_content"[^<>]*>([^<>]+)</div>z
LRC lyricsz\n
zalbummid:\'([0-9a-zA-Z]+)\'z"albummid":"([0-9a-zA-Z]+)"z	album midz8http://i.gtimg.cn/music/photo/mid_album_500/%s/%s/%s.jpgzEhttp://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?json=3&guid=%szRetrieve vkeyzUnable to get vkey)r   r+   transform_sourcekeyzAhttp://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0r   r   r   r   )r   format	format_idr   r   c                 s   s   | ]}|d  V  qdS )r2   Nr'   ).0liner'   r'   r(   	<genexpr>   s    z*QQMusicIE._real_extract.<locals>.<genexpr>z=(?m)^(\[[0-9]{2}:[0-9]{2}(?:\.[0-9]{2,})?\][^\n]*|\[[^\]]*\]))r   formatsr   r   r   r   r   originlrc)r   data	subtitles)	_match_id_download_webpage_html_search_regexreplace_search_regexr)   _download_jsonr   _FORMATSitemsappendget_check_formats_sort_formatsjoinrefindall)selfr   midZdetail_info_page	song_namepublish_timer1   lrc_contentthumbnail_urlZalbummidguidvkeyr<   r8   detailsZactual_lrc_lyricsr   r'   r'   r(   _real_extractL   s    
               


 	zQQMusicIE._real_extractN)__name__
__module____qualname__IE_NAMEIE_DESC
_VALID_URL_TESTSrG   staticmethodr)   rY   r'   r'   r'   r(   r
      s`   
 +

r
   c                   @   s(   e Zd Zedd Zdd Zdd ZdS )QQPlaylistBaseIEc                 C   s   d| |d |d |f S )Nz)http://y.qq.com/y/static/%s/%s/%s/%s.htmlr3   r4   r'   )categoryrQ   r'   r'   r(   qq_static_url   s    zQQPlaylistBaseIE.qq_static_urlc                 C   s&   | j d|ddddd|dd|dd	
d
S )Nz8https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcgjsonutf8utf-8Zyqqr   listenr   )
r7   Z	inCharset
outCharsetplatformZneedNewCode	singermidorderbeginnumZ
songstatus)query)rB   )rP   singmidrn   r'   r'   r(   get_singer_all_songs   s     z%QQPlaylistBaseIE.get_singer_all_songsc           	      C   s   g }d}|  ||}| ||}|d dkrP|d d }|  ||}| ||}|d d D ]:}|d dd k	r\|d d }|| d	| d
| q\|S )Nr   coder   r?   totallistZ	musicDatasongmidz#https://y.qq.com/n/yqq/song/%s.htmlQQMusic)rq   _parse_jsonrJ   rI   
url_result)	rP   rp   entriesZdefault_numZ	json_textZjson_obj_all_songsrs   itemru   r'   r'   r(   get_entries_from_page   s"      z&QQPlaylistBaseIE.get_entries_from_pageN)rZ   r[   r\   ra   rd   rq   r{   r'   r'   r'   r(   rb      s   
rb   c                   @   s4   e Zd ZdZdZdZdddddd	d
Zdd ZdS )QQMusicSingerIEzqqmusic:singeru   QQ音乐 - 歌手z;https?://y\.qq\.com/n/yqq/singer/(?P<id>[0-9A-Za-z]+)\.htmlz1https://y.qq.com/n/yqq/singer/001BLpXF2DyJe2.htmlZ001BLpXF2DyJe2r   z$md5:870ec08f7d8547c29c93010899103751r   r   r      )r   r   playlist_mincountc              	   C   sz   |  |}| |}| ||d}| jd|dd d}d }|rj| jd|dddd	|d
ddid}|dj}| ||||S )NzDownload singer pagezsingername\s*:\s*'(.*?)'zsinger namer-   z>http://s.plcloud.music.qq.com/fcgi-bin/fcg_get_singer_desc.fcgzDonwload singer description XMLr   rg   xml)rf   ri   r7   rk   Refererzhttps://y.qq.com/n/yqq/singer/)ro   headersz./data/info/desc)rA   r{   rB   rC   _download_xmlfindtextplaylist_result)rP   r   rQ   ry   Zsinger_pagesinger_nameZsinger_descZsinger_desc_pager'   r'   r(   rY      s(    

    zQQMusicSingerIE._real_extractN)rZ   r[   r\   r]   r^   r_   _TESTrY   r'   r'   r'   r(   r|      s   
r|   c                   @   sH   e Zd ZdZdZdZdddddd	d
ddddddd
gZdd ZdS )QQMusicAlbumIEzqqmusic:albumu   QQ音乐 - 专辑z:https?://y\.qq\.com/n/yqq/album/(?P<id>[0-9A-Za-z]+)\.htmlz0https://y.qq.com/n/yqq/album/000gXCTb2AhRR1.htmlZ000gXCTb2AhRR1u   我们都是这样长大的z$md5:179c5dce203a5931970d306aa9607ea6r}      r   r   playlist_countz0https://y.qq.com/n/yqq/album/002Y5a3b3AlCu3.htmlZ002Y5a3b3AlCu3u   그리고...z$md5:a48823755615508a95080e81b51ba729   c                    sj     |} d| |dd } fdd|d D }|d}|d}|d k	rZ| } ||||S )	NzMhttp://i.y.qq.com/v8/fcg-bin/fcg_v8_album_info_cp.fcg?albummid=%s&format=jsonzDownload album pager?   c                    s*   g | ]"}  d |d  d d|d qS https://y.qq.com/n/yqq/song/ru   .htmlrv   rx   r9   songrP   r'   r(   
<listcomp>  s     z0QQMusicAlbumIE._real_extract.<locals>.<listcomp>rt   namedesc)rA   rF   rJ   stripr   )rP   r   rQ   albumry   
album_nameZalbum_detailr'   r   r(   rY      s     
 


zQQMusicAlbumIE._real_extractNrZ   r[   r\   r]   r^   r_   r`   rY   r'   r'   r'   r(   r      s&   	r   c                   @   sZ   e Zd Zd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
gZdd ZdS )QQMusicToplistIEzqqmusic:toplistu   QQ音乐 - 排行榜z6https?://y\.qq\.com/n/yqq/toplist/(?P<id>[0-9]+)\.htmlz'https://y.qq.com/n/yqq/toplist/123.html123u   美国iTunes榜z$md5:89db2335fdbb10678dee2d43fe9aba08r}   d   r   z%https://y.qq.com/n/yqq/toplist/3.html3u   巅峰榜·欧美z$md5:5a600d42c01696b26b71f8c4d43407daz'https://y.qq.com/n/yqq/toplist/106.html106u   韩国Mnet榜z$md5:cb84b325215e1d21708c615cac82a6e72   c                    sj     |} jd|dd|ddd} fdd|d	 D }|d
i }|d}|d} ||||S )Nz2http://i.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcgzDownload toplist pageZtoplistre   )typeZtopidr7   )r   ro   c                    s2   g | ]*}  d |d d  d d|d d qS )r   r?   ru   r   rv   r   r   r   r'   r(   r   8  s    
z2QQMusicToplistIE._real_extract.<locals>.<listcomp>songlisttopinfoZListNameinfo)rA   rF   rJ   r   )rP   r   list_idZtoplist_jsonry   r   	list_namelist_descriptionr'   r   r(   rY   0  s    
 



zQQMusicToplistIE._real_extractNr   r'   r'   r'   r(   r     s4   		r   c                   @   sJ   e Zd ZdZdZdZdddddd	d
ddddddddgZdd ZdS )QQMusicPlaylistIEzqqmusic:playlistu   QQ音乐 - 歌单z7https?://y\.qq\.com/n/yqq/playlist/(?P<id>[0-9]+)\.htmlz.http://y.qq.com/n/yqq/playlist/3462654915.htmlZ
3462654915u   韩国5月新歌精选下旬z$md5:d2c9d758a96b9888cf4fe82f603121d4r}   r   zplaylist gone)r   r   r   skipz/https://y.qq.com/n/yqq/playlist/1374105607.htmlZ
1374105607u   易入人心的华语民谣u   民谣的歌曲易于传唱、、歌词朗朗伤口、旋律简单温馨。属于那种才入耳孔。却上心头的感觉。没有太多的复杂情绪。简单而直接地表达乐者的情绪，就是这样的简单才易入人心。   r   c              
      s     |} jd|ddddd|dtd}t|dg s`|drXtd	|d  d
dtd|d d } fdd|d D }|d}tt|d} ||||S )NzDhttp://i.y.qq.com/qzone-music/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcgzDownload list pager   r   )r   re   rf   ZonlysongZdisstid)ro   r5   cdlistrr   z1QQ Music said: error %d in fetching playlist infoT)expectedzUnable to get playlist infoc                    s*   g | ]"}  d |d  d d|d qS r   r   r   r   r'   r(   r   k  s     z3QQMusicPlaylistIE._real_extract.<locals>.<listcomp>r   Zdissnamer   )	rA   rF   r   lenrJ   r   r   r	   r   )rP   r   r   Z	list_jsonr   ry   r   r   r'   r   r(   rY   [  s,    
 



zQQMusicPlaylistIE._real_extractNr   r'   r'   r'   r(   r   C  s(   
r   )
__future__r   r&   rN   r$   commonr   utilsr   r   r   r	   r
   rb   r|   r   r   r   r'   r'   r'   r(   <module>   s    	*#+2