def btdigg(url, mstr=''):
    if url in 'search':
        url = 'http://btdigg.org/search?q='
        if not mstr:
            kb = Keyboard('',u'请输入搜索关键字')
            kb.doModal()
            if not kb.isConfirmed(): return
            mstr = kb.getText()
            if not mstr: return
        url = url + urllib2.quote(mstr)
    else:
        url = 'http://btdigg.org' + url

    rsp = hc.urlopen(url)
    rpat = re.compile(
        r'"idx">.*?>([^<]+)</a>.*?href="(magnet.*?)".*?Size:.*?">(.*?)<')
    items = rpat.findall(rsp)

    menus = [
        {'label': '%d.%s[%s]' % (s+1, v[0], v[2].replace('&nbsp;', '')),
         'path': plugin.url_for('playlxmagnet', magnet=v[1])}
        for s, v in enumerate(items)]
    ppat = re.compile(r'%s%s' % (
        'class="pager".*?(?:href="(/search.*?)")?>←.*?>',
        '(\d+/\d+).*?(?:href="(/search.*?)")?>Next'))

    pgs = ppat.findall(rsp)

    for s, p in enumerate((pgs[0][0], pgs[0][2])):
        if p:
            menus.append({'label': '上一页' if not s else '下一页',
                          'path': plugin.url_for('btdigg', url=p)})
    menus.insert(0, {'label': '[当前页%s页总共]返回上级目录' % pgs[0][1],
                     'path': plugin.url_for('index')})
    return menus
def dbactor(sstr, page):
    urlpre = 'http://movie.douban.com/subject_search'
    if 'none' in sstr:
        kb = Keyboard('',u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed(): return
        sstr = kb.getText()
    url = '%s/?search_text=%s&start=%s' % (urlpre ,sstr, str(int(page)*15))
    rsp = _http(url)
    rtxt = r'%s%s' % ('tr class="item".*?nbg".*?src="(.*?)" alt="(.*?)"',
                      '.*?class="pl">(.*?)</p>.*?rating_nums">(.*?)<')
    patt = re.compile(rtxt, re.S)
    mitems = patt.findall(rsp)
    if not mitems: return
    menus = [{'label': '{0}. {1}[{2}][{3}]'.format(s, i[1], i[3], i[2]),
             'path': plugin.url_for('btsearch', url='search', mstr=i[1]),
             'thumbnail': i[0],
         } for s, i in enumerate(mitems)]

    count = re.findall(r'class="count">.*?(\d+).*?</span>', rsp)
    count = int(count[0])
    page = int(page)
    if page>0:
        menus.append({
            'label': '上一页',
            'path': plugin.url_for('dbactor', sstr=sstr, page=page-1)})
    if (page+1)*15 < count:
        menus.append({
            'label': '下一页',
            'path': plugin.url_for('dbactor', sstr=sstr, page=page+1)})

    menus.insert(0, {
        'label': '【当前页%s/总共页%s】【放回上级菜单】' % (page+1, (count+14)//15),
        'path': plugin.url_for('index')})
    return menus
def torrentz(url, mname=''):
    '''
    magnet link search engine: torrentz.eu, torrentz index include eztv.it,
    thepiratebay.org.
    '''
    if url == 'search':
        url = 'http://torrentz.eu/search?f='
        sel = dialog.select('选择节目类型', ('电影', '电视', '视频', '自定义'))
        if sel is -1: return
        if sel == 0:
            typ = 'movie*+'
        if sel == 1:
            typ = 'show*+'
        if sel == 2:
            typ = 'video*+'
        if sel == 3:
            typ = ''
        if (not mname) or (mname and not typ):
            kb = Keyboard('',u'请输入搜索关键字')
            kb.doModal()
            if not kb.isConfirmed(): return
            _mname = kb.getText()
            if mname:
                mname = _mname + ' ' + mname
            else:
                mname = _mname
        #stxt = '%s%s' % (typ, mstr.replace(' ', '+'))
        url = '%s%s%s&p=0' % (
            'https://torrentz.eu/search?f=', typ, urllib.quote_plus(mname))
    print url
    rsp = hc.urlopen(url)
    mitems = re.findall(
        r'"/([0-9a-z]{40})">(.*?)</a>.*?class="s">([^>]+)<', rsp, re.S)

    menus = [{'label': '%s[%s]' % (re.sub(r'<.*?>', '', i[1]), i[2]),
              'path': plugin.url_for('playlxmagnet',
                                     magnet='magnet:?xt=urn:btih:%s' % i[0])
              } for i in mitems]

    cnt = re.findall(r'<h2 style="border-bottom: none">([,0-9]+) Torrents', rsp)
    if cnt:
        cnt = int(cnt[0].replace(',', ''))
        pages = (cnt + 49) // 50
        currpg = int(url.split('=')[-1])
        urlpre = '='.join(url.split('=')[:-1])
        if currpg > 0:
            menus.append({'label': '上一页',
                          'path': plugin.url_for(
                              'torrentz', url='%s=%s' % (urlpre, currpg-1))})
        if (currpg+1) < pages:
            menus.append({'label': '下一页',
                          'path': plugin.url_for(
                              'torrentz', url='%s=%s' % (urlpre, currpg+1))})
        menus.insert(0, {'label':
                         '【第%s页/共%s页】返回上级菜单' % (currpg+1, pages),
                         'path': plugin.url_for('index')})
    return menus
Exemple #4
0
def torrentz(url, mname=''):
    '''
    magnet link search engine: torrentz.eu, torrentz index include eztv.it,
    thepiratebay.org.
    '''
    if url == 'search':
        url = 'http://extratorrent.cc/search/?s_cat='
        sel = dialog.select('选择节目类型', ('电影', '电视'))
        if sel is -1:
            return
        if sel == 0:
            typ = '4'
        if sel == 1:
            typ = '8'
        if (not mname) or (mname and not typ):
            kb = Keyboard('', u'请输入搜索关键字')
            kb.doModal()
            if not kb.isConfirmed():
                return
            _mname = kb.getText()
            if mname:
                mname = _mname + ' ' + mname
            else:
                mname = _mname
        # stxt = '%s%s' % (typ, mstr.replace(' ', '+'))
        url = '%s%s&search=%s&page=1' % (url, typ, urllib.quote_plus(mname))
    #print url
    rsp = hc.urlopen(url)
    mitems = re.findall(
        r'href="(/torrent\/[0-9]+\/\S+html)" title="view (.*?) torrent"', rsp)

    print mitems
    menus = [{
        'label': i[1],
        'path': plugin.url_for('playlxmagnet', magnet=i[0])
    } for i in mitems]

    #cnt = re.findall(
    #    r'<h2 style="border-bottom: none">([,0-9]+) Torrents', rsp)
    #if cnt:
    #    cnt = int(cnt[0].replace(',', ''))
    #    pages = (cnt + 49) // 50
    #    currpg = int(url.split('=')[-1])
    #    urlpre = '='.join(url.split('=')[:-1])
    #    if currpg > 0:
    #        menus.append({'label': '上一页',
    #                      'path': plugin.url_for(
    #                          'torrentz', url='%s=%s' % (urlpre, currpg-1))})
    #    if (currpg+1) < pages:
    #        menus.append({'label': '下一页',
    #                      'path': plugin.url_for(
    #                          'torrentz', url='%s=%s' % (urlpre, currpg+1))})
    #    menus.insert(0, {'label':
    #                     '【第%s页/共%s页】返回上级菜单' % (currpg+1, pages),
    #                     'path': plugin.url_for('index')})
    return menus
Exemple #5
0
def dbsearch(url):
    '''
    douban movie tag search, support multiple tag
    '''
    if url == 'search':
        urlpre = 'http://movie.douban.com/tag'
        kb = Keyboard('', u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed():
            return
        sstr = kb.getText()
        url = '%s/%s?start=0' % (urlpre, urllib2.quote(sstr))
    rsp = hc.urlopen(url)
    rtxt = r'%s%s' % ('class="nbg".*?(subject/\d+).*?src="(.*?)" alt="(.*?)"',
                      '.*?class="pl">(.*?)</p>.*?rating_nums">(.*?)<')
    patt = re.compile(rtxt, re.S)
    mitems = patt.findall(rsp)
    if not mitems:
        return
    menus = [{
        'label':
        '{0}. {1}[{2}][{3}]'.format(s, i[2], i[4], i[3]),
        'path':
        plugin.url_for('searchdisp', mname='%s/%s' % (dbapi, i[0])),
        'thumbnail':
        i[2],
    } for s, i in enumerate(mitems)]

    pages = re.findall(r'class="thispage" data-total-page="(\d+)">(\d+)<', rsp)
    if pages:
        urlpre = '='.join(url.split('=')[:-1])
        currpg = int(pages[0][1])
        totalpg = int(pages[0][0])
        if currpg > 1:
            menus.append({
                'label':
                '上一页',
                'path':
                plugin.url_for('dbsearch',
                               url='%s=%s' % (urlpre, (currpg - 1) * 20))
            })
        if currpg < totalpg:
            menus.append({
                'label':
                '下一页',
                'path':
                plugin.url_for('dbsearch',
                               url='%s=%s' % (urlpre, (currpg + 1) * 20))
            })
        menus.insert(
            0, {
                'label': '【第%s页/共%s页】返回上级菜单' % (currpg, totalpg),
                'path': plugin.url_for('index')
            })
    return menus
def torrentz(url, mname=''):
    '''
    magnet link search engine: torrentz.eu, torrentz index include eztv.it,
    thepiratebay.org.
    '''
    if url == 'search':
        url = 'http://extratorrent.cc/search/?s_cat='
        sel = dialog.select('选择节目类型', ('电影', '电视'))
        if sel is -1:
            return
        if sel == 0:
            typ = '4'
        if sel == 1:
            typ = '8'
        if (not mname) or (mname and not typ):
            kb = Keyboard('', u'请输入搜索关键字')
            kb.doModal()
            if not kb.isConfirmed():
                return
            _mname = kb.getText()
            if mname:
                mname = _mname + ' ' + mname
            else:
                mname = _mname
        # stxt = '%s%s' % (typ, mstr.replace(' ', '+'))
        url = '%s%s&search=%s&page=1' % (url, typ, urllib.quote_plus(mname))
    #print url
    rsp = hc.urlopen(url)
    mitems = re.findall(
        r'href="(/torrent\/[0-9]+\/\S+html)" title="view (.*?) torrent"', rsp)

    print mitems
    menus = [{'label': i[1],
              'path': plugin.url_for('playlxmagnet', magnet=i[0])
              } for i in mitems]

    #cnt = re.findall(
    #    r'<h2 style="border-bottom: none">([,0-9]+) Torrents', rsp)
    #if cnt:
    #    cnt = int(cnt[0].replace(',', ''))
    #    pages = (cnt + 49) // 50
    #    currpg = int(url.split('=')[-1])
    #    urlpre = '='.join(url.split('=')[:-1])
    #    if currpg > 0:
    #        menus.append({'label': '上一页',
    #                      'path': plugin.url_for(
    #                          'torrentz', url='%s=%s' % (urlpre, currpg-1))})
    #    if (currpg+1) < pages:
    #        menus.append({'label': '下一页',
    #                      'path': plugin.url_for(
    #                          'torrentz', url='%s=%s' % (urlpre, currpg+1))})
    #    menus.insert(0, {'label':
    #                     '【第%s页/共%s页】返回上级菜单' % (currpg+1, pages),
    #                     'path': plugin.url_for('index')})
    return menus
Exemple #7
0
def dbscraper(url):
    '''
    由于豆瓣提供的tag搜索api不支持多tag关联查询,暂时先用dbsearch方法
    '''
    if url == 'search':
        kb = Keyboard('', u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed():
            return
        sstr = kb.getText()
        url = '%s/search?tag=%s&start=0' % (dbapi, sstr)
    if url == 'dbtop250':
        url = '%s/top250?count=20&start=0' % dbapi
    view = 'dbsearch' if 'search' in url else 'dbtop250'
    rsp = hc.urlopen(url)
    data = json.loads(rsp)
    movs = data['subjects']
    if not movs:
        return
    menus = [{
        'label':
        '{0}.{1}[{2}年][{3}分][{4}人收藏]'.format(s, m['title'].encode('utf-8'),
                                             m['year'], m['rating']['average'],
                                             m['collect_count']),
        'path':
        plugin.url_for('searchdisp',
                       mname=str((m['title'].encode('utf-8'),
                                  m['original_title'].encode('utf-8')))),
        'thumbnail':
        m['images']['large'],
    } for s, m in enumerate(movs)]

    start = data['start']
    urlpre = '='.join(url.split('=')[:-1])
    if start != 0:
        menus.append({
            'label':
            '上一页',
            'path':
            plugin.url_for(view, url='%s=%s' % (urlpre, start - 20))
        })
    menus.append({
        'label':
        '下一页',
        'path':
        plugin.url_for(view, url='%s=%s' % (urlpre, start + 20))
    })
    menus.insert(
        0, {
            'label': '【当前%s页】返回上级菜单' % str(start // 20 + 1),
            'path': plugin.url_for('index')
        })
    return menus
Exemple #8
0
def keyboard(title=u'请输入搜索关键字',text=''):
	buildinkb=False
	if str(plugin.get_setting('buildinkb'))=='true' or int(version)<16:
		buildinkb=True
	if buildinkb:
		kb = Keyboard(text,title)
	else:
		kb=xbmc.Keyboard(text,title)
	kb.doModal()
	text=''
	if kb.isConfirmed():
		text=kb.getText()
	return text
Exemple #9
0
def btdigg(url, mname=''):
    '''
    magnet linke search engine: btdigg.org
    '''
    if url == 'search':
        url = 'http://btdigg.org/search?q='
        if not mname:
            kb = Keyboard('', u'请输入搜索关键字')
            kb.doModal()
            if not kb.isConfirmed():
                return
            mname = kb.getText()
            if not mname:
                return
        url = url + urllib2.quote(mname)
    else:
        url = 'http://btdigg.org' + url

    rsp = hc.urlopen(url)
    rpat = re.compile(
        r'"idx">.*?>([^<]+)</a>.*?href="(magnet.*?)".*?Size:.*?">(.*?)<')
    items = rpat.findall(rsp)

    menus = [{
        'label': '%d.%s[%s]' % (s + 1, v[0], v[2].replace('&nbsp;', '')),
        'path': plugin.url_for('playlxmagnet', magnet=v[1])
    } for s, v in enumerate(items)]
    ppat = re.compile(r'%s%s' %
                      ('class="pager".*?(?:href="(/search.*?)")?>←.*?>',
                       '(\d+/\d+).*?(?:href="(/search.*?)")?>Next'))

    pgs = ppat.findall(rsp)

    for s, p in enumerate((pgs[0][0], pgs[0][2])):
        if p:
            menus.append({
                'label': '上一页' if not s else '下一页',
                'path': plugin.url_for('btdigg', url=p)
            })
    menus.insert(0, {
        'label': '[当前页%s页总共]返回上级目录' % pgs[0][1],
        'path': plugin.url_for('index')
    })
    return menus
def dbscraper(url):
    '''
    由于豆瓣提供的tag搜索api不支持多tag关联查询,暂时先用dbsearch方法
    '''
    if url == 'search':
        kb = Keyboard('', u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed():
            return
        sstr = kb.getText()
        url = '%s/search?tag=%s&start=0' % (dbapi, sstr)
    if url == 'dbtop250':
        url = '%s/top250?count=20&start=0' % dbapi
    view = 'dbsearch' if 'search' in url else 'dbtop250'
    rsp = hc.urlopen(url)
    data = json.loads(rsp)
    movs = data['subjects']
    if not movs:
        return
    menus = [{
        'label': '{0}.{1}[{2}年][{3}分][{4}人收藏]'.format(
            s, m['title'].encode('utf-8'), m['year'], m['rating']['average'],
            m['collect_count']
        ),
        'path': plugin.url_for(
            'searchdisp',
            mname=str((m['title'].encode('utf-8'),
                       m['original_title'].encode('utf-8')))
        ),
        'thumbnail': m['images']['large'],
    } for s, m in enumerate(movs)]

    start = data['start']
    urlpre = '='.join(url.split('=')[:-1])
    if start != 0:
        menus.append({'label': '上一页',
                      'path': plugin.url_for(
                          view, url='%s=%s' % (urlpre, start-20))})
    menus.append({'label': '下一页',
                  'path': plugin.url_for(
                      view, url='%s=%s' % (urlpre, start+20))})
    menus.insert(0, {'label': '【当前%s页】返回上级菜单' % str(start//20 + 1),
                     'path': plugin.url_for('index')})
    return menus
def dbsearch(url):
    '''
    douban movie tag search, support multiple tag
    '''
    if url == 'search':
        urlpre = 'http://movie.douban.com/tag'
        kb = Keyboard('', u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed():
            return
        sstr = kb.getText()
        url = '%s/%s?start=0' % (urlpre, urllib2.quote(sstr))
    rsp = hc.urlopen(url)
    rtxt = r'%s%s' % ('class="nbg".*?(subject/\d+).*?src="(.*?)" alt="(.*?)"',
                      '.*?class="pl">(.*?)</p>.*?rating_nums">(.*?)<')
    patt = re.compile(rtxt, re.S)
    mitems = patt.findall(rsp)
    if not mitems:
        return
    menus = [{'label': '{0}. {1}[{2}][{3}]'.format(s, i[2], i[4], i[3]),
              'path': plugin.url_for(
                  'searchdisp', mname='%s/%s' % (dbapi, i[0])),
              'thumbnail': i[2], }
             for s, i in enumerate(mitems)]

    pages = re.findall(r'class="thispage" data-total-page="(\d+)">(\d+)<', rsp)
    if pages:
        urlpre = '='.join(url.split('=')[:-1])
        currpg = int(pages[0][1])
        totalpg = int(pages[0][0])
        if currpg > 1:
            menus.append({'label': '上一页',
                          'path': plugin.url_for(
                              'dbsearch',
                              url='%s=%s' % (urlpre, (currpg-1)*20))})
        if currpg < totalpg:
            menus.append({'label': '下一页',
                          'path': plugin.url_for(
                              'dbsearch',
                              url='%s=%s' % (urlpre, (currpg+1)*20))})
        menus.insert(0, {'label':
                         '【第%s页/共%s页】返回上级菜单' % (currpg, totalpg),
                         'path': plugin.url_for('index')})
    return menus
def torrentz(url):
    if 'p=' not in url:
        url = 'http://torrentz.eu/search?f='
        sel = dialog.select('选择节目类型', ('电影', '电视'))
        if sel is -1: return
        typ = 'shows:' if sel else 'movies:'
        kb = Keyboard('',u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed(): return
        mstr = kb.getText()
        if not mstr: return
        stxt = '%s%s' % (typ, mstr.replace(' ', '+'))
        url = '%s%s&p=0' % ('http://torrentz.eu/search?f=', urllib2.quote(stxt))
    rsp = hc.urlopen(url)
    mitems = re.findall(
        r'"/([0-9a-z]{40})">(.*?)</a>.*?class="s">([^>]+)<', rsp, re.S)

    menus = [{'label': '%s[%s]' % (re.sub(r'<.*?>', '', i[1]), i[2]),
              'path': plugin.url_for('playlxmagnet',
                                     magnet='magnet:?xt=urn:btih:%s' % i[0])
              } for i in mitems]

    cnt = re.findall(r'<h2 style="border-bottom: none">([,0-9]+) Torrents', rsp)
    if cnt:
        cnt = int(cnt[0].replace(',', ''))
        pages = (cnt + 49) // 50
        currpg = int(url.split('=')[-1])
        urlpre = '='.join(url.split('=')[:-1])
        if currpg > 0:
            menus.append({'label': '上一页',
                          'path': plugin.url_for(
                              'torrentz', url='%s=%s' % (urlpre, currpg-1))})
        if (currpg+1) < pages:
            menus.append({'label': '下一页',
                          'path': plugin.url_for(
                              'torrentz', url='%s=%s' % (urlpre, currpg+1))})
        menus.insert(0, {'label':
                         '【第%s页/共%s页】返回上级菜单' % (currpg+1, pages),
                         'path': plugin.url_for('index')})
    return menus
def dbactor(url):
    if 'search_text' not in url:
        urlpre = 'http://movie.douban.com/subject_search'
        kb = Keyboard('',u'请输入搜索关键字')
        kb.doModal()
        if not kb.isConfirmed(): return
        sstr = kb.getText()
        url = '%s/?search_text=%s&start=0' % (urlpre ,sstr)
    rsp = hc.urlopen(url)
    rtxt = r'%s%s' % ('tr class="item".*?nbg".*?src="(.*?)" alt="(.*?)"',
                      '.*?class="pl">(.*?)</p>.*?rating_nums">(.*?)<')
    patt = re.compile(rtxt, re.S)
    mitems = patt.findall(rsp)
    if not mitems: return
    menus = [{'label': '{0}. {1}[{2}][{3}]'.format(s, i[1], i[3], i[2]),
             'path': plugin.url_for('btsearch', url='search', mstr=i[1]),
             'thumbnail': i[0],
         } for s, i in enumerate(mitems)]

    cnt = re.findall(r'class="count">.*?(\d+).*?</span>', rsp)
    if cnt:
        cnt = int(cnt[0])
        pages = (cnt + 14) // 15
        curpg = int(url.split('=')[-1]) // 15
        urlpre = '='.join(url.split('=')[:-1])
        if curpg > 0:
            menus.append({'label': '上一页',
                          'path': plugin.url_for(
                              'dbactor', url='%s=%s' % (urlpre, (curpg-1)*15))})
        if (curpg+1) < pages:
            menus.append({'label': '下一页',
                          'path': plugin.url_for(
                              'dbactor', url='%s=%s' % (urlpre, (curpg+1)*15))})
        menus.insert(0, {'label':
                         '【第%s页/共%s页】返回上级菜单' % (curpg+1, pages),
                         'path': plugin.url_for('index')})
    return menus
def searchvideo(url):
    """
    search video
    """
    source = [('http://v.youku.com', 'youku'), ('http://tv.sohu.com', 'sohu'),
              ('http://v.qq.com', 'qq'), ('http://www.iqiyi.com', 'iqiyi'),
              ('http://www.letv.com', 'letv'), ('http://v.pps.tv', 'pps'),
              ('http://www.tudou.com', 'tudou')]
    kb = Keyboard('', u'请输入搜索关键字')
    kb.doModal()
    if not kb.isConfirmed(): return
    sstr = kb.getText()
    if not sstr: return
    url = url + urllib2.quote(sstr)
    result = _http(url)
    movstr = re.findall(r'<div class="item">(.*?)<!--item end-->', result,
                        re.S)
    vitempat = re.compile(
        r'{0}{1}'.format('p_link">.*?title="(.*?)".*?p_thumb.*?src="(.*?)"',
                         '.*?status="(.*?)"'), re.S)
    menus = []
    site = None
    for movitem in movstr:
        if 'p_ispaid' in movitem or 'nosource' in movitem: continue
        psrc = re.compile(r'pgm-source(.*?)</div>', re.S).search(movitem)
        if not psrc: continue
        for k in source:
            if k[0] in psrc.group(1):
                site = k
                break
        if not site: continue
        vitem = vitempat.search(movitem)

        if 'class="movie"' in movitem:
            eps = re.search(r'(%s.*?html)' % site[0], movitem, re.S).group(1)
            menus.append({
                'label':
                '%s【%s】(%s)' % (vitem.group(1), vitem.group(3), site[1]),
                'path':
                plugin.url_for('playsearch', url=eps, source=site[1]),
                'thumbnail':
                vitem.group(2),
            })

        if 'class="tv"' in movitem or 'class="zy"' in movitem:
            if 'class="tv"' in movitem:
                epss = re.findall(r'(%s.*?html).*?>([\w ."]+?)</a>' % site[0],
                                  movitem, re.S)
            else:
                epss = re.findall(
                    r'{0}{1}{2}'.format(
                        '"(?:(?:date)|(?:phases))">([\d-]+)</span>\s+<a[\S ]+(',
                        site[0], '.*?html).*?>([^>]+?)<(?:(?:em)|(?:/a))(?s)'),
                    movitem)
                epss = [(i[1], '[%s]%s' % (i[0], i[2])) for i in epss]
            #epss = reversed([(k, v) for k,v in OrderedDict(reversed(epss)).
            #                 iteritems() if '查看全部' not in v])
            epss = [(v[0], site[1], v[1]) for v in epss]
            menus.append({
                'label':
                '%s【%s】(%s)' % (vitem.group(1), vitem.group(3), site[1]),
                'path':
                plugin.url_for('showsearch', url=str(epss)),
                'thumbnail':
                vitem.group(2),
            })
    return menus
def searchvideo(url):
    """
    search video
    """
    source = [('http://v.youku.com', 'youku'),
              ('http://tv.sohu.com', 'sohu'),
              ('http://v.qq.com', 'qq'),
              ('http://www.iqiyi.com', 'iqiyi'),
              ('http://www.letv.com', 'letv'),
              ('http://v.pps.tv', 'pps'),
              ('http://www.tudou.com', 'tudou')]
    kb = Keyboard('',u'请输入搜索关键字')
    kb.doModal()
    if not kb.isConfirmed(): return
    sstr = kb.getText()
    if not sstr: return
    url = url + urllib2.quote(sstr)
    result = _http(url)
    movstr = re.findall(r'<div class="item">(.*?)<!--item end-->', result, re.S)

    if not movstr:
        vitempat = re.compile(
            r'lass="v-thumb".*?img alt="(.*?)" src="(.*?)".*?href="(.*?)"',re.S)
        movs = re.findall(vitempat, result)
        menus = [{
            'label': m[0],
            'path': plugin.url_for('playmovie', url=m[2]),
            'thumbnail': m[1]
        } for m in movs]
        return menus

    vitempat = re.compile(
        r'{0}{1}'.format('p_link">.*?title="(.*?)".*?p_thumb.*?src="(.*?)"',
                         '.*?status="(.*?)"'), re.S)
    menus = []
    site = None
    for movitem in movstr:
        if 'p_ispaid' in movitem or 'nosource' in movitem: continue
        psrc = re.compile(r'pgm-source(.*?)</div>', re.S).search(movitem)
        if not psrc: continue
        for k in source:
            if k[0] in psrc.group(1):
                site = k
                break
        if not site: continue
        vitem = vitempat.search(movitem)

        if 'class="movie"' in movitem:
            eps = re.search(r'(%s.*?html)' % site[0], movitem, re.S).group(1)
            menus.append({
                'label': '%s【%s】(%s)' % (
                    vitem.group(1), vitem.group(3), site[1]),
                'path': plugin.url_for('playsearch', url=eps, source=site[1]),
                'thumbnail': vitem.group(2),})

        if 'class="tv"' in movitem or 'class="zy"' in movitem:
            if 'class="tv"' in movitem:
                epss = re.findall(
                    r'(%s.*?html).*?>([\w ."]+?)</a>' % site[0], movitem, re.S)
            else:
                epss = re.findall(r'{0}{1}{2}'.format(
                    '"(?:(?:date)|(?:phases))">([\d-]+)</span>\s+<a[\S ]+(',
                    site[0], '.*?html).*?>([^>]+?)<(?:(?:em)|(?:/a))(?s)'),
                                  movitem)
                epss = [(i[1], '[%s]%s' % (i[0], i[2])) for i in epss]
            #epss = reversed([(k, v) for k,v in OrderedDict(reversed(epss)).
            #                 iteritems() if '查看全部' not in v])
            epss = [(v[0], site[1], v[1]) for v in epss]
            menus.append({
                'label': '%s【%s】(%s)' % (
                    vitem.group(1), vitem.group(3), site[1]),
                'path': plugin.url_for('showsearch', url=str(epss)),
                'thumbnail': vitem.group(2),})
    return menus