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.

63 lines
2.6 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class AftonbladetIE(InfoExtractor):
  6. _VALID_URL = r'http://tv\.aftonbladet\.se/webbtv.+?(?P<id>article[0-9]+)\.ab(?:$|[?#])'
  7. _TEST = {
  8. 'url': 'http://tv.aftonbladet.se/webbtv/nyheter/vetenskap/rymden/article36015.ab',
  9. 'info_dict': {
  10. 'id': 'article36015',
  11. 'ext': 'mp4',
  12. 'title': 'Vulkanutbrott i rymden - nu släpper NASA bilderna',
  13. 'description': 'Jupiters måne mest aktiv av alla himlakroppar',
  14. 'timestamp': 1394142732,
  15. 'upload_date': '20140306',
  16. },
  17. }
  18. def _real_extract(self, url):
  19. video_id = self._match_id(url)
  20. webpage = self._download_webpage(url, video_id)
  21. # find internal video meta data
  22. meta_url = 'http://aftonbladet-play.drlib.aptoma.no/video/%s.json'
  23. internal_meta_id = self._html_search_regex(
  24. r'data-aptomaId="([\w\d]+)"', webpage, 'internal_meta_id')
  25. internal_meta_url = meta_url % internal_meta_id
  26. internal_meta_json = self._download_json(
  27. internal_meta_url, video_id, 'Downloading video meta data')
  28. # find internal video formats
  29. format_url = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s'
  30. internal_video_id = internal_meta_json['videoId']
  31. internal_formats_url = format_url % internal_video_id
  32. internal_formats_json = self._download_json(
  33. internal_formats_url, video_id, 'Downloading video formats')
  34. formats = []
  35. for fmt in internal_formats_json['formats']['http']['pseudostreaming']['mp4']:
  36. p = fmt['paths'][0]
  37. formats.append({
  38. 'url': 'http://%s:%d/%s/%s' % (p['address'], p['port'], p['path'], p['filename']),
  39. 'ext': 'mp4',
  40. 'width': int_or_none(fmt.get('width')),
  41. 'height': int_or_none(fmt.get('height')),
  42. 'tbr': int_or_none(fmt.get('bitrate')),
  43. 'protocol': 'http',
  44. })
  45. self._sort_formats(formats)
  46. return {
  47. 'id': video_id,
  48. 'title': internal_meta_json['title'],
  49. 'formats': formats,
  50. 'thumbnail': internal_meta_json.get('imageUrl'),
  51. 'description': internal_meta_json.get('shortPreamble'),
  52. 'timestamp': int_or_none(internal_meta_json.get('timePublished')),
  53. 'duration': int_or_none(internal_meta_json.get('duration')),
  54. 'view_count': int_or_none(internal_meta_json.get('views')),
  55. }