vine.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from __future__ import unicode_literals
  2. import re
  3. import itertools
  4. from .common import InfoExtractor
  5. from ..utils import unified_strdate
  6. class VineIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
  8. _TESTS = [{
  9. 'url': 'https://vine.co/v/b9KOOWX7HUx',
  10. 'md5': '2f36fed6235b16da96ce9b4dc890940d',
  11. 'info_dict': {
  12. 'id': 'b9KOOWX7HUx',
  13. 'ext': 'mp4',
  14. 'title': 'Chicken.',
  15. 'alt_title': 'Vine by Jack Dorsey',
  16. 'description': 'Chicken.',
  17. 'upload_date': '20130519',
  18. 'uploader': 'Jack Dorsey',
  19. 'uploader_id': '76',
  20. },
  21. }, {
  22. 'url': 'https://vine.co/v/MYxVapFvz2z',
  23. 'md5': '7b9a7cbc76734424ff942eb52c8f1065',
  24. 'info_dict': {
  25. 'id': 'MYxVapFvz2z',
  26. 'ext': 'mp4',
  27. 'title': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14',
  28. 'alt_title': 'Vine by Mars Ruiz',
  29. 'description': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14',
  30. 'upload_date': '20140815',
  31. 'uploader': 'Mars Ruiz',
  32. 'uploader_id': '1102363502380728320',
  33. },
  34. }, {
  35. 'url': 'https://vine.co/v/bxVjBbZlPUH',
  36. 'md5': 'ea27decea3fa670625aac92771a96b73',
  37. 'info_dict': {
  38. 'id': 'bxVjBbZlPUH',
  39. 'ext': 'mp4',
  40. 'title': '#mw3 #ac130 #killcam #angelofdeath',
  41. 'alt_title': 'Vine by Z3k3',
  42. 'description': '#mw3 #ac130 #killcam #angelofdeath',
  43. 'upload_date': '20130430',
  44. 'uploader': 'Z3k3',
  45. 'uploader_id': '936470460173008896',
  46. },
  47. }, {
  48. 'url': 'https://vine.co/oembed/MYxVapFvz2z.json',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'https://vine.co/v/e192BnZnZ9V',
  52. 'info_dict': {
  53. 'id': 'e192BnZnZ9V',
  54. 'ext': 'mp4',
  55. 'title': u'\u0e22\u0e34\u0e49\u0e21~ \u0e40\u0e02\u0e34\u0e19~ \u0e2d\u0e32\u0e22~ \u0e19\u0e48\u0e32\u0e23\u0e49\u0e32\u0e01\u0e2d\u0e49\u0e30 >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2',
  56. 'alt_title': 'Vine by Pimry_zaa',
  57. 'description': u'\u0e22\u0e34\u0e49\u0e21~ \u0e40\u0e02\u0e34\u0e19~ \u0e2d\u0e32\u0e22~ \u0e19\u0e48\u0e32\u0e23\u0e49\u0e32\u0e01\u0e2d\u0e49\u0e30 >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2',
  58. 'upload_date': '20150705',
  59. 'uploader': 'Pimry_zaa',
  60. 'uploader_id': '1135760698325307392',
  61. },
  62. 'params': {
  63. 'skip_download': True,
  64. },
  65. }]
  66. def _real_extract(self, url):
  67. video_id = self._match_id(url)
  68. webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
  69. data = self._parse_json(
  70. self._html_search_regex(
  71. r'window\.POST_DATA = { %s: ({.+?}) };\s*</script>' % video_id,
  72. webpage, 'vine data'),
  73. video_id)
  74. formats = [{
  75. 'format_id': '%(format)s-%(rate)s' % f,
  76. 'vcodec': f['format'],
  77. 'quality': f['rate'],
  78. 'url': f['videoUrl'],
  79. } for f in data['videoUrls']]
  80. self._sort_formats(formats)
  81. return {
  82. 'id': video_id,
  83. 'title': data['description'],
  84. 'alt_title': 'Vine by %s' % data['username'],
  85. 'description': data['description'],
  86. 'thumbnail': data['thumbnailUrl'],
  87. 'upload_date': unified_strdate(data['created']),
  88. 'uploader': data['username'],
  89. 'uploader_id': data['userIdStr'],
  90. 'like_count': data['likes']['count'],
  91. 'comment_count': data['comments']['count'],
  92. 'repost_count': data['reposts']['count'],
  93. 'formats': formats,
  94. }
  95. class VineUserIE(InfoExtractor):
  96. IE_NAME = 'vine:user'
  97. _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
  98. _VINE_BASE_URL = "https://vine.co/"
  99. _TESTS = [
  100. {
  101. 'url': 'https://vine.co/Visa',
  102. 'info_dict': {
  103. 'id': 'Visa',
  104. },
  105. 'playlist_mincount': 46,
  106. },
  107. {
  108. 'url': 'https://vine.co/u/941705360593584128',
  109. 'only_matching': True,
  110. },
  111. ]
  112. def _real_extract(self, url):
  113. mobj = re.match(self._VALID_URL, url)
  114. user = mobj.group('user')
  115. u = mobj.group('u')
  116. profile_url = "%sapi/users/profiles/%s%s" % (
  117. self._VINE_BASE_URL, 'vanity/' if not u else '', user)
  118. profile_data = self._download_json(
  119. profile_url, user, note='Downloading user profile data')
  120. user_id = profile_data['data']['userId']
  121. timeline_data = []
  122. for pagenum in itertools.count(1):
  123. timeline_url = "%sapi/timelines/users/%s?page=%s&size=100" % (
  124. self._VINE_BASE_URL, user_id, pagenum)
  125. timeline_page = self._download_json(
  126. timeline_url, user, note='Downloading page %d' % pagenum)
  127. timeline_data.extend(timeline_page['data']['records'])
  128. if timeline_page['data']['nextPage'] is None:
  129. break
  130. entries = [
  131. self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
  132. return self.playlist_result(entries, user)