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.

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