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.

98 lines
3.1 KiB

11 years ago
11 years ago
11 years ago
11 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. '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<user>[^/]+)/?(\?.*)?$'
  56. _VINE_BASE_URL = "https://vine.co/"
  57. _TEST = {
  58. 'url': 'https://vine.co/Visa',
  59. 'info_dict': {
  60. 'id': 'Visa',
  61. },
  62. 'playlist_mincount': 47,
  63. }
  64. def _real_extract(self, url):
  65. mobj = re.match(self._VALID_URL, url)
  66. user = mobj.group('user')
  67. profile_url = "%sapi/users/profiles/vanity/%s" % (
  68. self._VINE_BASE_URL, user)
  69. profile_data = self._download_json(
  70. profile_url, user, note='Downloading user profile data')
  71. user_id = profile_data['data']['userId']
  72. timeline_data = []
  73. for pagenum in itertools.count(1):
  74. timeline_url = "%sapi/timelines/users/%s?page=%s" % (
  75. self._VINE_BASE_URL, user_id, pagenum)
  76. timeline_page = self._download_json(
  77. timeline_url, user, note='Downloading page %d' % pagenum)
  78. timeline_data.extend(timeline_page['data']['records'])
  79. if timeline_page['data']['nextPage'] is None:
  80. break
  81. entries = [
  82. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  83. return self.playlist_result(entries, user)