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.

105 lines
3.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. import itertools
  5. from .common import InfoExtractor
  6. from ..utils import unified_strdate
  7. class VineIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?vine\.co/v/(?P<id>\w+)'
  9. _TEST = {
  10. 'url': 'https://vine.co/v/b9KOOWX7HUx',
  11. 'md5': '2f36fed6235b16da96ce9b4dc890940d',
  12. 'info_dict': {
  13. 'id': 'b9KOOWX7HUx',
  14. 'ext': 'mp4',
  15. 'title': 'Chicken.',
  16. 'description': 'Chicken.',
  17. 'upload_date': '20130519',
  18. 'uploader': 'Jack Dorsey',
  19. 'uploader_id': '76',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
  26. data = json.loads(self._html_search_regex(
  27. r'window\.POST_DATA = { %s: ({.+?}) }' % video_id, webpage, 'vine data'))
  28. formats = [
  29. {
  30. 'url': data['videoLowURL'],
  31. 'ext': 'mp4',
  32. 'format_id': 'low',
  33. },
  34. {
  35. 'url': data['videoUrl'],
  36. 'ext': 'mp4',
  37. 'format_id': 'standard',
  38. }
  39. ]
  40. return {
  41. 'id': video_id,
  42. 'title': self._og_search_title(webpage),
  43. 'description': data['description'],
  44. 'thumbnail': data['thumbnailUrl'],
  45. 'upload_date': unified_strdate(data['created']),
  46. 'uploader': data['username'],
  47. 'uploader_id': data['userIdStr'],
  48. 'like_count': data['likes']['count'],
  49. 'comment_count': data['comments']['count'],
  50. 'repost_count': data['reposts']['count'],
  51. 'formats': formats,
  52. }
  53. class VineUserIE(InfoExtractor):
  54. IE_NAME = 'vine:user'
  55. _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
  56. _VINE_BASE_URL = "https://vine.co/"
  57. _TESTS = [
  58. {
  59. 'url': 'https://vine.co/Visa',
  60. 'info_dict': {
  61. 'id': 'Visa',
  62. },
  63. 'playlist_mincount': 46,
  64. },
  65. {
  66. 'url': 'https://vine.co/u/941705360593584128',
  67. 'only_matching': True,
  68. },
  69. ]
  70. def _real_extract(self, url):
  71. mobj = re.match(self._VALID_URL, url)
  72. user = mobj.group('user')
  73. u = mobj.group('u')
  74. profile_url = "%sapi/users/profiles/%s%s" % (
  75. self._VINE_BASE_URL, 'vanity/' if not u else '', user)
  76. profile_data = self._download_json(
  77. profile_url, user, note='Downloading user profile data')
  78. user_id = profile_data['data']['userId']
  79. timeline_data = []
  80. for pagenum in itertools.count(1):
  81. timeline_url = "%sapi/timelines/users/%s?page=%s&size=100" % (
  82. self._VINE_BASE_URL, user_id, pagenum)
  83. timeline_page = self._download_json(
  84. timeline_url, user, note='Downloading page %d' % pagenum)
  85. timeline_data.extend(timeline_page['data']['records'])
  86. if timeline_page['data']['nextPage'] is None:
  87. break
  88. entries = [
  89. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  90. return self.playlist_result(entries, user)