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.

54 lines
2.1 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_urllib_parse,
  5. compat_urllib_request,
  6. ExtractorError,
  7. )
  8. class Vbox7IE(InfoExtractor):
  9. """Information Extractor for Vbox7"""
  10. _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)'
  11. _TEST = {
  12. u'url': u'http://vbox7.com/play:249bb972c2',
  13. u'file': u'249bb972c2.flv',
  14. u'md5': u'9c70d6d956f888bdc08c124acc120cfe',
  15. u'info_dict': {
  16. u"title": u"\u0421\u043c\u044f\u0445! \u0427\u0443\u0434\u043e - \u0447\u0438\u0441\u0442 \u0437\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0438 - \u0421\u043a\u0440\u0438\u0442\u0430 \u043a\u0430\u043c\u0435\u0440\u0430"
  17. }
  18. }
  19. def _real_extract(self,url):
  20. mobj = re.match(self._VALID_URL, url)
  21. if mobj is None:
  22. raise ExtractorError(u'Invalid URL: %s' % url)
  23. video_id = mobj.group(1)
  24. redirect_page, urlh = self._download_webpage_handle(url, video_id)
  25. new_location = self._search_regex(r'window\.location = \'(.*)\';', redirect_page, u'redirect location')
  26. redirect_url = urlh.geturl() + new_location
  27. webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page')
  28. title = self._html_search_regex(r'<title>(.*)</title>',
  29. webpage, u'title').split('/')[0].strip()
  30. ext = "flv"
  31. info_url = "http://vbox7.com/play/magare.do"
  32. data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id})
  33. info_request = compat_urllib_request.Request(info_url, data)
  34. info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  35. info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage')
  36. if info_response is None:
  37. raise ExtractorError(u'Unable to extract the media url')
  38. (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
  39. return [{
  40. 'id': video_id,
  41. 'url': final_url,
  42. 'ext': ext,
  43. 'title': title,
  44. 'thumbnail': thumbnail_url,
  45. }]