twentythreevideo.py 3.2 KB

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