sapo.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. parse_duration,
  5. unified_strdate,
  6. )
  7. class SapoIE(InfoExtractor):
  8. IE_DESC = 'SAPO Vídeos'
  9. _VALID_URL = r'https?://(?:(?:v2|www)\.)?videos\.sapo\.(?:pt|cv|ao|mz|tl)/(?P<id>[\da-zA-Z]{20})'
  10. _TESTS = [
  11. {
  12. 'url': 'http://videos.sapo.pt/UBz95kOtiWYUMTA5Ghfi',
  13. 'md5': '79ee523f6ecb9233ac25075dee0eda83',
  14. 'note': 'SD video',
  15. 'info_dict': {
  16. 'id': 'UBz95kOtiWYUMTA5Ghfi',
  17. 'ext': 'mp4',
  18. 'title': 'Benfica - Marcas na Hitória',
  19. 'description': 'md5:c9082000a128c3fd57bf0299e1367f22',
  20. 'duration': 264,
  21. 'uploader': 'tiago_1988',
  22. 'upload_date': '20080229',
  23. 'categories': ['benfica', 'cabral', 'desporto', 'futebol', 'geovanni', 'hooijdonk', 'joao', 'karel', 'lisboa', 'miccoli'],
  24. },
  25. },
  26. {
  27. 'url': 'http://videos.sapo.pt/IyusNAZ791ZdoCY5H5IF',
  28. 'md5': '90a2f283cfb49193fe06e861613a72aa',
  29. 'note': 'HD video',
  30. 'info_dict': {
  31. 'id': 'IyusNAZ791ZdoCY5H5IF',
  32. 'ext': 'mp4',
  33. 'title': 'Codebits VII - Report',
  34. 'description': 'md5:6448d6fd81ce86feac05321f354dbdc8',
  35. 'duration': 144,
  36. 'uploader': 'codebits',
  37. 'upload_date': '20140427',
  38. 'categories': ['codebits', 'codebits2014'],
  39. },
  40. },
  41. {
  42. 'url': 'http://v2.videos.sapo.pt/yLqjzPtbTimsn2wWBKHz',
  43. 'md5': 'e5aa7cc0bdc6db9b33df1a48e49a15ac',
  44. 'note': 'v2 video',
  45. 'info_dict': {
  46. 'id': 'yLqjzPtbTimsn2wWBKHz',
  47. 'ext': 'mp4',
  48. 'title': 'Hipnose Condicionativa 4',
  49. 'description': 'md5:ef0481abf8fb4ae6f525088a6dadbc40',
  50. 'duration': 692,
  51. 'uploader': 'sapozen',
  52. 'upload_date': '20090609',
  53. 'categories': ['condicionativa', 'heloisa', 'hipnose', 'miranda', 'sapo', 'zen'],
  54. },
  55. },
  56. ]
  57. def _real_extract(self, url):
  58. mobj = self._match_valid_url(url)
  59. video_id = mobj.group('id')
  60. item = self._download_xml(
  61. f'http://rd3.videos.sapo.pt/{video_id}/rss2', video_id).find('./channel/item')
  62. title = item.find('./title').text
  63. description = item.find('./{http://videos.sapo.pt/mrss/}synopse').text
  64. thumbnail = item.find('./{http://search.yahoo.com/mrss/}content').get('url')
  65. duration = parse_duration(item.find('./{http://videos.sapo.pt/mrss/}time').text)
  66. uploader = item.find('./{http://videos.sapo.pt/mrss/}author').text
  67. upload_date = unified_strdate(item.find('./pubDate').text)
  68. view_count = int(item.find('./{http://videos.sapo.pt/mrss/}views').text)
  69. comment_count = int(item.find('./{http://videos.sapo.pt/mrss/}comment_count').text)
  70. tags = item.find('./{http://videos.sapo.pt/mrss/}tags').text
  71. categories = tags.split() if tags else []
  72. age_limit = 18 if item.find('./{http://videos.sapo.pt/mrss/}m18').text == 'true' else 0
  73. video_url = item.find('./{http://videos.sapo.pt/mrss/}videoFile').text
  74. video_size = item.find('./{http://videos.sapo.pt/mrss/}videoSize').text.split('x')
  75. formats = [{
  76. 'url': video_url,
  77. 'ext': 'mp4',
  78. 'format_id': 'sd',
  79. 'width': int(video_size[0]),
  80. 'height': int(video_size[1]),
  81. }]
  82. if item.find('./{http://videos.sapo.pt/mrss/}HD').text == 'true':
  83. formats.append({
  84. 'url': re.sub(r'/mov/1$', '/mov/39', video_url),
  85. 'ext': 'mp4',
  86. 'format_id': 'hd',
  87. 'width': 1280,
  88. 'height': 720,
  89. })
  90. return {
  91. 'id': video_id,
  92. 'title': title,
  93. 'description': description,
  94. 'thumbnail': thumbnail,
  95. 'duration': duration,
  96. 'uploader': uploader,
  97. 'upload_date': upload_date,
  98. 'view_count': view_count,
  99. 'comment_count': comment_count,
  100. 'categories': categories,
  101. 'age_limit': age_limit,
  102. 'formats': formats,
  103. }