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.

69 lines
2.6 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import datetime
  4. import re
  5. from .common import InfoExtractor
  6. class AftonbladetIE(InfoExtractor):
  7. _VALID_URL = r'^http://tv\.aftonbladet\.se/webbtv.+?(?P<video_id>article[0-9]+)\.ab(?:$|[?#])'
  8. _TEST = {
  9. 'url': 'http://tv.aftonbladet.se/webbtv/nyheter/vetenskap/rymden/article36015.ab',
  10. 'info_dict': {
  11. 'id': 'article36015',
  12. 'ext': 'mp4',
  13. 'title': 'Vulkanutbrott i rymden - nu släpper NASA bilderna',
  14. 'description': 'Jupiters måne mest aktiv av alla himlakroppar',
  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. FORMATS_URL = 'http://aftonbladet-play.videodata.drvideo.aptoma.no/actions/video/?id=%s'
  31. internal_video_id = internal_meta_json['videoId']
  32. internal_formats_url = FORMATS_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. timestamp = datetime.datetime.fromtimestamp(internal_meta_json['timePublished'])
  48. upload_date = timestamp.strftime('%Y%m%d')
  49. return {
  50. 'id': video_id,
  51. 'title': internal_meta_json['title'],
  52. 'formats': formats,
  53. 'thumbnail': internal_meta_json['imageUrl'],
  54. 'description': internal_meta_json['shortPreamble'],
  55. 'upload_date': upload_date,
  56. 'duration': internal_meta_json['duration'],
  57. 'view_count': internal_meta_json['views'],
  58. }