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.

132 lines
4.5 KiB

11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import itertools
  4. from .common import InfoExtractor
  5. from ..utils import unified_strdate
  6. class VineIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
  8. _TESTS = [{
  9. 'url': 'https://vine.co/v/b9KOOWX7HUx',
  10. 'md5': '2f36fed6235b16da96ce9b4dc890940d',
  11. 'info_dict': {
  12. 'id': 'b9KOOWX7HUx',
  13. 'ext': 'mp4',
  14. 'title': 'Chicken.',
  15. 'alt_title': 'Vine by Jack Dorsey',
  16. 'description': 'Chicken.',
  17. 'upload_date': '20130519',
  18. 'uploader': 'Jack Dorsey',
  19. 'uploader_id': '76',
  20. },
  21. }, {
  22. 'url': 'https://vine.co/v/MYxVapFvz2z',
  23. 'md5': '7b9a7cbc76734424ff942eb52c8f1065',
  24. 'info_dict': {
  25. 'id': 'MYxVapFvz2z',
  26. 'ext': 'mp4',
  27. 'title': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14',
  28. 'alt_title': 'Vine by Luna',
  29. 'description': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14',
  30. 'upload_date': '20140815',
  31. 'uploader': 'Luna',
  32. 'uploader_id': '1102363502380728320',
  33. },
  34. }, {
  35. 'url': 'https://vine.co/v/bxVjBbZlPUH',
  36. 'md5': 'ea27decea3fa670625aac92771a96b73',
  37. 'info_dict': {
  38. 'id': 'bxVjBbZlPUH',
  39. 'ext': 'mp4',
  40. 'title': '#mw3 #ac130 #killcam #angelofdeath',
  41. 'alt_title': 'Vine by Z3k3',
  42. 'description': '#mw3 #ac130 #killcam #angelofdeath',
  43. 'upload_date': '20130430',
  44. 'uploader': 'Z3k3',
  45. 'uploader_id': '936470460173008896',
  46. },
  47. }, {
  48. 'url': 'https://vine.co/oembed/MYxVapFvz2z.json',
  49. 'only_matching': True,
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
  54. data = self._parse_json(
  55. self._html_search_regex(
  56. r'window\.POST_DATA = { %s: ({.+?}) };\s*</script>' % video_id,
  57. webpage, 'vine data'),
  58. video_id)
  59. formats = [{
  60. 'format_id': '%(format)s-%(rate)s' % f,
  61. 'vcodec': f['format'],
  62. 'quality': f['rate'],
  63. 'url': f['videoUrl'],
  64. } for f in data['videoUrls']]
  65. self._sort_formats(formats)
  66. return {
  67. 'id': video_id,
  68. 'title': self._og_search_title(webpage),
  69. 'alt_title': self._og_search_description(webpage, default=None),
  70. 'description': data['description'],
  71. 'thumbnail': data['thumbnailUrl'],
  72. 'upload_date': unified_strdate(data['created']),
  73. 'uploader': data['username'],
  74. 'uploader_id': data['userIdStr'],
  75. 'like_count': data['likes']['count'],
  76. 'comment_count': data['comments']['count'],
  77. 'repost_count': data['reposts']['count'],
  78. 'formats': formats,
  79. }
  80. class VineUserIE(InfoExtractor):
  81. IE_NAME = 'vine:user'
  82. _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
  83. _VINE_BASE_URL = "https://vine.co/"
  84. _TESTS = [
  85. {
  86. 'url': 'https://vine.co/Visa',
  87. 'info_dict': {
  88. 'id': 'Visa',
  89. },
  90. 'playlist_mincount': 46,
  91. },
  92. {
  93. 'url': 'https://vine.co/u/941705360593584128',
  94. 'only_matching': True,
  95. },
  96. ]
  97. def _real_extract(self, url):
  98. mobj = re.match(self._VALID_URL, url)
  99. user = mobj.group('user')
  100. u = mobj.group('u')
  101. profile_url = "%sapi/users/profiles/%s%s" % (
  102. self._VINE_BASE_URL, 'vanity/' if not u else '', user)
  103. profile_data = self._download_json(
  104. profile_url, user, note='Downloading user profile data')
  105. user_id = profile_data['data']['userId']
  106. timeline_data = []
  107. for pagenum in itertools.count(1):
  108. timeline_url = "%sapi/timelines/users/%s?page=%s&size=100" % (
  109. self._VINE_BASE_URL, user_id, pagenum)
  110. timeline_page = self._download_json(
  111. timeline_url, user, note='Downloading page %d' % pagenum)
  112. timeline_data.extend(timeline_page['data']['records'])
  113. if timeline_page['data']['nextPage'] is None:
  114. break
  115. entries = [
  116. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  117. return self.playlist_result(entries, user)