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.

88 lines
2.8 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse_unquote,
  6. compat_urllib_parse_unquote_plus,
  7. )
  8. from ..utils import (
  9. clean_html,
  10. ExtractorError,
  11. )
  12. class PlayvidIE(InfoExtractor):
  13. _VALID_URL = r'https?://www\.playvid\.com/watch(\?v=|/)(?P<id>.+?)(?:#|$)'
  14. _TEST = {
  15. 'url': 'http://www.playvid.com/watch/RnmBNgtrrJu',
  16. 'md5': 'ffa2f6b2119af359f544388d8c01eb6c',
  17. 'info_dict': {
  18. 'id': 'RnmBNgtrrJu',
  19. 'ext': 'mp4',
  20. 'title': 'md5:9256d01c6317e3f703848b5906880dc8',
  21. 'duration': 82,
  22. 'age_limit': 18,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. m_error = re.search(
  29. r'<div class="block-error">\s*<div class="heading">\s*<div>(?P<msg>.+?)</div>\s*</div>', webpage)
  30. if m_error:
  31. raise ExtractorError(clean_html(m_error.group('msg')), expected=True)
  32. video_title = None
  33. duration = None
  34. video_thumbnail = None
  35. formats = []
  36. # most of the information is stored in the flashvars
  37. flashvars = self._html_search_regex(
  38. r'flashvars="(.+?)"', webpage, 'flashvars')
  39. infos = compat_urllib_parse_unquote(flashvars).split(r'&')
  40. for info in infos:
  41. videovars_match = re.match(r'^video_vars\[(.+?)\]=(.+?)$', info)
  42. if videovars_match:
  43. key = videovars_match.group(1)
  44. val = videovars_match.group(2)
  45. if key == 'title':
  46. video_title = compat_urllib_parse_unquote_plus(val)
  47. if key == 'duration':
  48. try:
  49. duration = int(val)
  50. except ValueError:
  51. pass
  52. if key == 'big_thumb':
  53. video_thumbnail = val
  54. videourl_match = re.match(
  55. r'^video_urls\]\[(?P<resolution>[0-9]+)p', key)
  56. if videourl_match:
  57. height = int(videourl_match.group('resolution'))
  58. formats.append({
  59. 'height': height,
  60. 'url': val,
  61. })
  62. self._sort_formats(formats)
  63. # Extract title - should be in the flashvars; if not, look elsewhere
  64. if video_title is None:
  65. video_title = self._html_search_regex(
  66. r'<title>(.*?)</title', webpage, 'title')
  67. return {
  68. 'id': video_id,
  69. 'formats': formats,
  70. 'title': video_title,
  71. 'thumbnail': video_thumbnail,
  72. 'duration': duration,
  73. 'description': None,
  74. 'age_limit': 18
  75. }