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.

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