sport5.py 3.1 KB

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