novamov.py 2.3 KB

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