logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

twentythreevideo.py (3298B)


  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?://(?P<domain>[^.]+\.(?:twentythree\.net|23video\.com|filmweb\.no))/v\.ihtml/player\.html\?(?P<query>.*?\bphoto(?:_|%5f)id=(?P<id>\d+).*)'
  8. _TESTS = [{
  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. 'url': 'https://bonnier-publications-danmark.23video.com/v.ihtml/player.html?token=f0dc46476e06e13afd5a1f84a29e31e8&source=embed&photo%5fid=36137620',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. domain, query, photo_id = re.match(self._VALID_URL, url).groups()
  26. base_url = 'https://%s' % domain
  27. photo_data = self._download_json(
  28. base_url + '/api/photo/list?' + query, photo_id, query={
  29. 'format': 'json',
  30. }, transform_source=lambda s: self._search_regex(r'(?s)({.+})', s, 'photo data'))['photo']
  31. title = photo_data['title']
  32. formats = []
  33. audio_path = photo_data.get('audio_download')
  34. if audio_path:
  35. formats.append({
  36. 'format_id': 'audio',
  37. 'url': base_url + audio_path,
  38. 'filesize': int_or_none(photo_data.get('audio_size')),
  39. 'vcodec': 'none',
  40. })
  41. def add_common_info_to_list(l, template, id_field, id_value):
  42. f_base = template % id_value
  43. f_path = photo_data.get(f_base + 'download')
  44. if not f_path:
  45. return
  46. l.append({
  47. id_field: id_value,
  48. 'url': base_url + f_path,
  49. 'width': int_or_none(photo_data.get(f_base + 'width')),
  50. 'height': int_or_none(photo_data.get(f_base + 'height')),
  51. 'filesize': int_or_none(photo_data.get(f_base + 'size')),
  52. })
  53. for f in ('mobile_high', 'medium', 'hd', '1080p', '4k'):
  54. add_common_info_to_list(formats, 'video_%s_', 'format_id', f)
  55. thumbnails = []
  56. for t in ('quad16', 'quad50', 'quad75', 'quad100', 'small', 'portrait', 'standard', 'medium', 'large', 'original'):
  57. add_common_info_to_list(thumbnails, '%s_', 'id', t)
  58. return {
  59. 'id': photo_id,
  60. 'title': title,
  61. 'timestamp': int_or_none(photo_data.get('creation_date_epoch')),
  62. 'duration': int_or_none(photo_data.get('video_length')),
  63. 'view_count': int_or_none(photo_data.get('view_count')),
  64. 'comment_count': int_or_none(photo_data.get('number_of_comments')),
  65. 'uploader_id': photo_data.get('user_id'),
  66. 'uploader': photo_data.get('display_name'),
  67. 'thumbnails': thumbnails,
  68. 'formats': formats,
  69. }