qqmusic.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import strip_jsonp
  5. # guid is a random number generated in javascript, but seems a fixed number
  6. # also works
  7. guid = '1'
  8. class QQMusicIE(InfoExtractor):
  9. _VALID_URL = r'http://y.qq.com/#type=song&mid=(?P<id>[0-9A-Za-z]+)'
  10. _TESTS = [{
  11. 'url': 'http://y.qq.com/#type=song&mid=004295Et37taLD',
  12. 'md5': 'bed90b6db2a7a7a7e11bc585f471f63a',
  13. 'info_dict': {
  14. 'id': '004295Et37taLD',
  15. 'ext': 'm4a',
  16. 'title': '可惜没如果',
  17. 'upload_date': '20141227',
  18. 'creator': '林俊杰',
  19. }
  20. }]
  21. def _real_extract(self, url):
  22. mid = self._match_id(url)
  23. detail_info_page = self._download_webpage(
  24. 'http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=%s&play=0' % mid,
  25. mid, note='Download sont detail info',
  26. errnote='Unable to get song detail info')
  27. song_name = self._html_search_regex(
  28. r"songname:\s*'([^']+)'", detail_info_page, 'song name')
  29. publish_time = self._html_search_regex(
  30. r'发行时间:(\d{4}-\d{2}-\d{2})', detail_info_page,
  31. 'publish time').replace('-', '')
  32. singer = self._html_search_regex(
  33. r"singer:\s*'([^']+)", detail_info_page, 'singer')
  34. vkey = self._download_json(
  35. 'http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?json=3&guid=%s' % guid,
  36. mid, note='Retrieve vkey', errnote='Unable to get vkey',
  37. transform_source=strip_jsonp)['key']
  38. song_url = 'http://cc.stream.qqmusic.qq.com/C200%s.m4a?vkey=%s&guid=%s&fromtag=0' % (mid, vkey, guid)
  39. return {
  40. 'id': mid,
  41. 'url': song_url,
  42. 'title': song_name,
  43. 'upload_date': publish_time,
  44. 'creator': singer,
  45. }