logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

cjsw.py (2412B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. unescapeHTML,
  8. )
  9. class CJSWIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?cjsw\.com/program/(?P<program>[^/]+)/episode/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'http://cjsw.com/program/freshly-squeezed/episode/20170620',
  13. 'md5': 'cee14d40f1e9433632c56e3d14977120',
  14. 'info_dict': {
  15. 'id': '91d9f016-a2e7-46c5-8dcb-7cbcd7437c41',
  16. 'ext': 'mp3',
  17. 'title': 'Freshly Squeezed – Episode June 20, 2017',
  18. 'description': 'md5:c967d63366c3898a80d0c7b0ff337202',
  19. 'series': 'Freshly Squeezed',
  20. 'episode_id': '20170620',
  21. },
  22. }, {
  23. # no description
  24. 'url': 'http://cjsw.com/program/road-pops/episode/20170707/',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. program, episode_id = mobj.group('program', 'id')
  30. audio_id = '%s/%s' % (program, episode_id)
  31. webpage = self._download_webpage(url, episode_id)
  32. title = unescapeHTML(self._search_regex(
  33. (r'<h1[^>]+class=["\']episode-header__title["\'][^>]*>(?P<title>[^<]+)',
  34. r'data-audio-title=(["\'])(?P<title>(?:(?!\1).)+)\1'),
  35. webpage, 'title', group='title'))
  36. audio_url = self._search_regex(
  37. r'<button[^>]+data-audio-src=(["\'])(?P<url>(?:(?!\1).)+)\1',
  38. webpage, 'audio url', group='url')
  39. audio_id = self._search_regex(
  40. r'/([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})\.mp3',
  41. audio_url, 'audio id', default=audio_id)
  42. formats = [{
  43. 'url': audio_url,
  44. 'ext': determine_ext(audio_url, 'mp3'),
  45. 'vcodec': 'none',
  46. }]
  47. description = self._html_search_regex(
  48. r'<p>(?P<description>.+?)</p>', webpage, 'description',
  49. default=None)
  50. series = self._search_regex(
  51. r'data-showname=(["\'])(?P<name>(?:(?!\1).)+)\1', webpage,
  52. 'series', default=program, group='name')
  53. return {
  54. 'id': audio_id,
  55. 'title': title,
  56. 'description': description,
  57. 'formats': formats,
  58. 'series': series,
  59. 'episode_id': episode_id,
  60. }