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.

98 lines
3.3 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 AftenpostenIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?aftenposten\.no/webtv/(?:#!/)?video/(?P<id>\d+)'
  14. _TEST = {
  15. 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
  16. 'md5': 'fd828cd29774a729bf4d4425fe192972',
  17. 'info_dict': {
  18. 'id': '21039',
  19. 'ext': 'mov',
  20. 'title': 'TRAILER: "Sweatshop" - I can´t take any more',
  21. 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
  22. 'timestamp': 1416927969,
  23. 'upload_date': '20141125',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. data = self._download_xml(
  29. 'http://frontend.xstream.dk/ap/feed/video/?platform=web&id=%s' % video_id, video_id)
  30. NS_MAP = {
  31. 'atom': 'http://www.w3.org/2005/Atom',
  32. 'xt': 'http://xstream.dk/',
  33. 'media': 'http://search.yahoo.com/mrss/',
  34. }
  35. entry = data.find(xpath_with_ns('./atom:entry', NS_MAP))
  36. title = xpath_text(
  37. entry, xpath_with_ns('./atom:title', NS_MAP), 'title')
  38. description = xpath_text(
  39. entry, xpath_with_ns('./atom:summary', NS_MAP), 'description')
  40. timestamp = parse_iso8601(xpath_text(
  41. entry, xpath_with_ns('./atom:published', NS_MAP), 'upload date'))
  42. formats = []
  43. media_group = entry.find(xpath_with_ns('./media:group', NS_MAP))
  44. for media_content in media_group.findall(xpath_with_ns('./media:content', NS_MAP)):
  45. media_url = media_content.get('url')
  46. if not media_url:
  47. continue
  48. tbr = int_or_none(media_content.get('bitrate'))
  49. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', media_url)
  50. if mobj:
  51. formats.append({
  52. 'url': mobj.group('url'),
  53. 'play_path': 'mp4:%s' % mobj.group('playpath'),
  54. 'app': mobj.group('app'),
  55. 'ext': 'flv',
  56. 'tbr': tbr,
  57. 'format_id': 'rtmp-%d' % tbr,
  58. })
  59. else:
  60. formats.append({
  61. 'url': media_url,
  62. 'tbr': tbr,
  63. })
  64. self._sort_formats(formats)
  65. link = find_xpath_attr(
  66. entry, xpath_with_ns('./atom:link', NS_MAP), 'rel', 'original')
  67. if link is not None:
  68. formats.append({
  69. 'url': link.get('href'),
  70. 'format_id': link.get('rel'),
  71. })
  72. thumbnails = [{
  73. 'url': splash.get('url'),
  74. 'width': int_or_none(splash.get('width')),
  75. 'height': int_or_none(splash.get('height')),
  76. } for splash in media_group.findall(xpath_with_ns('./xt:splash', NS_MAP))]
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'description': description,
  81. 'timestamp': timestamp,
  82. 'formats': formats,
  83. 'thumbnails': thumbnails,
  84. }