logo

youtube-dl

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

turbo.py (2431B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. ExtractorError,
  8. int_or_none,
  9. qualities,
  10. xpath_text,
  11. )
  12. class TurboIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?turbo\.fr/videos-voiture/(?P<id>[0-9]+)-'
  14. _API_URL = 'http://www.turbo.fr/api/tv/xml.php?player_generique=player_generique&id={0:}'
  15. _TEST = {
  16. 'url': 'http://www.turbo.fr/videos-voiture/454443-turbo-du-07-09-2014-renault-twingo-3-bentley-continental-gt-speed-ces-guide-achat-dacia.html',
  17. 'md5': '33f4b91099b36b5d5a91f84b5bcba600',
  18. 'info_dict': {
  19. 'id': '454443',
  20. 'ext': 'mp4',
  21. 'duration': 3715,
  22. 'title': 'Turbo du 07/09/2014 : Renault Twingo 3, Bentley Continental GT Speed, CES, Guide Achat Dacia... ',
  23. 'description': 'Turbo du 07/09/2014 : Renault Twingo 3, Bentley Continental GT Speed, CES, Guide Achat Dacia...',
  24. 'thumbnail': r're:^https?://.*\.jpg$',
  25. }
  26. }
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. video_id = mobj.group('id')
  30. webpage = self._download_webpage(url, video_id)
  31. playlist = self._download_xml(self._API_URL.format(video_id), video_id)
  32. item = playlist.find('./channel/item')
  33. if item is None:
  34. raise ExtractorError('Playlist item was not found', expected=True)
  35. title = xpath_text(item, './title', 'title')
  36. duration = int_or_none(xpath_text(item, './durate', 'duration'))
  37. thumbnail = xpath_text(item, './visuel_clip', 'thumbnail')
  38. description = self._html_search_meta('description', webpage)
  39. formats = []
  40. get_quality = qualities(['3g', 'sd', 'hq'])
  41. for child in item:
  42. m = re.search(r'url_video_(?P<quality>.+)', child.tag)
  43. if m:
  44. quality = compat_str(m.group('quality'))
  45. formats.append({
  46. 'format_id': quality,
  47. 'url': child.text,
  48. 'quality': get_quality(quality),
  49. })
  50. self._sort_formats(formats)
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'duration': duration,
  55. 'thumbnail': thumbnail,
  56. 'description': description,
  57. 'formats': formats,
  58. }