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

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