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.

101 lines
3.3 KiB

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