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.

68 lines
2.5 KiB

  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 NovaMovIE(InfoExtractor):
  9. IE_NAME = 'novamov'
  10. IE_DESC = 'NovaMov'
  11. _VALID_URL = r'http://(?:(?:www\.)?%(host)s/video/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<videoid>[a-z\d]{13})' % {'host': 'novamov\.com'}
  12. _HOST = 'www.novamov.com'
  13. _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>'
  14. _FILEKEY_REGEX = r'flashvars\.filekey="(?P<filekey>[^"]+)";'
  15. _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
  16. _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
  17. _TEST = {
  18. 'url': 'http://www.novamov.com/video/4rurhn9x446jj',
  19. 'md5': '7205f346a52bbeba427603ba10d4b935',
  20. 'info_dict': {
  21. 'id': '4rurhn9x446jj',
  22. 'ext': 'flv',
  23. 'title': 'search engine optimization',
  24. 'description': 'search engine optimization is used to rank the web page in the google search engine'
  25. },
  26. 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
  27. }
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. video_id = mobj.group('videoid')
  31. page = self._download_webpage(
  32. 'http://%s/video/%s' % (self._HOST, video_id), video_id, 'Downloading video page')
  33. if re.search(self._FILE_DELETED_REGEX, page) is not None:
  34. raise ExtractorError(u'Video %s does not exist' % video_id, expected=True)
  35. filekey = self._search_regex(self._FILEKEY_REGEX, page, 'filekey')
  36. title = self._html_search_regex(self._TITLE_REGEX, page, 'title', fatal=False)
  37. description = self._html_search_regex(self._DESCRIPTION_REGEX, page, 'description', default='', fatal=False)
  38. api_response = self._download_webpage(
  39. 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
  40. 'Downloading video api response')
  41. response = compat_urlparse.parse_qs(api_response)
  42. if 'error_msg' in response:
  43. raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
  44. video_url = response['url'][0]
  45. return {
  46. 'id': video_id,
  47. 'url': video_url,
  48. 'title': title,
  49. 'description': description
  50. }