You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

  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. formats = []
  27. for _, video_url in re.findall(r'file\s*=\s*(["\'])(.+?)\1', webpage):
  28. if video_url.startswith('rtmp://'):
  29. rtmp = re.search(
  30. r'^(?P<url>rtmp://[^/]+/(?P<app>.+/))(?P<play_path>mp4:.+)$', video_url)
  31. formats.append({
  32. 'url': rtmp.group('url'),
  33. 'format_id': 'rtmp',
  34. 'ext': 'flv',
  35. 'app': rtmp.group('app'),
  36. 'play_path': rtmp.group('play_path'),
  37. 'page_url': url,
  38. })
  39. else:
  40. formats.append({
  41. 'url': video_url,
  42. 'format_id': 'http',
  43. })
  44. self._sort_formats(formats)
  45. title = self._html_search_regex(
  46. r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.*?)</h3>', webpage, 'title')
  47. duration = parse_duration(self._search_regex(
  48. r'id=["\']video_duree["\'][^>]*>([^<]+)',
  49. webpage, 'duration', fatal=False))
  50. return {
  51. 'id': video_id,
  52. 'title': title,
  53. 'duration': duration,
  54. 'formats': formats,
  55. }