melonvod.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. urljoin,
  5. )
  6. class MelonVODIE(InfoExtractor):
  7. _VALID_URL = r'https?://vod\.melon\.com/video/detail2\.html?\?.*?mvId=(?P<id>[0-9]+)'
  8. _TEST = {
  9. 'url': 'http://vod.melon.com/video/detail2.htm?mvId=50158734',
  10. 'info_dict': {
  11. 'id': '50158734',
  12. 'ext': 'mp4',
  13. 'title': "Jessica 'Wonderland' MV Making Film",
  14. 'thumbnail': r're:^https?://.*\.jpg$',
  15. 'artist': 'Jessica (제시카)',
  16. 'upload_date': '20161212',
  17. 'duration': 203,
  18. },
  19. 'params': {
  20. 'skip_download': 'm3u8 download',
  21. },
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. play_info = self._download_json(
  26. 'http://vod.melon.com/video/playerInfo.json', video_id,
  27. note='Downloading player info JSON', query={'mvId': video_id})
  28. title = play_info['mvInfo']['MVTITLE']
  29. info = self._download_json(
  30. 'http://vod.melon.com/delivery/streamingInfo.json', video_id,
  31. note='Downloading streaming info JSON',
  32. query={
  33. 'contsId': video_id,
  34. 'contsType': 'VIDEO',
  35. })
  36. stream_info = info['streamingInfo']
  37. formats = self._extract_m3u8_formats(
  38. stream_info['encUrl'], video_id, 'mp4', m3u8_id='hls')
  39. artist_list = play_info.get('artistList')
  40. artist = None
  41. if isinstance(artist_list, list):
  42. artist = ', '.join(
  43. [a['ARTISTNAMEWEBLIST']
  44. for a in artist_list if a.get('ARTISTNAMEWEBLIST')])
  45. thumbnail = urljoin(info.get('staticDomain'), stream_info.get('imgPath'))
  46. duration = int_or_none(stream_info.get('playTime'))
  47. upload_date = stream_info.get('mvSvcOpenDt', '')[:8] or None
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'artist': artist,
  52. 'thumbnail': thumbnail,
  53. 'upload_date': upload_date,
  54. 'duration': duration,
  55. 'formats': formats,
  56. }