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.6 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_TEMPLATE = r'http://(?:(?:www\.)?%(host)s/(?:file|video)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})'
  12. _VALID_URL = _VALID_URL_TEMPLATE % {'host': 'novamov\.com'}
  13. _HOST = 'www.novamov.com'
  14. _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>'
  15. _FILEKEY_REGEX = r'flashvars\.filekey="(?P<filekey>[^"]+)";'
  16. _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
  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.novamov.com/video/4rurhn9x446jj',
  20. 'md5': '7205f346a52bbeba427603ba10d4b935',
  21. 'info_dict': {
  22. 'id': '4rurhn9x446jj',
  23. 'ext': 'flv',
  24. 'title': 'search engine optimization',
  25. 'description': 'search engine optimization is used to rank the web page in the google search engine'
  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. page = self._download_webpage(
  33. 'http://%s/video/%s' % (self._HOST, video_id), video_id, 'Downloading video page')
  34. if re.search(self._FILE_DELETED_REGEX, page) is not None:
  35. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  36. filekey = self._search_regex(self._FILEKEY_REGEX, page, 'filekey')
  37. title = self._html_search_regex(self._TITLE_REGEX, page, 'title', fatal=False)
  38. description = self._html_search_regex(self._DESCRIPTION_REGEX, page, 'description', default='', fatal=False)
  39. api_response = self._download_webpage(
  40. 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
  41. 'Downloading video api response')
  42. response = compat_urlparse.parse_qs(api_response)
  43. if 'error_msg' in response:
  44. raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
  45. video_url = response['url'][0]
  46. return {
  47. 'id': video_id,
  48. 'url': video_url,
  49. 'title': title,
  50. 'description': description
  51. }