canalc2.py 2.2 KB

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