#!/usr/bin/env python

__all__ = ['vine_download']

from ..common import *

def vine_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
    html = get_html(url)

    vid = r1(r'vine.co/v/([^/]+)', url)
    title1 = r1(r'<meta property="twitter:title" content="([^"]*)"', html)
    title2 = r1(r'<meta property="twitter:description" content="([^"]*)"', html)
    title = "{} - {} [{}]".format(title1, title2, vid)
    stream = r1(r'<meta property="twitter:player:stream" content="([^"]*)">', html)
    mime, ext, size = url_info(stream)

    print_info(site_info, title, mime, size)
    if not info_only:
        download_urls([stream], title, ext, size, output_dir, merge=merge)

site_info = "Vine.co"
download = vine_download
download_playlist = playlist_not_supported('vine')

@@ -223,17 +223,16 @@
    title
-1
  = r1(r'
@@ -236,55 +236,29 @@
 (r'%3C
-meta property=%22twitter:title%22 content=%22(%5B%5E%22%5D*)%22
+title%3E(%5B%5E%3C%5D*)%3C/title%3E
 ', h
@@ -266,22 +266,22 @@
 ml)%0A    
-title2
+stream
  = r1(r'
@@ -308,19 +308,21 @@
 ter:
-description
+player:stream
 %22 co
@@ -336,16 +336,17 @@
 (%5B%5E%22%5D*)%22
+%3E
 ', html)
@@ -354,142 +354,102 @@
     
-title = %22%7B%7D - %7B%7D %5B%7B%7D%5D%22.format(title1, title2, vid)%0A    stream = r1(r'%3Cmeta property=%22twitter:player:stream%22 content=
+if not stream: # https://vine.co/v/.../card%0A        stream = r1(r'%22videoUrl%22:
 %22(%5B%5E%22%5D
-*
++
 )%22
-%3E
 ', html)
 %0A   
@@ -440,24 +440,45 @@
 %5D+)%22', html)
+.replace('%5C%5C/', '/')%0A
 %0A    mime, e

support card URLs