logo

youtube-dl

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

jove.py (3075B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. unified_strdate
  7. )
  8. class JoveIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?jove\.com/video/(?P<id>[0-9]+)'
  10. _CHAPTERS_URL = 'http://www.jove.com/video-chapters?videoid={video_id:}'
  11. _TESTS = [
  12. {
  13. 'url': 'http://www.jove.com/video/2744/electrode-positioning-montage-transcranial-direct-current',
  14. 'md5': '93723888d82dbd6ba8b3d7d0cd65dd2b',
  15. 'info_dict': {
  16. 'id': '2744',
  17. 'ext': 'mp4',
  18. 'title': 'Electrode Positioning and Montage in Transcranial Direct Current Stimulation',
  19. 'description': 'md5:015dd4509649c0908bc27f049e0262c6',
  20. 'thumbnail': r're:^https?://.*\.png$',
  21. 'upload_date': '20110523',
  22. }
  23. },
  24. {
  25. 'url': 'http://www.jove.com/video/51796/culturing-caenorhabditis-elegans-axenic-liquid-media-creation',
  26. 'md5': '914aeb356f416811d911996434811beb',
  27. 'info_dict': {
  28. 'id': '51796',
  29. 'ext': 'mp4',
  30. 'title': 'Culturing Caenorhabditis elegans in Axenic Liquid Media and Creation of Transgenic Worms by Microparticle Bombardment',
  31. 'description': 'md5:35ff029261900583970c4023b70f1dc9',
  32. 'thumbnail': r're:^https?://.*\.png$',
  33. 'upload_date': '20140802',
  34. }
  35. },
  36. ]
  37. def _real_extract(self, url):
  38. mobj = re.match(self._VALID_URL, url)
  39. video_id = mobj.group('id')
  40. webpage = self._download_webpage(url, video_id)
  41. chapters_id = self._html_search_regex(
  42. r'/video-chapters\?videoid=([0-9]+)', webpage, 'chapters id')
  43. chapters_xml = self._download_xml(
  44. self._CHAPTERS_URL.format(video_id=chapters_id),
  45. video_id, note='Downloading chapters XML',
  46. errnote='Failed to download chapters XML')
  47. video_url = chapters_xml.attrib.get('video')
  48. if not video_url:
  49. raise ExtractorError('Failed to get the video URL')
  50. title = self._html_search_meta('citation_title', webpage, 'title')
  51. thumbnail = self._og_search_thumbnail(webpage)
  52. description = self._html_search_regex(
  53. r'<div id="section_body_summary"><p class="jove_content">(.+?)</p>',
  54. webpage, 'description', fatal=False)
  55. publish_date = unified_strdate(self._html_search_meta(
  56. 'citation_publication_date', webpage, 'publish date', fatal=False))
  57. comment_count = int(self._html_search_regex(
  58. r'<meta name="num_comments" content="(\d+) Comments?"',
  59. webpage, 'comment count', fatal=False))
  60. return {
  61. 'id': video_id,
  62. 'title': title,
  63. 'url': video_url,
  64. 'thumbnail': thumbnail,
  65. 'description': description,
  66. 'upload_date': publish_date,
  67. 'comment_count': comment_count,
  68. }