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.

68 lines
2.2 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': 'flv',
  15. 'title': 'Terrasses du Numérique',
  16. 'duration': 122,
  17. },
  18. 'params': {
  19. 'skip_download': True, # Requires rtmpdump
  20. }
  21. }, {
  22. 'url': 'http://archives-canalc2.u-strasbg.fr/video.asp?idVideo=11427&voir=oui',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(
  28. 'http://www.canalc2.tv/video/%s' % video_id, video_id)
  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. self._sort_formats(formats)
  48. title = self._html_search_regex(
  49. r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.*?)</h3>', webpage, 'title')
  50. duration = parse_duration(self._search_regex(
  51. r'id=["\']video_duree["\'][^>]*>([^<]+)',
  52. webpage, 'duration', fatal=False))
  53. return {
  54. 'id': video_id,
  55. 'title': title,
  56. 'duration': duration,
  57. 'formats': formats,
  58. }