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 orderedSet
  6. class CTVNewsIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?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. def _real_extract(self, url):
  41. page_id = self._match_id(url)
  42. def ninecninemedia_url_result(clip_id):
  43. return {
  44. '_type': 'url_transparent',
  45. 'id': clip_id,
  46. 'url': '9c9media:ctvnews_web:%s' % clip_id,
  47. 'ie_key': 'NineCNineMedia',
  48. }
  49. if page_id.isdigit():
  50. return ninecninemedia_url_result(page_id)
  51. else:
  52. webpage = self._download_webpage('http://www.ctvnews.ca/%s' % page_id, page_id, query={
  53. 'ot': 'example.AjaxPageLayout.ot',
  54. 'maxItemsPerPage': 1000000,
  55. })
  56. entries = [ninecninemedia_url_result(clip_id) for clip_id in orderedSet(
  57. re.findall(r'clip\.id\s*=\s*(\d+);', webpage))]
  58. return self.playlist_result(entries, page_id)