80 lines
2.5 KiB

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