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.

96 lines
3.6 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_request,
  6. compat_urlparse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. NO_DEFAULT,
  11. encode_dict,
  12. urlencode_postdata,
  13. )
  14. class NovaMovIE(InfoExtractor):
  15. IE_NAME = 'novamov'
  16. IE_DESC = 'NovaMov'
  17. _VALID_URL_TEMPLATE = r'http://(?:(?:www\.)?%(host)s/(?:file|video)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})'
  18. _VALID_URL = _VALID_URL_TEMPLATE % {'host': 'novamov\.com'}
  19. _HOST = 'www.novamov.com'
  20. _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>'
  21. _FILEKEY_REGEX = r'flashvars\.filekey="(?P<filekey>[^"]+)";'
  22. _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
  23. _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
  24. _TEST = {
  25. 'url': 'http://www.novamov.com/video/4rurhn9x446jj',
  26. 'md5': '7205f346a52bbeba427603ba10d4b935',
  27. 'info_dict': {
  28. 'id': '4rurhn9x446jj',
  29. 'ext': 'flv',
  30. 'title': 'search engine optimization',
  31. 'description': 'search engine optimization is used to rank the web page in the google search engine'
  32. },
  33. 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
  34. }
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. url = 'http://%s/video/%s' % (self._HOST, video_id)
  38. webpage = self._download_webpage(
  39. url, video_id, 'Downloading video page')
  40. if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
  41. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  42. def extract_filekey(default=NO_DEFAULT):
  43. return self._search_regex(
  44. self._FILEKEY_REGEX, webpage, 'filekey', default=default)
  45. filekey = extract_filekey(default=None)
  46. if not filekey:
  47. fields = self._hidden_inputs(webpage)
  48. post_url = self._search_regex(
  49. r'<form[^>]+action=(["\'])(?P<url>.+?)\1', webpage,
  50. 'post url', default=url, group='url')
  51. if not post_url.startswith('http'):
  52. post_url = compat_urlparse.urljoin(url, post_url)
  53. request = compat_urllib_request.Request(
  54. post_url, urlencode_postdata(encode_dict(fields)))
  55. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  56. request.add_header('Referer', post_url)
  57. webpage = self._download_webpage(
  58. request, video_id, 'Downloading continue to the video page')
  59. filekey = extract_filekey()
  60. title = self._html_search_regex(self._TITLE_REGEX, webpage, 'title', fatal=False)
  61. description = self._html_search_regex(self._DESCRIPTION_REGEX, webpage, 'description', default='', fatal=False)
  62. api_response = self._download_webpage(
  63. 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
  64. 'Downloading video api response')
  65. response = compat_urlparse.parse_qs(api_response)
  66. if 'error_msg' in response:
  67. raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
  68. video_url = response['url'][0]
  69. return {
  70. 'id': video_id,
  71. 'url': video_url,
  72. 'title': title,
  73. 'description': description
  74. }