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.

77 lines
3.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class TwentyThreeVideoIE(InfoExtractor):
  6. IE_NAME = '23video'
  7. _VALID_URL = r'https?://video\.(?P<domain>twentythree\.net|23video\.com|filmweb\.no)/v\.ihtml/player\.html\?(?P<query>.*?\bphoto(?:_|%5f)id=(?P<id>\d+).*)'
  8. _TEST = {
  9. 'url': 'https://video.twentythree.net/v.ihtml/player.html?showDescriptions=0&source=site&photo%5fid=20448876&autoPlay=1',
  10. 'md5': '75fcf216303eb1dae9920d651f85ced4',
  11. 'info_dict': {
  12. 'id': '20448876',
  13. 'ext': 'mp4',
  14. 'title': 'Video Marketing Minute: Personalized Video',
  15. 'timestamp': 1513855354,
  16. 'upload_date': '20171221',
  17. 'uploader_id': '12258964',
  18. 'uploader': 'Rasmus Bysted',
  19. }
  20. }
  21. def _real_extract(self, url):
  22. domain, query, photo_id = re.match(self._VALID_URL, url).groups()
  23. base_url = 'https://video.%s' % domain
  24. photo_data = self._download_json(
  25. base_url + '/api/photo/list?' + query, photo_id, query={
  26. 'format': 'json',
  27. }, transform_source=lambda s: self._search_regex(r'(?s)({.+})', s, 'photo data'))['photo']
  28. title = photo_data['title']
  29. formats = []
  30. audio_path = photo_data.get('audio_download')
  31. if audio_path:
  32. formats.append({
  33. 'format_id': 'audio',
  34. 'url': base_url + audio_path,
  35. 'filesize': int_or_none(photo_data.get('audio_size')),
  36. 'vcodec': 'none',
  37. })
  38. def add_common_info_to_list(l, template, id_field, id_value):
  39. f_base = template % id_value
  40. f_path = photo_data.get(f_base + 'download')
  41. if not f_path:
  42. return
  43. l.append({
  44. id_field: id_value,
  45. 'url': base_url + f_path,
  46. 'width': int_or_none(photo_data.get(f_base + 'width')),
  47. 'height': int_or_none(photo_data.get(f_base + 'height')),
  48. 'filesize': int_or_none(photo_data.get(f_base + 'size')),
  49. })
  50. for f in ('mobile_high', 'medium', 'hd', '1080p', '4k'):
  51. add_common_info_to_list(formats, 'video_%s_', 'format_id', f)
  52. thumbnails = []
  53. for t in ('quad16', 'quad50', 'quad75', 'quad100', 'small', 'portrait', 'standard', 'medium', 'large', 'original'):
  54. add_common_info_to_list(thumbnails, '%s_', 'id', t)
  55. return {
  56. 'id': photo_id,
  57. 'title': title,
  58. 'timestamp': int_or_none(photo_data.get('creation_date_epoch')),
  59. 'duration': int_or_none(photo_data.get('video_length')),
  60. 'view_count': int_or_none(photo_data.get('view_count')),
  61. 'comment_count': int_or_none(photo_data.get('number_of_comments')),
  62. 'uploader_id': photo_data.get('user_id'),
  63. 'uploader': photo_data.get('display_name'),
  64. 'thumbnails': thumbnails,
  65. 'formats': formats,
  66. }