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.

119 lines
3.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. xpath_with_ns,
  9. xpath_text,
  10. find_xpath_attr,
  11. )
  12. class XstreamIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. (?:
  15. xstream:|
  16. https?://frontend\.xstream\.(?:dk|net)/
  17. )
  18. (?P<partner_id>[^/]+)
  19. (?:
  20. :|
  21. /feed/video/\?.*?\bid=
  22. )
  23. (?P<id>\d+)
  24. '''
  25. _TESTS = [{
  26. 'url': 'http://frontend.xstream.dk/btno/feed/video/?platform=web&id=86588',
  27. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  28. 'info_dict': {
  29. 'id': '86588',
  30. 'ext': 'mov',
  31. 'title': 'Otto Wollertsen',
  32. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  33. 'timestamp': 1430473209,
  34. 'upload_date': '20150501',
  35. },
  36. }, {
  37. 'url': 'http://frontend.xstream.dk/ap/feed/video/?platform=web&id=21039',
  38. 'only_matching': True,
  39. }]
  40. def _extract_video_info(self, partner_id, video_id):
  41. data = self._download_xml(
  42. 'http://frontend.xstream.dk/%s/feed/video/?platform=web&id=%s'
  43. % (partner_id, video_id),
  44. video_id)
  45. NS_MAP = {
  46. 'atom': 'http://www.w3.org/2005/Atom',
  47. 'xt': 'http://xstream.dk/',
  48. 'media': 'http://search.yahoo.com/mrss/',
  49. }
  50. entry = data.find(xpath_with_ns('./atom:entry', NS_MAP))
  51. title = xpath_text(
  52. entry, xpath_with_ns('./atom:title', NS_MAP), 'title')
  53. description = xpath_text(
  54. entry, xpath_with_ns('./atom:summary', NS_MAP), 'description')
  55. timestamp = parse_iso8601(xpath_text(
  56. entry, xpath_with_ns('./atom:published', NS_MAP), 'upload date'))
  57. formats = []
  58. media_group = entry.find(xpath_with_ns('./media:group', NS_MAP))
  59. for media_content in media_group.findall(xpath_with_ns('./media:content', NS_MAP)):
  60. media_url = media_content.get('url')
  61. if not media_url:
  62. continue
  63. tbr = int_or_none(media_content.get('bitrate'))
  64. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', media_url)
  65. if mobj:
  66. formats.append({
  67. 'url': mobj.group('url'),
  68. 'play_path': 'mp4:%s' % mobj.group('playpath'),
  69. 'app': mobj.group('app'),
  70. 'ext': 'flv',
  71. 'tbr': tbr,
  72. 'format_id': 'rtmp-%d' % tbr,
  73. })
  74. else:
  75. formats.append({
  76. 'url': media_url,
  77. 'tbr': tbr,
  78. })
  79. self._sort_formats(formats)
  80. link = find_xpath_attr(
  81. entry, xpath_with_ns('./atom:link', NS_MAP), 'rel', 'original')
  82. if link is not None:
  83. formats.append({
  84. 'url': link.get('href'),
  85. 'format_id': link.get('rel'),
  86. 'preference': 2,
  87. })
  88. thumbnails = [{
  89. 'url': splash.get('url'),
  90. 'width': int_or_none(splash.get('width')),
  91. 'height': int_or_none(splash.get('height')),
  92. } for splash in media_group.findall(xpath_with_ns('./xt:splash', NS_MAP))]
  93. return {
  94. 'id': video_id,
  95. 'title': title,
  96. 'description': description,
  97. 'timestamp': timestamp,
  98. 'formats': formats,
  99. 'thumbnails': thumbnails,
  100. }
  101. def _real_extract(self, url):
  102. mobj = re.match(self._VALID_URL, url)
  103. partner_id = mobj.group('partner_id')
  104. video_id = mobj.group('id')
  105. return self._extract_video_info(partner_id, video_id)