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.

129 lines
4.7 KiB

11 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. int_or_none,
  10. ExtractorError,
  11. )
  12. class VeohIE(InfoExtractor):
  13. _VALID_URL = r'http://(?:www\.)?veoh\.com/(?:watch|iphone/#_Watch)/(?P<id>(?:v|yapi-)[\da-zA-Z]+)'
  14. _TESTS = [
  15. {
  16. 'url': 'http://www.veoh.com/watch/v56314296nk7Zdmz3',
  17. 'md5': '620e68e6a3cff80086df3348426c9ca3',
  18. 'info_dict': {
  19. 'id': '56314296',
  20. 'ext': 'mp4',
  21. 'title': 'Straight Backs Are Stronger',
  22. 'uploader': 'LUMOback',
  23. 'description': 'At LUMOback, we believe straight backs are stronger. The LUMOback Posture & Movement Sensor: It gently vibrates when you slouch, inspiring improved posture and mobility. Use the app to track your data and improve your posture over time. ',
  24. },
  25. },
  26. {
  27. 'url': 'http://www.veoh.com/watch/v27701988pbTc4wzN?h1=Chile+workers+cover+up+to+avoid+skin+damage',
  28. 'md5': '4a6ff84b87d536a6a71e6aa6c0ad07fa',
  29. 'info_dict': {
  30. 'id': '27701988',
  31. 'ext': 'mp4',
  32. 'title': 'Chile workers cover up to avoid skin damage',
  33. 'description': 'md5:2bd151625a60a32822873efc246ba20d',
  34. 'uploader': 'afp-news',
  35. 'duration': 123,
  36. },
  37. },
  38. {
  39. 'url': 'http://www.veoh.com/watch/v69525809F6Nc4frX',
  40. 'md5': '4fde7b9e33577bab2f2f8f260e30e979',
  41. 'note': 'Embedded ooyala video',
  42. 'info_dict': {
  43. 'id': '69525809',
  44. 'ext': 'mp4',
  45. 'title': 'Doctors Alter Plan For Preteen\'s Weight Loss Surgery',
  46. 'description': 'md5:f5a11c51f8fb51d2315bca0937526891',
  47. 'uploader': 'newsy-videos',
  48. },
  49. 'skip': 'This video has been deleted.',
  50. },
  51. ]
  52. def _extract_formats(self, source):
  53. formats = []
  54. link = source.get('aowPermalink')
  55. if link:
  56. formats.append({
  57. 'url': link,
  58. 'ext': 'mp4',
  59. 'format_id': 'aow',
  60. })
  61. link = source.get('fullPreviewHashLowPath')
  62. if link:
  63. formats.append({
  64. 'url': link,
  65. 'format_id': 'low',
  66. })
  67. link = source.get('fullPreviewHashHighPath')
  68. if link:
  69. formats.append({
  70. 'url': link,
  71. 'format_id': 'high',
  72. })
  73. return formats
  74. def _extract_video(self, source):
  75. return {
  76. 'id': source.get('videoId'),
  77. 'title': source.get('title'),
  78. 'description': source.get('description'),
  79. 'thumbnail': source.get('highResImage') or source.get('medResImage'),
  80. 'uploader': source.get('username'),
  81. 'duration': int_or_none(source.get('length')),
  82. 'view_count': int_or_none(source.get('views')),
  83. 'age_limit': 18 if source.get('isMature') == 'true' or source.get('isSexy') == 'true' else 0,
  84. 'formats': self._extract_formats(source),
  85. }
  86. def _real_extract(self, url):
  87. mobj = re.match(self._VALID_URL, url)
  88. video_id = mobj.group('id')
  89. if video_id.startswith('v'):
  90. rsp = self._download_xml(
  91. r'http://www.veoh.com/api/findByPermalink?permalink=%s' % video_id, video_id, 'Downloading video XML')
  92. stat = rsp.get('stat')
  93. if stat == 'ok':
  94. return self._extract_video(rsp.find('./videoList/video'))
  95. elif stat == 'fail':
  96. raise ExtractorError(
  97. '%s said: %s' % (self.IE_NAME, rsp.find('./errorList/error').get('errorMessage')), expected=True)
  98. webpage = self._download_webpage(url, video_id)
  99. age_limit = 0
  100. if 'class="adultwarning-container"' in webpage:
  101. self.report_age_confirmation()
  102. age_limit = 18
  103. request = compat_urllib_request.Request(url)
  104. request.add_header('Cookie', 'confirmedAdult=true')
  105. webpage = self._download_webpage(request, video_id)
  106. m_youtube = re.search(r'http://www\.youtube\.com/v/(.*?)(\&|"|\?)', webpage)
  107. if m_youtube is not None:
  108. youtube_id = m_youtube.group(1)
  109. self.to_screen('%s: detected Youtube video.' % video_id)
  110. return self.url_result(youtube_id, 'Youtube')
  111. info = json.loads(
  112. self._search_regex(r'videoDetailsJSON = \'({.*?})\';', webpage, 'info').replace('\\\'', '\''))
  113. video = self._extract_video(info)
  114. video['age_limit'] = age_limit
  115. return video