veoh.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import functools
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. OnDemandPagedList,
  7. int_or_none,
  8. parse_duration,
  9. qualities,
  10. try_get,
  11. )
  12. class VeohIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?veoh\.com/(?:watch|videos|embed|iphone/#_Watch)/(?P<id>(?:v|e|yapi-)[\da-zA-Z]+)'
  14. _TESTS = [{
  15. 'url': 'http://www.veoh.com/watch/v56314296nk7Zdmz3',
  16. 'md5': '620e68e6a3cff80086df3348426c9ca3',
  17. 'info_dict': {
  18. 'id': 'v56314296nk7Zdmz3',
  19. 'ext': 'mp4',
  20. 'title': 'Straight Backs Are Stronger',
  21. 'description': 'md5:203f976279939a6dc664d4001e13f5f4',
  22. 'thumbnail': 're:https://fcache\\.veoh\\.com/file/f/th56314296\\.jpg(\\?.*)?',
  23. 'uploader': 'LUMOback',
  24. 'duration': 46,
  25. 'view_count': int,
  26. 'average_rating': int,
  27. 'comment_count': int,
  28. 'age_limit': 0,
  29. 'categories': ['technology_and_gaming'],
  30. 'tags': ['posture', 'posture', 'sensor', 'back', 'pain', 'wearable', 'tech', 'lumo'],
  31. },
  32. }, {
  33. 'url': 'http://www.veoh.com/embed/v56314296nk7Zdmz3',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'http://www.veoh.com/watch/v27701988pbTc4wzN?h1=Chile+workers+cover+up+to+avoid+skin+damage',
  37. 'md5': '4a6ff84b87d536a6a71e6aa6c0ad07fa',
  38. 'info_dict': {
  39. 'id': '27701988',
  40. 'ext': 'mp4',
  41. 'title': 'Chile workers cover up to avoid skin damage',
  42. 'description': 'md5:2bd151625a60a32822873efc246ba20d',
  43. 'uploader': 'afp-news',
  44. 'duration': 123,
  45. },
  46. 'skip': 'This video has been deleted.',
  47. }, {
  48. 'url': 'http://www.veoh.com/watch/v69525809F6Nc4frX',
  49. 'md5': '4fde7b9e33577bab2f2f8f260e30e979',
  50. 'note': 'Embedded ooyala video',
  51. 'info_dict': {
  52. 'id': '69525809',
  53. 'ext': 'mp4',
  54. 'title': 'Doctors Alter Plan For Preteen\'s Weight Loss Surgery',
  55. 'description': 'md5:f5a11c51f8fb51d2315bca0937526891',
  56. 'uploader': 'newsy-videos',
  57. },
  58. 'skip': 'This video has been deleted.',
  59. }, {
  60. 'url': 'http://www.veoh.com/watch/e152215AJxZktGS',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'https://www.veoh.com/videos/v16374379WA437rMH',
  64. 'md5': 'cceb73f3909063d64f4b93d4defca1b3',
  65. 'info_dict': {
  66. 'id': 'v16374379WA437rMH',
  67. 'ext': 'mp4',
  68. 'title': 'Phantasmagoria 2, pt. 1-3',
  69. 'description': 'Phantasmagoria: a Puzzle of Flesh',
  70. 'thumbnail': 're:https://fcache\\.veoh\\.com/file/f/th16374379\\.jpg(\\?.*)?',
  71. 'uploader': 'davidspackage',
  72. 'duration': 968,
  73. 'view_count': int,
  74. 'average_rating': int,
  75. 'comment_count': int,
  76. 'age_limit': 18,
  77. 'categories': ['technology_and_gaming', 'gaming'],
  78. 'tags': ['puzzle', 'of', 'flesh'],
  79. },
  80. }]
  81. def _real_extract(self, url):
  82. video_id = self._match_id(url)
  83. metadata = self._download_json(
  84. 'https://www.veoh.com/watch/getVideo/' + video_id,
  85. video_id)
  86. video = metadata['video']
  87. title = video['title']
  88. thumbnail_url = None
  89. q = qualities(['Regular', 'HQ'])
  90. formats = []
  91. for f_id, f_url in video.get('src', {}).items():
  92. if not f_url:
  93. continue
  94. if f_id == 'poster':
  95. thumbnail_url = f_url
  96. else:
  97. formats.append({
  98. 'format_id': f_id,
  99. 'quality': q(f_id),
  100. 'url': f_url,
  101. })
  102. categories = metadata.get('categoryPath')
  103. if not categories:
  104. category = try_get(video, lambda x: x['category'].strip().removeprefix('category_'))
  105. categories = [category] if category else None
  106. tags = video.get('tags')
  107. return {
  108. 'id': video_id,
  109. 'title': title,
  110. 'description': video.get('description'),
  111. 'thumbnail': thumbnail_url,
  112. 'uploader': video.get('author', {}).get('nickname'),
  113. 'duration': int_or_none(video.get('lengthBySec')) or parse_duration(video.get('length')),
  114. 'view_count': int_or_none(video.get('views')),
  115. 'formats': formats,
  116. 'average_rating': int_or_none(video.get('rating')),
  117. 'comment_count': int_or_none(video.get('numOfComments')),
  118. 'age_limit': 18 if video.get('contentRatingId') == 2 else 0,
  119. 'categories': categories,
  120. 'tags': tags.split(', ') if tags else None,
  121. }
  122. class VeohUserIE(VeohIE): # XXX: Do not subclass from concrete IE
  123. _VALID_URL = r'https?://(?:www\.)?veoh\.com/users/(?P<id>[\w-]+)'
  124. IE_NAME = 'veoh:user'
  125. _TESTS = [
  126. {
  127. 'url': 'https://www.veoh.com/users/valentinazoe',
  128. 'info_dict': {
  129. 'id': 'valentinazoe',
  130. 'title': 'valentinazoe (Uploads)',
  131. },
  132. 'playlist_mincount': 75,
  133. },
  134. {
  135. 'url': 'https://www.veoh.com/users/PiensaLibre',
  136. 'info_dict': {
  137. 'id': 'PiensaLibre',
  138. 'title': 'PiensaLibre (Uploads)',
  139. },
  140. 'playlist_mincount': 2,
  141. }]
  142. _PAGE_SIZE = 16
  143. def _fetch_page(self, uploader, page):
  144. response = self._download_json(
  145. 'https://www.veoh.com/users/published/videos', uploader,
  146. note=f'Downloading videos page {page + 1}',
  147. headers={
  148. 'x-csrf-token': self._TOKEN,
  149. 'content-type': 'application/json;charset=UTF-8',
  150. },
  151. data=json.dumps({
  152. 'username': uploader,
  153. 'maxResults': self._PAGE_SIZE,
  154. 'page': page + 1,
  155. 'requestName': 'userPage',
  156. }).encode())
  157. if not response.get('success'):
  158. raise ExtractorError(response['message'])
  159. for video in response['videos']:
  160. yield self.url_result(f'https://www.veoh.com/watch/{video["permalinkId"]}', VeohIE,
  161. video['permalinkId'], video.get('title'))
  162. def _real_initialize(self):
  163. webpage = self._download_webpage(
  164. 'https://www.veoh.com', None, note='Downloading authorization token')
  165. self._TOKEN = self._search_regex(
  166. r'csrfToken:\s*(["\'])(?P<token>[0-9a-zA-Z]{40})\1', webpage,
  167. 'request token', group='token')
  168. def _real_extract(self, url):
  169. uploader = self._match_id(url)
  170. return self.playlist_result(OnDemandPagedList(
  171. functools.partial(self._fetch_page, uploader),
  172. self._PAGE_SIZE), uploader, f'{uploader} (Uploads)')