ctvnews.py 2.1 KB

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