#!/usr/bin/env python

__all__ = ['miomio_download']

from ..common import *

from .tudou import tudou_download_by_id
from .youku import youku_download_by_id

def miomio_download(url, output_dir = '.', merge = True, info_only = False):
    html = get_html(url)
    
    title = r1(r'<meta name="description" content="([^"]*)"', html)
    flashvars = r1(r'flashvars="(type=[^"]*)"', html)
    
    t = r1(r'type=(\w+)', flashvars)
    id = r1(r'vid=([^"]+)', flashvars)
    if t == 'youku':
        youku_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only)
    elif t == 'tudou':
        tudou_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only)
    else:
        raise NotImplementedError(flashvars)

site_info = "MioMio.tv"
download = miomio_download
download_playlist = playlist_not_supported('miomio')

@@ -71,16 +71,55 @@
 port *%0A%0A
+from .sina import sina_download_by_vid%0A
 from .tu
@@ -564,35 +564,33 @@
 itle, output_dir
- = 
+=
 output_dir, merg
@@ -582,35 +582,33 @@
 utput_dir, merge
- = 
+=
 merge, info_only
@@ -599,35 +599,33 @@
 merge, info_only
- = 
+=
 info_only)%0A    e
@@ -692,19 +692,136 @@
 tput_dir
- = 
+=output_dir, merge=merge, info_only=info_only)%0A    elif t == 'sina':%0A        sina_download_by_vid(id, title, output_dir=
 output_d
@@ -829,19 +829,17 @@
 r, merge
- = 
+=
 merge, i
@@ -846,19 +846,17 @@
 nfo_only
- = 
+=
 info_onl

add Sina as video source