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.

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