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.

77 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. urlencode_postdata,
  11. xpath_text,
  12. xpath_with_ns,
  13. )
  14. _x = lambda p: xpath_with_ns(p, {'xspf': 'http://xspf.org/ns/0/'})
  15. class NosVideoIE(InfoExtractor):
  16. _VALID_URL = r'https?://(?:www\.)?nosvideo\.com/' + \
  17. '(?:embed/|\?v=)(?P<id>[A-Za-z0-9]{12})/?'
  18. _PLAYLIST_URL = 'http://nosvideo.com/xml/{xml_id:s}.xml'
  19. _FILE_DELETED_REGEX = r'<b>File Not Found</b>'
  20. _TEST = {
  21. 'url': 'http://nosvideo.com/?v=mu8fle7g7rpq',
  22. 'md5': '6124ed47130d8be3eacae635b071e6b6',
  23. 'info_dict': {
  24. 'id': 'mu8fle7g7rpq',
  25. 'ext': 'mp4',
  26. 'title': 'big_buck_bunny_480p_surround-fix.avi.mp4',
  27. 'thumbnail': 're:^https?://.*\.jpg$',
  28. }
  29. }
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. fields = {
  33. 'id': video_id,
  34. 'op': 'download1',
  35. 'method_free': 'Continue to Video',
  36. }
  37. req = compat_urllib_request.Request(url, urlencode_postdata(fields))
  38. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  39. webpage = self._download_webpage(req, video_id,
  40. 'Downloading download page')
  41. if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
  42. raise ExtractorError('Video %s does not exist' % video_id,
  43. expected=True)
  44. xml_id = self._search_regex(r'php\|([^\|]+)\|', webpage, 'XML ID')
  45. playlist_url = self._PLAYLIST_URL.format(xml_id=xml_id)
  46. playlist = self._download_xml(playlist_url, video_id)
  47. track = playlist.find(_x('.//xspf:track'))
  48. if track is None:
  49. raise ExtractorError(
  50. 'XML playlist is missing the \'track\' element',
  51. expected=True)
  52. title = xpath_text(track, _x('./xspf:title'), 'title')
  53. url = xpath_text(track, _x('./xspf:file'), 'URL', fatal=True)
  54. thumbnail = xpath_text(track, _x('./xspf:image'), 'thumbnail')
  55. if title is not None:
  56. title = title.strip()
  57. formats = [{
  58. 'format_id': 'sd',
  59. 'url': url,
  60. }]
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'thumbnail': thumbnail,
  65. 'formats': formats,
  66. }