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.

64 lines
2.1 KiB

  1. import os.path
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse_urlparse,
  6. ExtractorError,
  7. )
  8. class MySpassIE(InfoExtractor):
  9. _VALID_URL = r'http://www.myspass.de/.*'
  10. def _real_extract(self, url):
  11. META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
  12. # video id is the last path element of the URL
  13. # usually there is a trailing slash, so also try the second but last
  14. url_path = compat_urllib_parse_urlparse(url).path
  15. url_parent_path, video_id = os.path.split(url_path)
  16. if not video_id:
  17. _, video_id = os.path.split(url_parent_path)
  18. # get metadata
  19. metadata_url = META_DATA_URL_TEMPLATE % video_id
  20. metadata_text = self._download_webpage(metadata_url, video_id)
  21. metadata = xml.etree.ElementTree.fromstring(metadata_text.encode('utf-8'))
  22. # extract values from metadata
  23. url_flv_el = metadata.find('url_flv')
  24. if url_flv_el is None:
  25. raise ExtractorError(u'Unable to extract download url')
  26. video_url = url_flv_el.text
  27. extension = os.path.splitext(video_url)[1][1:]
  28. title_el = metadata.find('title')
  29. if title_el is None:
  30. raise ExtractorError(u'Unable to extract title')
  31. title = title_el.text
  32. format_id_el = metadata.find('format_id')
  33. if format_id_el is None:
  34. format = 'mp4'
  35. else:
  36. format = format_id_el.text
  37. description_el = metadata.find('description')
  38. if description_el is not None:
  39. description = description_el.text
  40. else:
  41. description = None
  42. imagePreview_el = metadata.find('imagePreview')
  43. if imagePreview_el is not None:
  44. thumbnail = imagePreview_el.text
  45. else:
  46. thumbnail = None
  47. info = {
  48. 'id': video_id,
  49. 'url': video_url,
  50. 'title': title,
  51. 'ext': extension,
  52. 'format': format,
  53. 'thumbnail': thumbnail,
  54. 'description': description
  55. }
  56. return [info]