logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

melonvod.py (2251B)


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