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.

103 lines
3.5 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/([^/]+/)*(?P<id>[^/]+)-\d+\.html'
  14. _TEST = {
  15. 'url': 'http://www.aftenposten.no/webtv/serier-og-programmer/sweatshopenglish/TRAILER-SWEATSHOP---I-cant-take-any-more-7800835.html?paging=&section=webtv_serierogprogrammer_sweatshop_sweatshopenglish',
  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. display_id = self._match_id(url)
  28. webpage = self._download_webpage(url, display_id)
  29. video_id = self._html_search_regex(
  30. r'data-xs-id="(\d+)"', webpage, 'video id')
  31. data = self._download_xml(
  32. 'http://frontend.xstream.dk/ap/feed/video/?platform=web&id=%s' % video_id, video_id)
  33. NS_MAP = {
  34. 'atom': 'http://www.w3.org/2005/Atom',
  35. 'xt': 'http://xstream.dk/',
  36. 'media': 'http://search.yahoo.com/mrss/',
  37. }
  38. entry = data.find(xpath_with_ns('./atom:entry', NS_MAP))
  39. title = xpath_text(
  40. entry, xpath_with_ns('./atom:title', NS_MAP), 'title')
  41. description = xpath_text(
  42. entry, xpath_with_ns('./atom:summary', NS_MAP), 'description')
  43. timestamp = parse_iso8601(xpath_text(
  44. entry, xpath_with_ns('./atom:published', NS_MAP), 'upload date'))
  45. formats = []
  46. media_group = entry.find(xpath_with_ns('./media:group', NS_MAP))
  47. for media_content in media_group.findall(xpath_with_ns('./media:content', NS_MAP)):
  48. media_url = media_content.get('url')
  49. if not media_url:
  50. continue
  51. tbr = int_or_none(media_content.get('bitrate'))
  52. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', media_url)
  53. if mobj:
  54. formats.append({
  55. 'url': mobj.group('url'),
  56. 'play_path': 'mp4:%s' % mobj.group('playpath'),
  57. 'app': mobj.group('app'),
  58. 'ext': 'flv',
  59. 'tbr': tbr,
  60. 'format_id': 'rtmp-%d' % tbr,
  61. })
  62. else:
  63. formats.append({
  64. 'url': media_url,
  65. 'tbr': tbr,
  66. })
  67. self._sort_formats(formats)
  68. link = find_xpath_attr(
  69. entry, xpath_with_ns('./atom:link', NS_MAP), 'rel', 'original')
  70. if link is not None:
  71. formats.append({
  72. 'url': link.get('href'),
  73. 'format_id': link.get('rel'),
  74. })
  75. thumbnails = [{
  76. 'url': splash.get('url'),
  77. 'width': int_or_none(splash.get('width')),
  78. 'height': int_or_none(splash.get('height')),
  79. } for splash in media_group.findall(xpath_with_ns('./xt:splash', NS_MAP))]
  80. return {
  81. 'id': video_id,
  82. 'title': title,
  83. 'description': description,
  84. 'timestamp': timestamp,
  85. 'formats': formats,
  86. 'thumbnails': thumbnails,
  87. }