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.

74 lines
2.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. float_or_none,
  7. int_or_none,
  8. clean_html,
  9. )
  10. class DBTVIE(InfoExtractor):
  11. _VALID_URL = r'http://dbtv\.no/(?P<id>[0-9]+)#(?P<display_id>.+)'
  12. _TEST = {
  13. 'url': 'http://dbtv.no/3649835190001#Skulle_teste_ut_fornøyelsespark,_men_kollegaen_var_bare_opptatt_av_bikinikroppen',
  14. 'md5': 'b89953ed25dacb6edb3ef6c6f430f8bc',
  15. 'info_dict': {
  16. 'id': '33100',
  17. 'display_id': 'Skulle_teste_ut_fornøyelsespark,_men_kollegaen_var_bare_opptatt_av_bikinikroppen',
  18. 'ext': 'mp4',
  19. 'title': 'Skulle teste ut fornøyelsespark, men kollegaen var bare opptatt av bikinikroppen',
  20. 'description': 'md5:1504a54606c4dde3e4e61fc97aa857e0',
  21. 'thumbnail': 're:https?://.*\.jpg$',
  22. 'timestamp': 1404039863.438,
  23. 'upload_date': '20140629',
  24. 'duration': 69.544,
  25. 'view_count': int,
  26. 'categories': list,
  27. }
  28. }
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. display_id = mobj.group('display_id')
  33. data = self._download_json(
  34. 'http://api.dbtv.no/discovery/%s' % video_id, display_id)
  35. video = data['playlist'][0]
  36. formats = [{
  37. 'url': f['URL'],
  38. 'vcodec': f.get('container'),
  39. 'width': int_or_none(f.get('width')),
  40. 'height': int_or_none(f.get('height')),
  41. 'vbr': float_or_none(f.get('rate'), 1000),
  42. 'filesize': int_or_none(f.get('size')),
  43. } for f in video['renditions'] if 'URL' in f]
  44. if not formats:
  45. for url_key, format_id in [('URL', 'mp4'), ('HLSURL', 'hls')]:
  46. if url_key in video:
  47. formats.append({
  48. 'url': video[url_key],
  49. 'format_id': format_id,
  50. })
  51. self._sort_formats(formats)
  52. return {
  53. 'id': video['id'],
  54. 'display_id': display_id,
  55. 'title': video['title'],
  56. 'description': clean_html(video['desc']),
  57. 'thumbnail': video.get('splash') or video.get('thumb'),
  58. 'timestamp': float_or_none(video.get('publishedAt'), 1000),
  59. 'duration': float_or_none(video.get('length'), 1000),
  60. 'view_count': int_or_none(video.get('views')),
  61. 'categories': video.get('tags'),
  62. 'formats': formats,
  63. }