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.

65 lines
2.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse,
  7. compat_urllib_request,
  8. xpath_with_ns,
  9. )
  10. _x = lambda p: xpath_with_ns(p, {'xspf': 'http://xspf.org/ns/0/'})
  11. _find = lambda el, p: el.find(_x(p)).text.strip()
  12. class NosVideoIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?nosvideo\.com/' + \
  14. '(?:embed/|\?v=)(?P<id>[A-Za-z0-9]{12})/?'
  15. _PLAYLIST_URL = 'http://nosvideo.com/xml/{xml_id:s}.xml'
  16. _TEST = {
  17. 'url': 'http://nosvideo.com/?v=drlp6s40kg54',
  18. 'md5': '4b4ac54c6ad5d70ab88f2c2c6ccec71c',
  19. 'info_dict': {
  20. 'id': 'drlp6s40kg54',
  21. 'ext': 'mp4',
  22. 'title': 'big_buck_bunny_480p_surround-fix.avi.mp4',
  23. 'thumbnail': 're:^https?://.*\.jpg$',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. video_id = mobj.group('id')
  29. fields = {
  30. 'id': video_id,
  31. 'op': 'download1',
  32. 'method_free': 'Continue to Video',
  33. }
  34. post = compat_urllib_parse.urlencode(fields)
  35. req = compat_urllib_request.Request(url, post)
  36. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  37. webpage = self._download_webpage(req, video_id,
  38. 'Downloading download page')
  39. xml_id = self._search_regex(r'php\|([^\|]+)\|', webpage, 'XML ID')
  40. playlist_url = self._PLAYLIST_URL.format(xml_id=xml_id)
  41. playlist = self._download_xml(playlist_url, video_id)
  42. track = playlist.find(_x('.//xspf:track'))
  43. title = _find(track, './xspf:title')
  44. url = _find(track, './xspf:file')
  45. thumbnail = _find(track, './xspf:image')
  46. formats = [{
  47. 'format_id': 'sd',
  48. 'url': url,
  49. }]
  50. return {
  51. 'id': video_id,
  52. 'title': title,
  53. 'thumbnail': thumbnail,
  54. 'formats': formats,
  55. }