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 orderedSet
  6. class CTVNewsIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:.+?\.)?ctvnews\.ca/(?:video\?(?:clip|playlist|bin)Id=|.*?)(?P<id>[0-9.]+)'
  8. _TESTS = [{
  9. 'url': 'http://www.ctvnews.ca/video?clipId=901995',
  10. 'md5': '10deb320dc0ccb8d01d34d12fc2ea672',
  11. 'info_dict': {
  12. 'id': '901995',
  13. 'ext': 'mp4',
  14. 'title': 'Extended: \'That person cannot be me\' Johnson says',
  15. 'description': 'md5:958dd3b4f5bbbf0ed4d045c790d89285',
  16. 'timestamp': 1467286284,
  17. 'upload_date': '20160630',
  18. }
  19. }, {
  20. 'url': 'http://www.ctvnews.ca/video?playlistId=1.2966224',
  21. 'info_dict':
  22. {
  23. 'id': '1.2966224',
  24. },
  25. 'playlist_mincount': 19,
  26. }, {
  27. 'url': 'http://www.ctvnews.ca/video?binId=1.2876780',
  28. 'info_dict':
  29. {
  30. 'id': '1.2876780',
  31. },
  32. 'playlist_mincount': 100,
  33. }, {
  34. 'url': 'http://www.ctvnews.ca/1.810401',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://www.ctvnews.ca/canadiens-send-p-k-subban-to-nashville-in-blockbuster-trade-1.2967231',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://vancouverisland.ctvnews.ca/video?clipId=761241',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. page_id = self._match_id(url)
  45. def ninecninemedia_url_result(clip_id):
  46. return {
  47. '_type': 'url_transparent',
  48. 'id': clip_id,
  49. 'url': '9c9media:ctvnews_web:%s' % clip_id,
  50. 'ie_key': 'NineCNineMedia',
  51. }
  52. if page_id.isdigit():
  53. return ninecninemedia_url_result(page_id)
  54. else:
  55. webpage = self._download_webpage('http://www.ctvnews.ca/%s' % page_id, page_id, query={
  56. 'ot': 'example.AjaxPageLayout.ot',
  57. 'maxItemsPerPage': 1000000,
  58. })
  59. entries = [ninecninemedia_url_result(clip_id) for clip_id in orderedSet(
  60. re.findall(r'clip\.id\s*=\s*(\d+);', webpage))]
  61. return self.playlist_result(entries, page_id)