logo

youtube-dl

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

sport5.py (3255B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class Sport5IE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www|vod)?\.sport5\.co\.il/.*\b(?:Vi|docID)=(?P<id>\d+)'
  8. _TESTS = [
  9. {
  10. 'url': 'http://vod.sport5.co.il/?Vc=147&Vi=176331&Page=1',
  11. 'info_dict': {
  12. 'id': 's5-Y59xx1-GUh2',
  13. 'ext': 'mp4',
  14. 'title': 'ולנסיה-קורדובה 0:3',
  15. 'description': 'אלקאסר, גאייה ופגולי סידרו לקבוצה של נונו ניצחון על קורדובה ואת המקום הראשון בליגה',
  16. 'duration': 228,
  17. 'categories': list,
  18. },
  19. 'skip': 'Blocked outside of Israel',
  20. }, {
  21. 'url': 'http://www.sport5.co.il/articles.aspx?FolderID=3075&docID=176372&lang=HE',
  22. 'info_dict': {
  23. 'id': 's5-SiXxx1-hKh2',
  24. 'ext': 'mp4',
  25. 'title': 'GOALS_CELTIC_270914.mp4',
  26. 'description': '',
  27. 'duration': 87,
  28. 'categories': list,
  29. },
  30. 'skip': 'Blocked outside of Israel',
  31. }
  32. ]
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. media_id = mobj.group('id')
  36. webpage = self._download_webpage(url, media_id)
  37. video_id = self._html_search_regex(r'clipId=([\w-]+)', webpage, 'video id')
  38. metadata = self._download_xml(
  39. 'http://sport5-metadata-rr-d.nsacdn.com/vod/vod/%s/HDS/metadata.xml' % video_id,
  40. video_id)
  41. error = metadata.find('./Error')
  42. if error is not None:
  43. raise ExtractorError(
  44. '%s returned error: %s - %s' % (
  45. self.IE_NAME,
  46. error.find('./Name').text,
  47. error.find('./Description').text),
  48. expected=True)
  49. title = metadata.find('./Title').text
  50. description = metadata.find('./Description').text
  51. duration = int(metadata.find('./Duration').text)
  52. posters_el = metadata.find('./PosterLinks')
  53. thumbnails = [{
  54. 'url': thumbnail.text,
  55. 'width': int(thumbnail.get('width')),
  56. 'height': int(thumbnail.get('height')),
  57. } for thumbnail in posters_el.findall('./PosterIMG')] if posters_el is not None else []
  58. categories_el = metadata.find('./Categories')
  59. categories = [
  60. cat.get('name') for cat in categories_el.findall('./Category')
  61. ] if categories_el is not None else []
  62. formats = [{
  63. 'url': fmt.text,
  64. 'ext': 'mp4',
  65. 'vbr': int(fmt.get('bitrate')),
  66. 'width': int(fmt.get('width')),
  67. 'height': int(fmt.get('height')),
  68. } for fmt in metadata.findall('./PlaybackLinks/FileURL')]
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'description': description,
  74. 'thumbnails': thumbnails,
  75. 'duration': duration,
  76. 'categories': categories,
  77. 'formats': formats,
  78. }