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.

81 lines
2.8 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'https?://(?:www\.)?dbtv\.no/(?:(?:lazyplayer|player)/)?(?P<id>[0-9]+)(?:#(?P<display_id>.+))?'
  13. _TESTS = [{
  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. 'url': 'http://dbtv.no/3649835190001',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'http://www.dbtv.no/lazyplayer/4631135248001',
  34. 'only_matching': True,
  35. }]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. video_id = mobj.group('id')
  39. display_id = mobj.group('display_id') or video_id
  40. data = self._download_json(
  41. 'http://api.dbtv.no/discovery/%s' % video_id, display_id)
  42. video = data['playlist'][0]
  43. formats = [{
  44. 'url': f['URL'],
  45. 'vcodec': f.get('container'),
  46. 'width': int_or_none(f.get('width')),
  47. 'height': int_or_none(f.get('height')),
  48. 'vbr': float_or_none(f.get('rate'), 1000),
  49. 'filesize': int_or_none(f.get('size')),
  50. } for f in video['renditions'] if 'URL' in f]
  51. if not formats:
  52. for url_key, format_id in [('URL', 'mp4'), ('HLSURL', 'hls')]:
  53. if url_key in video:
  54. formats.append({
  55. 'url': video[url_key],
  56. 'format_id': format_id,
  57. })
  58. self._sort_formats(formats)
  59. return {
  60. 'id': compat_str(video['id']),
  61. 'display_id': display_id,
  62. 'title': video['title'],
  63. 'description': clean_html(video['desc']),
  64. 'thumbnail': video.get('splash') or video.get('thumb'),
  65. 'timestamp': float_or_none(video.get('publishedAt'), 1000),
  66. 'duration': float_or_none(video.get('length'), 1000),
  67. 'view_count': int_or_none(video.get('views')),
  68. 'categories': video.get('tags'),
  69. 'formats': formats,
  70. }