vbox7.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import urlencode_postdata
  5. class Vbox7IE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?vbox7\.com/play:(?P<id>[^/]+)'
  7. _TESTS = [{
  8. 'url': 'http://vbox7.com/play:0946fff23c',
  9. 'md5': 'a60f9ab3a3a2f013ef9a967d5f7be5bf',
  10. 'info_dict': {
  11. 'id': '0946fff23c',
  12. 'ext': 'mp4',
  13. 'title': 'Борисов: Притеснен съм за бъдещето на България',
  14. },
  15. }, {
  16. 'url': 'http://vbox7.com/play:249bb972c2',
  17. 'md5': '99f65c0c9ef9b682b97313e052734c3f',
  18. 'info_dict': {
  19. 'id': '249bb972c2',
  20. 'ext': 'mp4',
  21. 'title': 'Смях! Чудо - чист за секунди - Скрита камера',
  22. },
  23. 'skip': 'georestricted',
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. title = self._html_search_regex(
  29. r'<title>(.*)</title>', webpage, 'title').split('/')[0].strip()
  30. video_url = self._search_regex(
  31. r'src\s*:\s*(["\'])(?P<url>.+?.mp4.*?)\1',
  32. webpage, 'video url', default=None, group='url')
  33. thumbnail_url = self._og_search_thumbnail(webpage)
  34. if not video_url:
  35. info_response = self._download_webpage(
  36. 'http://vbox7.com/play/magare.do', video_id,
  37. 'Downloading info webpage',
  38. data=urlencode_postdata({'as3': '1', 'vid': video_id}),
  39. headers={'Content-Type': 'application/x-www-form-urlencoded'})
  40. final_url, thumbnail_url = map(
  41. lambda x: x.split('=')[1], info_response.split('&'))
  42. if '/na.mp4' in video_url:
  43. self.raise_geo_restricted()
  44. return {
  45. 'id': video_id,
  46. 'url': self._proto_relative_url(video_url, 'http:'),
  47. 'title': title,
  48. 'thumbnail': thumbnail_url,
  49. }