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.

154 lines
5.2 KiB

11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. determine_ext,
  8. int_or_none,
  9. unified_timestamp,
  10. )
  11. class VineIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
  13. _TESTS = [{
  14. 'url': 'https://vine.co/v/b9KOOWX7HUx',
  15. 'md5': '2f36fed6235b16da96ce9b4dc890940d',
  16. 'info_dict': {
  17. 'id': 'b9KOOWX7HUx',
  18. 'ext': 'mp4',
  19. 'title': 'Chicken.',
  20. 'alt_title': 'Vine by Jack',
  21. 'timestamp': 1368997951,
  22. 'upload_date': '20130519',
  23. 'uploader': 'Jack',
  24. 'uploader_id': '76',
  25. 'view_count': int,
  26. 'like_count': int,
  27. 'comment_count': int,
  28. 'repost_count': int,
  29. },
  30. }, {
  31. 'url': 'https://vine.co/v/e192BnZnZ9V',
  32. 'info_dict': {
  33. 'id': 'e192BnZnZ9V',
  34. 'ext': 'mp4',
  35. 'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2',
  36. 'alt_title': 'Vine by Pimry_zaa',
  37. 'timestamp': 1436057405,
  38. 'upload_date': '20150705',
  39. 'uploader': 'Pimry_zaa',
  40. 'uploader_id': '1135760698325307392',
  41. 'view_count': int,
  42. 'like_count': int,
  43. 'comment_count': int,
  44. 'repost_count': int,
  45. },
  46. 'params': {
  47. 'skip_download': True,
  48. },
  49. }, {
  50. 'url': 'https://vine.co/v/MYxVapFvz2z',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'https://vine.co/v/bxVjBbZlPUH',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'https://vine.co/oembed/MYxVapFvz2z.json',
  57. 'only_matching': True,
  58. }]
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url)
  61. data = self._download_json(
  62. 'https://archive.vine.co/posts/%s.json' % video_id, video_id)
  63. def video_url(kind):
  64. for url_suffix in ('Url', 'URL'):
  65. format_url = data.get('video%s%s' % (kind, url_suffix))
  66. if format_url:
  67. return format_url
  68. formats = []
  69. for quality, format_id in enumerate(('low', '', 'dash')):
  70. format_url = video_url(format_id.capitalize())
  71. if not format_url:
  72. continue
  73. # DASH link returns plain mp4
  74. if format_id == 'dash' and determine_ext(format_url) == 'mpd':
  75. formats.extend(self._extract_mpd_formats(
  76. format_url, video_id, mpd_id='dash', fatal=False))
  77. else:
  78. formats.append({
  79. 'url': format_url,
  80. 'format_id': format_id or 'standard',
  81. 'quality': quality,
  82. })
  83. self._sort_formats(formats)
  84. username = data.get('username')
  85. alt_title = 'Vine by %s' % username if username else None
  86. return {
  87. 'id': video_id,
  88. 'title': data.get('description') or alt_title or 'Vine video',
  89. 'alt_title': alt_title,
  90. 'thumbnail': data.get('thumbnailUrl'),
  91. 'timestamp': unified_timestamp(data.get('created')),
  92. 'uploader': username,
  93. 'uploader_id': data.get('userIdStr'),
  94. 'view_count': int_or_none(data.get('loops')),
  95. 'like_count': int_or_none(data.get('likes')),
  96. 'comment_count': int_or_none(data.get('comments')),
  97. 'repost_count': int_or_none(data.get('reposts')),
  98. 'formats': formats,
  99. }
  100. class VineUserIE(InfoExtractor):
  101. IE_NAME = 'vine:user'
  102. _VALID_URL = r'https?://vine\.co/(?P<u>u/)?(?P<user>[^/]+)'
  103. _VINE_BASE_URL = 'https://vine.co/'
  104. _TESTS = [{
  105. 'url': 'https://vine.co/itsruthb',
  106. 'info_dict': {
  107. 'id': 'itsruthb',
  108. 'title': 'Ruth B',
  109. 'description': '| Instagram/Twitter: itsruthb | still a lost boy from neverland',
  110. },
  111. 'playlist_mincount': 611,
  112. }, {
  113. 'url': 'https://vine.co/u/942914934646415360',
  114. 'only_matching': True,
  115. }]
  116. @classmethod
  117. def suitable(cls, url):
  118. return False if VineIE.suitable(url) else super(VineUserIE, cls).suitable(url)
  119. def _real_extract(self, url):
  120. mobj = re.match(self._VALID_URL, url)
  121. user = mobj.group('user')
  122. u = mobj.group('u')
  123. profile_url = '%sapi/users/profiles/%s%s' % (
  124. self._VINE_BASE_URL, 'vanity/' if not u else '', user)
  125. profile_data = self._download_json(
  126. profile_url, user, note='Downloading user profile data')
  127. data = profile_data['data']
  128. user_id = data.get('userId') or data['userIdStr']
  129. profile = self._download_json(
  130. 'https://archive.vine.co/profiles/%s.json' % user_id, user_id)
  131. entries = [
  132. self.url_result(
  133. 'https://vine.co/v/%s' % post_id, ie='Vine', video_id=post_id)
  134. for post_id in profile['posts']
  135. if post_id and isinstance(post_id, compat_str)]
  136. return self.playlist_result(
  137. entries, user, profile.get('username'), profile.get('description'))