videoweed.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. compat_urlparse
  7. )
  8. class VideoweedIE(InfoExtractor):
  9. IE_NAME = 'videoweed'
  10. IE_DESC = 'VideoWEED'
  11. #_VALID_URL = r'http://(?:(?:www\.)?%(host)s/file/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<videoid>[a-z\d]{13})' % {'host': 'videoweed\.com'}
  12. _VALID_URL =r'http://(?:www\.)videoweed\.es/file/(?P<id>[^"]+)'
  13. _HOST = 'www.videoweed.es'
  14. _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.</'
  15. _FILEKEY_REGEX = r'flashvars\.filekey="(?P<filekey>[^"]+)";'
  16. _TITLE_REGEX = r'<h1 class="text_shadow">([^<]+)</h1>'
  17. _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
  18. _TEST = {
  19. 'url': 'http://www.videoweed.es/file/89868b4aa3bdf',
  20. 'md5': '7205f346a52bbeba427603ba10d4b935',
  21. 'info_dict': {
  22. 'id': '89868b4aa3bdf',
  23. 'ext': 'flv',
  24. 'title': 'law and order svu 103 dvdrip',
  25. 'description': ''
  26. },
  27. 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
  28. }
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. print "itworks"
  33. page = self._download_webpage(
  34. 'http://%s/file/%s' % (self._HOST, video_id), video_id, 'Downloading video page')
  35. if re.search(self._FILE_DELETED_REGEX, page) is not None:
  36. raise ExtractorError(u'Video %s does not exist' % video_id, expected=True)
  37. filekey = self._search_regex(self._FILEKEY_REGEX, page, 'filekey')
  38. title = self._html_search_regex(self._TITLE_REGEX, page, 'title', fatal=False)
  39. description = self._html_search_regex(self._DESCRIPTION_REGEX, page, 'description', default='', fatal=False)
  40. api_response = self._download_webpage(
  41. 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
  42. 'Downloading video api response')
  43. response = compat_urlparse.parse_qs(api_response)
  44. if 'error_msg' in response:
  45. raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
  46. video_url = response['url'][0]
  47. return {
  48. 'id': video_id,
  49. 'url': video_url,
  50. 'title': title,
  51. 'description': description
  52. }