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.

161 lines
5.6 KiB

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