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.

99 lines
3.2 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. _TESTS = [{
  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. 'skip': 'Video removed due to ToS',
  25. }, {
  26. 'url': 'http://www.playvid.com/watch/hwb0GpNkzgH',
  27. 'md5': '39d49df503ad7b8f23a4432cbf046477',
  28. 'info_dict': {
  29. 'id': 'hwb0GpNkzgH',
  30. 'ext': 'mp4',
  31. 'title': 'Ellen Euro Cutie Blond Takes a Sexy Survey Get Facial in The Park',
  32. 'age_limit': 18,
  33. 'thumbnail': r're:^https?://.*\.jpg$',
  34. },
  35. }]
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. webpage = self._download_webpage(url, video_id)
  39. m_error = re.search(
  40. r'<div class="block-error">\s*<div class="heading">\s*<div>(?P<msg>.+?)</div>\s*</div>', webpage)
  41. if m_error:
  42. raise ExtractorError(clean_html(m_error.group('msg')), expected=True)
  43. video_title = None
  44. duration = None
  45. video_thumbnail = None
  46. formats = []
  47. # most of the information is stored in the flashvars
  48. flashvars = self._html_search_regex(
  49. r'flashvars="(.+?)"', webpage, 'flashvars')
  50. infos = compat_urllib_parse_unquote(flashvars).split(r'&')
  51. for info in infos:
  52. videovars_match = re.match(r'^video_vars\[(.+?)\]=(.+?)$', info)
  53. if videovars_match:
  54. key = videovars_match.group(1)
  55. val = videovars_match.group(2)
  56. if key == 'title':
  57. video_title = compat_urllib_parse_unquote_plus(val)
  58. if key == 'duration':
  59. try:
  60. duration = int(val)
  61. except ValueError:
  62. pass
  63. if key == 'big_thumb':
  64. video_thumbnail = val
  65. videourl_match = re.match(
  66. r'^video_urls\]\[(?P<resolution>[0-9]+)p', key)
  67. if videourl_match:
  68. height = int(videourl_match.group('resolution'))
  69. formats.append({
  70. 'height': height,
  71. 'url': val,
  72. })
  73. self._sort_formats(formats)
  74. # Extract title - should be in the flashvars; if not, look elsewhere
  75. if video_title is None:
  76. video_title = self._html_search_regex(
  77. r'<title>(.*?)</title', webpage, 'title')
  78. return {
  79. 'id': video_id,
  80. 'formats': formats,
  81. 'title': video_title,
  82. 'thumbnail': video_thumbnail,
  83. 'duration': duration,
  84. 'description': None,
  85. 'age_limit': 18
  86. }