playvid.py 3.1 KB

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