you-get/src/you_get/extractors/vine.py

36 lines
1.1 KiB
Python
Raw Normal View History

2013-03-22 07:31:28 +04:00
#!/usr/bin/env python
__all__ = ['vine_download']
from ..common import *
2017-03-22 19:16:36 +03:00
import json
2013-03-22 07:31:28 +04:00
def vine_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
2013-03-22 07:31:28 +04:00
html = get_html(url)
2014-02-15 00:19:43 +04:00
2015-06-13 17:52:11 +03:00
vid = r1(r'vine.co/v/([^/]+)', url)
2015-11-09 18:45:32 +03:00
title = r1(r'<title>([^<]*)</title>', html)
2015-06-13 17:52:11 +03:00
stream = r1(r'<meta property="twitter:player:stream" content="([^"]*)">', html)
2015-11-09 18:45:32 +03:00
if not stream: # https://vine.co/v/.../card
2017-03-22 19:16:36 +03:00
stream = r1(r'"videoUrl":"([^"]+)"', html)
if stream:
stream = stream.replace('\\/', '/')
else:
if url[-1] == '/':
url = url[:-1]
video_id = url.split('/')[-1]
posts_url = 'https://archive.vine.co/posts/' + video_id + '.json'
json_data = json.loads(get_content(posts_url))
stream = json_data['videoDashUrl']
title = json_data['description']
2015-11-09 18:45:32 +03:00
2015-06-13 17:52:11 +03:00
mime, ext, size = url_info(stream)
2014-02-15 00:19:43 +04:00
2015-06-13 17:52:11 +03:00
print_info(site_info, title, mime, size)
2013-03-22 07:31:28 +04:00
if not info_only:
2015-06-13 17:52:11 +03:00
download_urls([stream], title, ext, size, output_dir, merge=merge)
2013-03-22 07:31:28 +04:00
site_info = "Vine.co"
download = vine_download
download_playlist = playlist_not_supported('vine')