102 lines
3.3 KiB

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