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.

91 lines
2.9 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. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. user = mobj.group('user')
  60. profile_url = "%sapi/users/profiles/vanity/%s" % (
  61. self._VINE_BASE_URL, user)
  62. profile_data = self._download_json(
  63. profile_url, user, note='Downloading user profile data')
  64. user_id = profile_data['data']['userId']
  65. timeline_data = []
  66. for pagenum in itertools.count(1):
  67. timeline_url = "%sapi/timelines/users/%s?page=%s" % (
  68. self._VINE_BASE_URL, user_id, pagenum)
  69. timeline_page = self._download_json(
  70. timeline_url, user, note='Downloading page %d' % pagenum)
  71. timeline_data.extend(timeline_page['data']['records'])
  72. if timeline_page['data']['nextPage'] is None:
  73. break
  74. entries = [
  75. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  76. return self.playlist_result(entries, user)