You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urlparse
  5. from ..utils import (
  6. int_or_none,
  7. js_to_json,
  8. mimetype2ext,
  9. )
  10. class MusicPlayOnIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:.+?\.)?musicplayon\.com/play(?:-touch)?\?(?:v|pl=\d+&play)=(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'http://en.musicplayon.com/play?v=433377',
  14. 'md5': '00cdcdea1726abdf500d1e7fd6dd59bb',
  15. 'info_dict': {
  16. 'id': '433377',
  17. 'ext': 'mp4',
  18. 'title': 'Rick Ross - Interview On Chelsea Lately (2014)',
  19. 'description': 'Rick Ross Interview On Chelsea Lately',
  20. 'duration': 342,
  21. 'uploader': 'ultrafish',
  22. },
  23. }, {
  24. 'url': 'http://en.musicplayon.com/play?pl=102&play=442629',
  25. 'only_matching': True,
  26. }]
  27. _URL_TEMPLATE = 'http://en.musicplayon.com/play?v=%s'
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. url = self._URL_TEMPLATE % video_id
  31. page = self._download_webpage(url, video_id)
  32. title = self._og_search_title(page)
  33. description = self._og_search_description(page)
  34. thumbnail = self._og_search_thumbnail(page)
  35. duration = self._html_search_meta('video:duration', page, 'duration', fatal=False)
  36. view_count = self._og_search_property('count', page, fatal=False)
  37. uploader = self._html_search_regex(
  38. r'<div>by&nbsp;<a href="[^"]+" class="purple">([^<]+)</a></div>', page, 'uploader', fatal=False)
  39. sources = self._parse_json(
  40. self._search_regex(r'setup\[\'_sources\'\]\s*=\s*([^;]+);', page, 'video sources'),
  41. video_id, transform_source=js_to_json)
  42. formats = [{
  43. 'url': compat_urlparse.urljoin(url, source['src']),
  44. 'ext': mimetype2ext(source.get('type')),
  45. 'format_note': source.get('data-res'),
  46. } for source in sources]
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'description': description,
  51. 'thumbnail': thumbnail,
  52. 'uploader': uploader,
  53. 'duration': int_or_none(duration),
  54. 'view_count': int_or_none(view_count),
  55. 'formats': formats,
  56. }