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.

75 lines
2.6 KiB

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