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.

73 lines
2.8 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. _TEST = {
  11. u'url': u'http://www.myspass.de/myspass/shows/tvshows/absolute-mehrheit/Absolute-Mehrheit-vom-17022013-Die-Highlights-Teil-2--/11741/',
  12. u'file': u'11741.mp4',
  13. u'md5': u'0b49f4844a068f8b33f4b7c88405862b',
  14. u'info_dict': {
  15. u"description": u"Wer kann in die Fu\u00dfstapfen von Wolfgang Kubicki treten und die Mehrheit der Zuschauer hinter sich versammeln? Wird vielleicht sogar die Absolute Mehrheit geknackt und der Jackpot von 200.000 Euro mit nach Hause genommen?",
  16. u"title": u"Absolute Mehrheit vom 17.02.2013 - Die Highlights, Teil 2"
  17. }
  18. }
  19. def _real_extract(self, url):
  20. META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
  21. # video id is the last path element of the URL
  22. # usually there is a trailing slash, so also try the second but last
  23. url_path = compat_urllib_parse_urlparse(url).path
  24. url_parent_path, video_id = os.path.split(url_path)
  25. if not video_id:
  26. _, video_id = os.path.split(url_parent_path)
  27. # get metadata
  28. metadata_url = META_DATA_URL_TEMPLATE % video_id
  29. metadata_text = self._download_webpage(metadata_url, video_id)
  30. metadata = xml.etree.ElementTree.fromstring(metadata_text.encode('utf-8'))
  31. # extract values from metadata
  32. url_flv_el = metadata.find('url_flv')
  33. if url_flv_el is None:
  34. raise ExtractorError(u'Unable to extract download url')
  35. video_url = url_flv_el.text
  36. extension = os.path.splitext(video_url)[1][1:]
  37. title_el = metadata.find('title')
  38. if title_el is None:
  39. raise ExtractorError(u'Unable to extract title')
  40. title = title_el.text
  41. format_id_el = metadata.find('format_id')
  42. if format_id_el is None:
  43. format = 'mp4'
  44. else:
  45. format = format_id_el.text
  46. description_el = metadata.find('description')
  47. if description_el is not None:
  48. description = description_el.text
  49. else:
  50. description = None
  51. imagePreview_el = metadata.find('imagePreview')
  52. if imagePreview_el is not None:
  53. thumbnail = imagePreview_el.text
  54. else:
  55. thumbnail = None
  56. info = {
  57. 'id': video_id,
  58. 'url': video_url,
  59. 'title': title,
  60. 'ext': extension,
  61. 'format': format,
  62. 'thumbnail': thumbnail,
  63. 'description': description
  64. }
  65. return [info]