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.

153 lines
5.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import datetime
  4. import re
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_urllib_parse,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. parse_iso8601,
  12. str_to_int,
  13. )
  14. class CamdemyIE(InfoExtractor):
  15. _VALID_URL = r'http://(?:www\.)?camdemy\.com/media/(?P<id>\d+)'
  16. _TESTS = [{
  17. # single file
  18. 'url': 'http://www.camdemy.com/media/5181/',
  19. 'md5': '5a5562b6a98b37873119102e052e311b',
  20. 'info_dict': {
  21. 'id': '5181',
  22. 'ext': 'mp4',
  23. 'title': 'Ch1-1 Introduction, Signals (02-23-2012)',
  24. 'thumbnail': 're:^https?://.*\.jpg$',
  25. 'description': '',
  26. 'creator': 'ss11spring',
  27. 'upload_date': '20130114',
  28. 'timestamp': 1358154556,
  29. 'view_count': int,
  30. }
  31. }, {
  32. # With non-empty description
  33. 'url': 'http://www.camdemy.com/media/13885',
  34. 'md5': '4576a3bb2581f86c61044822adbd1249',
  35. 'info_dict': {
  36. 'id': '13885',
  37. 'ext': 'mp4',
  38. 'title': 'EverCam + Camdemy QuickStart',
  39. 'thumbnail': 're:^https?://.*\.jpg$',
  40. 'description': 'md5:050b62f71ed62928f8a35f1a41e186c9',
  41. 'creator': 'evercam',
  42. 'upload_date': '20140620',
  43. 'timestamp': 1403271569,
  44. }
  45. }, {
  46. # External source
  47. 'url': 'http://www.camdemy.com/media/14842',
  48. 'md5': '50e1c3c3aa233d3d7b7daa2fa10b1cf7',
  49. 'info_dict': {
  50. 'id': '2vsYQzNIsJo',
  51. 'ext': 'mp4',
  52. 'upload_date': '20130211',
  53. 'uploader': 'Hun Kim',
  54. 'description': 'Excel 2013 Tutorial for Beginners - How to add Password Protection',
  55. 'uploader_id': 'hunkimtutorials',
  56. 'title': 'Excel 2013 Tutorial - How to add Password Protection',
  57. }
  58. }]
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url)
  61. page = self._download_webpage(url, video_id)
  62. src_from = self._html_search_regex(
  63. r"<div class='srcFrom'>Source: <a title='([^']+)'", page,
  64. 'external source', default=None)
  65. if src_from:
  66. return self.url_result(src_from)
  67. oembed_obj = self._download_json(
  68. 'http://www.camdemy.com/oembed/?format=json&url=' + url, video_id)
  69. thumb_url = oembed_obj['thumbnail_url']
  70. video_folder = compat_urlparse.urljoin(thumb_url, 'video/')
  71. file_list_doc = self._download_xml(
  72. compat_urlparse.urljoin(video_folder, 'fileList.xml'),
  73. video_id, 'Filelist XML')
  74. file_name = file_list_doc.find('./video/item/fileName').text
  75. video_url = compat_urlparse.urljoin(video_folder, file_name)
  76. timestamp = parse_iso8601(self._html_search_regex(
  77. r"<div class='title'>Posted\s*:</div>\s*<div class='value'>([^<>]+)<",
  78. page, 'creation time', fatal=False),
  79. delimiter=' ', timezone=datetime.timedelta(hours=8))
  80. view_count = str_to_int(self._html_search_regex(
  81. r"<div class='title'>Views\s*:</div>\s*<div class='value'>([^<>]+)<",
  82. page, 'view count', fatal=False))
  83. return {
  84. 'id': video_id,
  85. 'url': video_url,
  86. 'title': oembed_obj['title'],
  87. 'thumbnail': thumb_url,
  88. 'description': self._html_search_meta('description', page),
  89. 'creator': oembed_obj['author_name'],
  90. 'duration': oembed_obj['duration'],
  91. 'timestamp': timestamp,
  92. 'view_count': view_count,
  93. }
  94. class CamdemyFolderIE(InfoExtractor):
  95. _VALID_URL = r'http://www.camdemy.com/folder/(?P<id>\d+)'
  96. _TESTS = [{
  97. # links with trailing slash
  98. 'url': 'http://www.camdemy.com/folder/450',
  99. 'info_dict': {
  100. 'id': '450',
  101. 'title': '信號與系統 2012 & 2011 (Signals and Systems)',
  102. },
  103. 'playlist_mincount': 145
  104. }, {
  105. # links without trailing slash
  106. # and multi-page
  107. 'url': 'http://www.camdemy.com/folder/853',
  108. 'info_dict': {
  109. 'id': '853',
  110. 'title': '科學計算 - 使用 Matlab'
  111. },
  112. 'playlist_mincount': 20
  113. }, {
  114. # with displayMode parameter. For testing the codes to add parameters
  115. 'url': 'http://www.camdemy.com/folder/853/?displayMode=defaultOrderByOrg',
  116. 'info_dict': {
  117. 'id': '853',
  118. 'title': '科學計算 - 使用 Matlab'
  119. },
  120. 'playlist_mincount': 20
  121. }]
  122. def _real_extract(self, url):
  123. folder_id = self._match_id(url)
  124. # Add displayMode=list so that all links are displayed in a single page
  125. parsed_url = list(compat_urlparse.urlparse(url))
  126. query = dict(compat_urlparse.parse_qsl(parsed_url[4]))
  127. query.update({'displayMode': 'list'})
  128. parsed_url[4] = compat_urllib_parse.urlencode(query)
  129. final_url = compat_urlparse.urlunparse(parsed_url)
  130. page = self._download_webpage(final_url, folder_id)
  131. matches = re.findall(r"href='(/media/\d+/?)'", page)
  132. entries = [self.url_result('http://www.camdemy.com' + media_path)
  133. for media_path in matches]
  134. folder_title = self._html_search_meta('keywords', page)
  135. return self.playlist_result(entries, folder_id, folder_title)