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.

160 lines
5.5 KiB

11 years ago
11 years ago
11 years ago
10 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. int_or_none,
  8. unified_strdate,
  9. )
  10. class VineIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
  12. _TESTS = [{
  13. 'url': 'https://vine.co/v/b9KOOWX7HUx',
  14. 'md5': '2f36fed6235b16da96ce9b4dc890940d',
  15. 'info_dict': {
  16. 'id': 'b9KOOWX7HUx',
  17. 'ext': 'mp4',
  18. 'title': 'Chicken.',
  19. 'alt_title': 'Vine by Jack Dorsey',
  20. 'upload_date': '20130519',
  21. 'uploader': 'Jack Dorsey',
  22. 'uploader_id': '76',
  23. 'like_count': int,
  24. 'comment_count': int,
  25. 'repost_count': int,
  26. },
  27. }, {
  28. 'url': 'https://vine.co/v/MYxVapFvz2z',
  29. 'md5': '7b9a7cbc76734424ff942eb52c8f1065',
  30. 'info_dict': {
  31. 'id': 'MYxVapFvz2z',
  32. 'ext': 'mp4',
  33. 'title': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14',
  34. 'alt_title': 'Vine by Mars Ruiz',
  35. 'upload_date': '20140815',
  36. 'uploader': 'Mars Ruiz',
  37. 'uploader_id': '1102363502380728320',
  38. 'like_count': int,
  39. 'comment_count': int,
  40. 'repost_count': int,
  41. },
  42. }, {
  43. 'url': 'https://vine.co/v/bxVjBbZlPUH',
  44. 'md5': 'ea27decea3fa670625aac92771a96b73',
  45. 'info_dict': {
  46. 'id': 'bxVjBbZlPUH',
  47. 'ext': 'mp4',
  48. 'title': '#mw3 #ac130 #killcam #angelofdeath',
  49. 'alt_title': 'Vine by Z3k3',
  50. 'upload_date': '20130430',
  51. 'uploader': 'Z3k3',
  52. 'uploader_id': '936470460173008896',
  53. 'like_count': int,
  54. 'comment_count': int,
  55. 'repost_count': int,
  56. },
  57. }, {
  58. 'url': 'https://vine.co/oembed/MYxVapFvz2z.json',
  59. 'only_matching': True,
  60. }, {
  61. 'url': 'https://vine.co/v/e192BnZnZ9V',
  62. 'info_dict': {
  63. 'id': 'e192BnZnZ9V',
  64. 'ext': 'mp4',
  65. 'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2',
  66. 'alt_title': 'Vine by Pimry_zaa',
  67. 'upload_date': '20150705',
  68. 'uploader': 'Pimry_zaa',
  69. 'uploader_id': '1135760698325307392',
  70. 'like_count': int,
  71. 'comment_count': int,
  72. 'repost_count': int,
  73. },
  74. 'params': {
  75. 'skip_download': True,
  76. },
  77. }]
  78. def _real_extract(self, url):
  79. video_id = self._match_id(url)
  80. webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
  81. data = self._parse_json(
  82. self._search_regex(
  83. r'window\.POST_DATA\s*=\s*{\s*%s\s*:\s*({.+?})\s*};\s*</script>' % video_id,
  84. webpage, 'vine data'),
  85. video_id)
  86. formats = [{
  87. 'format_id': '%(format)s-%(rate)s' % f,
  88. 'vcodec': f.get('format'),
  89. 'quality': f.get('rate'),
  90. 'url': f['videoUrl'],
  91. } for f in data['videoUrls'] if f.get('videoUrl')]
  92. self._sort_formats(formats)
  93. username = data.get('username')
  94. return {
  95. 'id': video_id,
  96. 'title': data.get('description') or self._og_search_title(webpage),
  97. 'alt_title': 'Vine by %s' % username if username else self._og_search_description(webpage, default=None),
  98. 'thumbnail': data.get('thumbnailUrl'),
  99. 'upload_date': unified_strdate(data.get('created')),
  100. 'uploader': username,
  101. 'uploader_id': data.get('userIdStr'),
  102. 'like_count': int_or_none(data.get('likes', {}).get('count')),
  103. 'comment_count': int_or_none(data.get('comments', {}).get('count')),
  104. 'repost_count': int_or_none(data.get('reposts', {}).get('count')),
  105. 'formats': formats,
  106. }
  107. class VineUserIE(InfoExtractor):
  108. IE_NAME = 'vine:user'
  109. _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
  110. _VINE_BASE_URL = 'https://vine.co/'
  111. _TESTS = [
  112. {
  113. 'url': 'https://vine.co/Visa',
  114. 'info_dict': {
  115. 'id': 'Visa',
  116. },
  117. 'playlist_mincount': 46,
  118. },
  119. {
  120. 'url': 'https://vine.co/u/941705360593584128',
  121. 'only_matching': True,
  122. },
  123. ]
  124. def _real_extract(self, url):
  125. mobj = re.match(self._VALID_URL, url)
  126. user = mobj.group('user')
  127. u = mobj.group('u')
  128. profile_url = '%sapi/users/profiles/%s%s' % (
  129. self._VINE_BASE_URL, 'vanity/' if not u else '', user)
  130. profile_data = self._download_json(
  131. profile_url, user, note='Downloading user profile data')
  132. user_id = profile_data['data']['userId']
  133. timeline_data = []
  134. for pagenum in itertools.count(1):
  135. timeline_url = '%sapi/timelines/users/%s?page=%s&size=100' % (
  136. self._VINE_BASE_URL, user_id, pagenum)
  137. timeline_page = self._download_json(
  138. timeline_url, user, note='Downloading page %d' % pagenum)
  139. timeline_data.extend(timeline_page['data']['records'])
  140. if timeline_page['data']['nextPage'] is None:
  141. break
  142. entries = [
  143. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  144. return self.playlist_result(entries, user)