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.

152 lines
5.1 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. import itertools
  5. from .common import InfoExtractor
  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. return {
  86. 'id': video_id,
  87. 'title': data.get('description'),
  88. 'alt_title': 'Vine by %s' % username if username else None,
  89. 'thumbnail': data.get('thumbnailUrl'),
  90. 'timestamp': unified_timestamp(data.get('created')),
  91. 'uploader': username,
  92. 'uploader_id': data.get('userIdStr'),
  93. 'view_count': int_or_none(data.get('loops')),
  94. 'like_count': int_or_none(data.get('likes')),
  95. 'comment_count': int_or_none(data.get('comments')),
  96. 'repost_count': int_or_none(data.get('reposts')),
  97. 'formats': formats,
  98. }
  99. class VineUserIE(InfoExtractor):
  100. IE_NAME = 'vine:user'
  101. _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
  102. _VINE_BASE_URL = 'https://vine.co/'
  103. _TESTS = [
  104. {
  105. 'url': 'https://vine.co/Visa',
  106. 'info_dict': {
  107. 'id': 'Visa',
  108. },
  109. 'playlist_mincount': 46,
  110. },
  111. {
  112. 'url': 'https://vine.co/u/941705360593584128',
  113. 'only_matching': True,
  114. },
  115. ]
  116. def _real_extract(self, url):
  117. mobj = re.match(self._VALID_URL, url)
  118. user = mobj.group('user')
  119. u = mobj.group('u')
  120. profile_url = '%sapi/users/profiles/%s%s' % (
  121. self._VINE_BASE_URL, 'vanity/' if not u else '', user)
  122. profile_data = self._download_json(
  123. profile_url, user, note='Downloading user profile data')
  124. user_id = profile_data['data']['userId']
  125. timeline_data = []
  126. for pagenum in itertools.count(1):
  127. timeline_url = '%sapi/timelines/users/%s?page=%s&size=100' % (
  128. self._VINE_BASE_URL, user_id, pagenum)
  129. timeline_page = self._download_json(
  130. timeline_url, user, note='Downloading page %d' % pagenum)
  131. timeline_data.extend(timeline_page['data']['records'])
  132. if timeline_page['data']['nextPage'] is None:
  133. break
  134. entries = [
  135. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  136. return self.playlist_result(entries, user)