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.

126 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. },
  48. ]
  49. def _extract_formats(self, source):
  50. formats = []
  51. link = source.get('aowPermalink')
  52. if link:
  53. formats.append({
  54. 'url': link,
  55. 'ext': 'mp4',
  56. 'format_id': 'aow',
  57. })
  58. link = source.get('fullPreviewHashLowPath')
  59. if link:
  60. formats.append({
  61. 'url': link,
  62. 'format_id': 'low',
  63. })
  64. link = source.get('fullPreviewHashHighPath')
  65. if link:
  66. formats.append({
  67. 'url': link,
  68. 'format_id': 'high',
  69. })
  70. return formats
  71. def _extract_video(self, source):
  72. return {
  73. 'id': source.get('videoId'),
  74. 'title': source.get('title'),
  75. 'description': source.get('description'),
  76. 'thumbnail': source.get('highResImage') or source.get('medResImage'),
  77. 'uploader': source.get('username'),
  78. 'duration': int_or_none(source.get('length')),
  79. 'view_count': int_or_none(source.get('views')),
  80. 'age_limit': 18 if source.get('isMature') == 'true' or source.get('isSexy') == 'true' else 0,
  81. 'formats': self._extract_formats(source),
  82. }
  83. def _real_extract(self, url):
  84. mobj = re.match(self._VALID_URL, url)
  85. video_id = mobj.group('id')
  86. if video_id.startswith('v'):
  87. rsp = self._download_xml(
  88. r'http://www.veoh.com/api/findByPermalink?permalink=%s' % video_id, video_id, 'Downloading video XML')
  89. stat = rsp.get('stat')
  90. if stat == 'ok':
  91. return self._extract_video(rsp.find('./videoList/video'))
  92. elif stat == 'fail':
  93. raise ExtractorError(
  94. '%s said: %s' % (self.IE_NAME, rsp.find('./errorList/error').get('errorMessage')), expected=True)
  95. webpage = self._download_webpage(url, video_id)
  96. age_limit = 0
  97. if 'class="adultwarning-container"' in webpage:
  98. self.report_age_confirmation()
  99. age_limit = 18
  100. request = compat_urllib_request.Request(url)
  101. request.add_header('Cookie', 'confirmedAdult=true')
  102. webpage = self._download_webpage(request, video_id)
  103. m_youtube = re.search(r'http://www\.youtube\.com/v/(.*?)(\&|"|\?)', webpage)
  104. if m_youtube is not None:
  105. youtube_id = m_youtube.group(1)
  106. self.to_screen('%s: detected Youtube video.' % video_id)
  107. return self.url_result(youtube_id, 'Youtube')
  108. info = json.loads(
  109. self._search_regex(r'videoDetailsJSON = \'({.*?})\';', webpage, 'info').replace('\\\'', '\''))
  110. video = self._extract_video(info)
  111. video['age_limit'] = age_limit
  112. return video