logo

youtube-dl

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

canalc2.py (2317B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import parse_duration
  6. class Canalc2IE(InfoExtractor):
  7. IE_NAME = 'canalc2.tv'
  8. _VALID_URL = r'https?://(?:(?:www\.)?canalc2\.tv/video/|archives-canalc2\.u-strasbg\.fr/video\.asp\?.*\bidVideo=)(?P<id>\d+)'
  9. _TESTS = [{
  10. 'url': 'http://www.canalc2.tv/video/12163',
  11. 'md5': '060158428b650f896c542dfbb3d6487f',
  12. 'info_dict': {
  13. 'id': '12163',
  14. 'ext': 'mp4',
  15. 'title': 'Terrasses du Numérique',
  16. 'duration': 122,
  17. },
  18. }, {
  19. 'url': 'http://archives-canalc2.u-strasbg.fr/video.asp?idVideo=11427&voir=oui',
  20. 'only_matching': True,
  21. }]
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(
  25. 'http://www.canalc2.tv/video/%s' % video_id, video_id)
  26. title = self._html_search_regex(
  27. r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.+?)</h3>',
  28. webpage, 'title')
  29. formats = []
  30. for _, video_url in re.findall(r'file\s*=\s*(["\'])(.+?)\1', webpage):
  31. if video_url.startswith('rtmp://'):
  32. rtmp = re.search(
  33. r'^(?P<url>rtmp://[^/]+/(?P<app>.+/))(?P<play_path>mp4:.+)$', video_url)
  34. formats.append({
  35. 'url': rtmp.group('url'),
  36. 'format_id': 'rtmp',
  37. 'ext': 'flv',
  38. 'app': rtmp.group('app'),
  39. 'play_path': rtmp.group('play_path'),
  40. 'page_url': url,
  41. })
  42. else:
  43. formats.append({
  44. 'url': video_url,
  45. 'format_id': 'http',
  46. })
  47. if formats:
  48. info = {
  49. 'formats': formats,
  50. }
  51. else:
  52. info = self._parse_html5_media_entries(url, webpage, url)[0]
  53. self._sort_formats(info['formats'])
  54. info.update({
  55. 'id': video_id,
  56. 'title': title,
  57. 'duration': parse_duration(self._search_regex(
  58. r'id=["\']video_duree["\'][^>]*>([^<]+)',
  59. webpage, 'duration', fatal=False)),
  60. })
  61. return info