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.

66 lines
2.5 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class AftonbladetIE(InfoExtractor):
  6. _VALID_URL = r'^http://tv\.aftonbladet\.se/webbtv.+?(?P<video_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. mobj = re.search(self._VALID_URL, url)
  20. video_id = mobj.group('video_id')
  21. webpage = self._download_webpage(url, video_id)
  22. # find internal video meta data
  23. meta_url = 'http://aftonbladet-play.drlib.aptoma.no/video/%s.json'
  24. internal_meta_id = self._html_search_regex(
  25. r'data-aptomaId="([\w\d]+)"', webpage, 'internal_meta_id')
  26. internal_meta_url = meta_url % internal_meta_id
  27. internal_meta_json = self._download_json(
  28. internal_meta_url, video_id, 'Downloading video meta data')
  29. # find internal video formats
  30. format_url = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s'
  31. internal_video_id = internal_meta_json['videoId']
  32. internal_formats_url = format_url % internal_video_id
  33. internal_formats_json = self._download_json(
  34. internal_formats_url, video_id, 'Downloading video formats')
  35. formats = []
  36. for fmt in internal_formats_json['formats']['http']['pseudostreaming']['mp4']:
  37. p = fmt['paths'][0]
  38. formats.append({
  39. 'url': 'http://%s:%d/%s/%s' % (p['address'], p['port'], p['path'], p['filename']),
  40. 'ext': 'mp4',
  41. 'width': fmt['width'],
  42. 'height': fmt['height'],
  43. 'tbr': fmt['bitrate'],
  44. 'protocol': 'http',
  45. })
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'title': internal_meta_json['title'],
  50. 'formats': formats,
  51. 'thumbnail': internal_meta_json['imageUrl'],
  52. 'description': internal_meta_json['shortPreamble'],
  53. 'timestamp': internal_meta_json['timePublished'],
  54. 'duration': internal_meta_json['duration'],
  55. 'view_count': internal_meta_json['views'],
  56. }