logo

youtube-dl

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

sapo.py (4496B)


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