cms.py 24.6 KB
Newer Older
H
hjdhnx 已提交
1 2 3 4 5
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : cms.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date  : 2022/8/25
H
hjdhnx 已提交
6

H
hjdhnx 已提交
7
import requests
8
import re
9
import math
H
hjdhnx 已提交
10
from utils.web import *
H
hjdhnx 已提交
11
from models import *
H
hjdhnx 已提交
12
from utils.config import config
H
hjdhnx 已提交
13
from utils.log import logger
14
from utils.encode import base64Encode,baseDecode,fetch,post,request,getCryptoJS,getPreJs
H
hjdhnx 已提交
15
from utils.safePython import safePython
H
hjdhnx 已提交
16
from utils.parser import runPy,runJScode
H
hjdhnx 已提交
17
from utils.htmlParser import jsoup
H
hjdhnx 已提交
18
from urllib.parse import urljoin
19
from concurrent.futures import ThreadPoolExecutor  # 引入线程池
H
hjdhnx 已提交
20
from flask import url_for,redirect
21
from easydict import EasyDict as edict
H
hjdhnx 已提交
22

H
hjdhnx 已提交
23 24
py_ctx = {
'requests':requests,'print':print,'base64Encode':base64Encode,'baseDecode':baseDecode,
25
'log':logger.info,'fetch':fetch,'post':post,'request':request,'getCryptoJS':getCryptoJS
H
hjdhnx 已提交
26
}
27
# print(getCryptoJS())
H
hjdhnx 已提交
28

H
hjdhnx 已提交
29
class CMS:
H
hjdhnx 已提交
30
    def __init__(self, rule, db=None, RuleClass=None, PlayParse=None,new_conf=None):
H
hjdhnx 已提交
31 32
        if new_conf is None:
            new_conf = {}
H
hjdhnx 已提交
33
        self.title = rule.get('title', '')
H
hjdhnx 已提交
34
        self.id = rule.get('id', self.title)
H
hjdhnx 已提交
35
        self.lazy = rule.get('lazy', False)
36
        self.play_disable = new_conf.get('PLAY_DISABLE',False)
H
hjdhnx 已提交
37
        self.vod = redirect(url_for('vod')).headers['Location']
H
hjdhnx 已提交
38
        # if not self.play_disable and self.lazy:
39 40 41 42 43 44
        if not self.play_disable:
            self.play_parse = rule.get('play_parse', False)
            play_url = new_conf.get('PLAY_URL',getHost(1))
            if not play_url.startswith('http'):
                play_url = 'http://'+play_url
            if self.play_parse:
H
hjdhnx 已提交
45
                # self.play_url = play_url + self.vod + '?play_url='
H
hjdhnx 已提交
46
                self.play_url = f'{play_url}{self.vod}?rule={self.id}&play_url='
H
hjdhnx 已提交
47
                # logger.info(f'cms重定向链接:{self.play_url}')
48 49
            else:
                self.play_url = ''
H
hjdhnx 已提交
50
        else:
51
            self.play_parse = False
H
hjdhnx 已提交
52
            self.play_url = ''
53

H
hjdhnx 已提交
54 55
        self.db = db
        self.RuleClass = RuleClass
H
hjdhnx 已提交
56
        self.PlayParse = PlayParse
57
        host = rule.get('host','').rstrip('/')
58
        timeout = rule.get('timeout',5000)
H
hjdhnx 已提交
59
        homeUrl = rule.get('homeUrl','/')
60 61 62 63
        url = rule.get('url','')
        detailUrl = rule.get('detailUrl','')
        searchUrl = rule.get('searchUrl','')
        headers = rule.get('headers',{})
64
        limit = rule.get('limit',6)
H
hjdhnx 已提交
65
        encoding = rule.get('编码', 'utf-8')
H
hjdhnx 已提交
66
        self.limit = min(limit,30)
67 68 69 70 71 72 73 74
        keys = headers.keys()
        for k in headers.keys():
            if str(k).lower() == 'user-agent':
                v = headers[k]
                if v == 'MOBILE_UA':
                    headers[k] = MOBILE_UA
                elif v == 'PC_UA':
                    headers[k] = PC_UA
H
hjdhnx 已提交
75 76
                elif v == 'UC_UA':
                    headers[k] = UC_UA
77 78 79 80 81 82 83 84 85 86
        lower_keys = list(map(lambda x:x.lower(),keys))
        if not 'user-agent' in lower_keys:
            headers['User-Agent'] = UA
        self.headers = headers
        self.host = host
        self.homeUrl = urljoin(host,homeUrl) if host and homeUrl else homeUrl
        if url.find('[') >-1 and url.find(']') > -1:
            u1 = url.split('[')[0]
            u2 = url.split('[')[1].split(']')[0]
            self.url = urljoin(host,u1)+'['+urljoin(host,u2)+']' if host and url else url
H
hjdhnx 已提交
87
        else:
88 89 90 91
            self.url = urljoin(host, url) if host and url else url

        self.detailUrl = urljoin(host,detailUrl) if host and detailUrl else detailUrl
        self.searchUrl = urljoin(host,searchUrl) if host and searchUrl else searchUrl
H
hjdhnx 已提交
92 93
        self.class_name = rule.get('class_name','')
        self.class_url = rule.get('class_url','')
94
        self.class_parse = rule.get('class_parse','')
H
hjdhnx 已提交
95 96 97
        self.filter_name = rule.get('filter_name', '')
        self.filter_url = rule.get('filter_url', '')
        self.filter_parse = rule.get('filter_parse', '')
98
        self.double = rule.get('double',False)
H
hjdhnx 已提交
99 100 101
        self.一级 = rule.get('一级','')
        self.二级 = rule.get('二级','')
        self.搜索 = rule.get('搜索','')
102
        self.推荐 = rule.get('推荐','')
H
hjdhnx 已提交
103
        self.encoding = encoding
104
        self.timeout = round(int(timeout)/1000,2)
H
hjdhnx 已提交
105 106
        self.filter = rule.get('filter',[])
        self.extend = rule.get('extend',[])
107
        self.d = self.getObject()
H
hjdhnx 已提交
108 109 110 111

    def getName(self):
        return self.title

112 113 114 115 116 117 118 119 120 121 122 123
    def getObject(self):
        o = edict({
            'jsp':jsoup(self.url),
            'getParse':self.getParse,
            'saveParse':self.saveParse,
            'headers':self.headers,
            'encoding':self.encoding,
            'name':self.title,
            'timeout':self.timeout,
        })
        return o

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    def regexp(self,prule,text,pos=None):
        ret = re.search(prule,text).groups()
        if pos != None and isinstance(pos,int):
            return ret[pos]
        else:
            return ret

    def test(self,text,string):
        searchObj = re.search(rf'{text}', string, re.M | re.I)
        # print(searchObj)
        # global vflag
        if searchObj:
            # vflag = searchObj.group()
            pass
        return searchObj

    def blank(self):
        result = {
            'list': []
        }
        return result

    def blank_vod(self):
        return {
            "vod_id": "",
            "vod_name": "",
            "vod_pic": "",
            "type_name": "",
            "vod_year": "",
            "vod_area": "",
            "vod_remarks": "",
            "vod_actor": "",
            "vod_director": "",
            "vod_content": ""
        }

    def jsoup(self):
        jsp = jsoup(self.url)
        pdfh = jsp.pdfh
        pdfa = jsp.pdfa
        pd = jsp.pd
        pq = jsp.pq
        return pdfh,pdfa,pd,pq

H
hjdhnx 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    def getClasses(self):
        if not self.db:
            msg = '未提供数据库连接'
            print(msg)
            return []
        name = self.getName()
        # self.db.metadata.clear()
        # RuleClass = rule_classes.init(self.db)
        res = self.db.session.query(self.RuleClass).filter(self.RuleClass.name == name).first()
        # _logger.info('xxxxxx')
        if res:
            cls = res.class_name.split('&')
            cls2 = res.class_url.split('&')
            classes = [{'type_name':cls[i],'type_id':cls2[i]} for i in range(len(cls))]
            # _logger.info(classes)
H
hjdhnx 已提交
183
            logger.info(f"{self.getName()}使用缓存分类:{classes}")
H
hjdhnx 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
            return classes
        else:
            return []

    def saveClass(self, classes):
        if not self.db:
            msg = '未提供数据库连接'
            print(msg)
            return msg
        name = self.getName()
        class_name = '&'.join([cl['type_name'] for cl in classes])
        class_url = '&'.join([cl['type_id'] for cl in classes])
        # data = RuleClass.query.filter(RuleClass.name == '555影视').all()
        # self.db.metadata.clear()
        # RuleClass = rule_classes.init(self.db)
        res = self.db.session.query(self.RuleClass).filter(self.RuleClass.name == name).first()
H
hjdhnx 已提交
200
        # print(res)
H
hjdhnx 已提交
201 202 203 204
        if res:
            res.class_name = class_name
            res.class_url = class_url
            self.db.session.add(res)
H
hjdhnx 已提交
205
            msg = f'{self.getName()}修改成功:{res.id}'
H
hjdhnx 已提交
206 207 208 209
        else:
            res = self.RuleClass(name=name, class_name=class_name, class_url=class_url)
            self.db.session.add(res)
            res = self.db.session.query(self.RuleClass).filter(self.RuleClass.name == name).first()
H
hjdhnx 已提交
210
            msg = f'{self.getName()}新增成功:{res.id}'
H
hjdhnx 已提交
211 212 213

        try:
            self.db.session.commit()
H
hjdhnx 已提交
214
            logger.info(msg)
H
hjdhnx 已提交
215 216 217
        except Exception as e:
            return f'发生了错误:{e}'

H
hjdhnx 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    def getParse(self,play_url):
        if not self.db:
            msg = '未提供数据库连接'
            print(msg)
            return ''
        name = self.getName()
        # self.db.metadata.clear()
        # RuleClass = rule_classes.init(self.db)
        res = self.db.session.query(self.PlayParse).filter(self.PlayParse.play_url == play_url).first()
        # _logger.info('xxxxxx')
        if res:
            real_url = res.real_url
            logger.info(f"{name}使用缓存播放地址:{real_url}")
            return real_url
        else:
H
hjdhnx 已提交
233
            return ''
H
hjdhnx 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261

    def saveParse(self, play_url,real_url):
        if not self.db:
            msg = '未提供数据库连接'
            print(msg)
            return msg
        name = self.getName()
        # data = RuleClass.query.filter(RuleClass.name == '555影视').all()
        # self.db.metadata.clear()
        # RuleClass = rule_classes.init(self.db)
        res = self.db.session.query(self.PlayParse).filter(self.PlayParse.play_url == play_url).first()
        # print(res)
        if res:
            res.real_url = real_url
            self.db.session.add(res)
            msg = f'{name}服务端免嗅修改成功:{res.id}'
        else:
            res = self.PlayParse(play_url=play_url, real_url=real_url)
            self.db.session.add(res)
            res = self.db.session.query(self.PlayParse).filter(self.PlayParse.play_url == play_url).first()
            msg = f'{name}服务端免嗅新增成功:{res.id}'

        try:
            self.db.session.commit()
            logger.info(msg)
        except Exception as e:
            return f'{name}发生了错误:{e}'

H
hjdhnx 已提交
262

263
    def homeContent(self,fypage=1):
H
hjdhnx 已提交
264 265
        # yanaifei
        # https://yanetflix.com/vodtype/dianying.html
H
hjdhnx 已提交
266
        t1 = time()
H
hjdhnx 已提交
267 268
        result = {}
        classes = []
269
        video_result = self.blank()
270 271 272 273 274 275 276 277 278 279 280

        if self.class_url and self.class_name:
            class_names = self.class_name.split('&')
            class_urls = self.class_url.split('&')
            cnt = min(len(class_urls), len(class_names))
            for i in range(cnt):
                classes.append({
                    'type_name': class_names[i],
                    'type_id': class_urls[i]
                })
        # print(self.url)
H
hjdhnx 已提交
281
        has_cache = False
282
        if self.homeUrl.startswith('http'):
283 284 285
            # print(self.homeUrl)
            # print(self.class_parse)
            try:
H
hjdhnx 已提交
286
                if self.class_parse:
H
hjdhnx 已提交
287
                    t2 = time()
H
hjdhnx 已提交
288
                    cache_classes = self.getClasses()
H
hjdhnx 已提交
289
                    logger.info(f'{self.getName()}读取缓存耗时:{get_interval(t2)}毫秒')
H
hjdhnx 已提交
290 291
                    if len(cache_classes) > 0:
                        classes = cache_classes
H
hjdhnx 已提交
292
                        # print(cache_classes)
H
hjdhnx 已提交
293
                        has_cache = True
H
hjdhnx 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
                # logger.info(f'是否有缓存分类:{has_cache}')
                if has_cache and not self.推荐:
                    pass
                else:
                    new_classes = []
                    r = requests.get(self.homeUrl, headers=self.headers, timeout=self.timeout)
                    r.encoding = self.encoding
                    html = r.text
                    if self.class_parse and not has_cache:
                        p = self.class_parse.split(';')
                        print(p)
                        jsp = jsoup(self.url)
                        pdfh = jsp.pdfh
                        pdfa = jsp.pdfa
                        pd = jsp.pd
                        items = pdfa(html,p[0])
                        print(len(items))
                        print(items)
                        for item in items:
                            title = pdfh(item, p[1])
                            url = pd(item, p[2])
                            print(url)
                            tag = url
                            if len(p) > 3 and p[3].strip():
                                tag = self.regexp(p[3].strip(),url,0)
                            new_classes.append({
                                'type_name': title,
                                'type_id': tag
                            })
                        if len(new_classes) > 0:
                            classes.extend(new_classes)
                            self.saveClass(classes)
                    video_result = self.homeVideoContent(html,fypage)
327
            except Exception as e:
H
hjdhnx 已提交
328
                logger.info(f'{self.getName()}主页发生错误:{e}')
329

H
hjdhnx 已提交
330 331 332
        result['class'] = classes
        if self.filter:
            result['filters'] = config['filter']
333
        result.update(video_result)
H
hjdhnx 已提交
334
        logger.info(f'{self.getName()}获取首页总耗时(包含读取缓存):{get_interval(t1)}毫秒')
H
hjdhnx 已提交
335 336
        return result

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
    def homeVideoContent(self,html,fypage=1):
        if not self.推荐:
            return self.blank()

        p = self.推荐.split(';')  # 解析
        if not self.double and len(p) < 5:
            return self.blank()
        if self.double and len(p) < 6:
            return self.blank()
        result = {}
        videos = []
        jsp = jsoup(self.homeUrl)
        pdfh = jsp.pdfh
        pdfa = jsp.pdfa
        pd = jsp.pd
        try:
            if self.double:
                items = pdfa(html, p[0])
                for item in items:
                    items2 = pdfa(item,p[1])
                    for item2 in items2:
                        title = pdfh(item2, p[2])
                        img = pd(item2, p[3])
                        desc = pdfh(item2, p[4])
                        link = pd(item2, p[5])
                        content = '' if len(p) < 7 else pdfh(item2, p[6])
                        videos.append({
                            "vod_id": link,
                            "vod_name": title,
                            "vod_pic": img,
                            "vod_remarks": desc,
                            "vod_content": content,
                            "type_id": 1,
                            "type_name": "首页推荐",
                        })
            else:
                items = pdfa(html, p[0])
                for item in items:
                    title = pdfh(item, p[1])
                    img = pd(item, p[2])
                    desc = pdfh(item, p[3])
                    link = pd(item, p[4])
                    content = '' if len(p) < 6 else pdfh(item, p[5])
                    videos.append({
                        "vod_id": link,
                        "vod_name": title,
                        "vod_pic": img,
                        "vod_remarks": desc,
                        "vod_content": content,
                        "type_id": 1,
                        "type_name": "首页推荐",
                    })
            result['list'] = videos
            result['code'] = 1
            result['msg'] = '数据列表'
            result['page'] = fypage
            result['pagecount'] = math.ceil(len(videos)/self.limit)
            result['limit'] = self.limit
            result['total'] = len(videos)
            return result
        except Exception as e:
H
hjdhnx 已提交
398
            logger.info(f'首页内容获取失败:{e}')
399
            return self.blank()
H
hjdhnx 已提交
400 401 402 403 404 405 406 407

    def categoryContent(self, fyclass, fypage):
        """
        一级带分类的数据返回
        :param fyclass: 分类标识
        :param fypage: 页码
        :return: cms一级数据
        """
H
hjdhnx 已提交
408
        
H
hjdhnx 已提交
409 410 411 412 413 414 415 416 417 418
        result = {}
        # urlParams = ["", "", "", "", "", "", "", "", "", "", "", ""]
        # urlParams = [""] * 12
        # urlParams[0] = tid
        # urlParams[8] = str(pg)
        # for key in self.extend:
        #     urlParams[int(key)] = self.extend[key]
        # params = '-'.join(urlParams)
        # print(params)
        # url = self.url + '/{0}.html'.format(params)
H
hjdhnx 已提交
419 420
        pg = str(fypage)
        url = self.url.replace('fyclass',fyclass).replace('fypage',pg)
421 422 423
        if fypage == 1 and self.test('[\[\]]',url):
            url = url.split('[')[1].split(']')[0]
        r = requests.get(url, headers=self.headers,timeout=self.timeout)
H
hjdhnx 已提交
424
        r.encoding = self.encoding
425
        print(r.url)
H
hjdhnx 已提交
426
        p = self.一级.split(';')  # 解析
427 428 429
        if len(p) < 5:
            return self.blank()

H
hjdhnx 已提交
430 431 432 433
        jsp = jsoup(self.url)
        pdfh = jsp.pdfh
        pdfa = jsp.pdfa
        pd = jsp.pd
H
hjdhnx 已提交
434 435 436
        # print(pdfh(r.text,'body a.module-poster-item.module-item:eq(1)&&Text'))
        # print(pdfh(r.text,'body a.module-poster-item.module-item:eq(0)'))
        # print(pdfh(r.text,'body a.module-poster-item.module-item:first'))
H
hjdhnx 已提交
437 438 439 440 441 442 443 444
        items = pdfa(r.text, p[0])
        videos = []
        for item in items:
            # print(item)
            title = pdfh(item, p[1])
            img = pd(item, p[2])
            desc = pdfh(item, p[3])
            link = pd(item, p[4])
H
hjdhnx 已提交
445
            content = '' if len(p) < 6 else pdfh(item, p[5])
H
hjdhnx 已提交
446 447 448 449 450 451 452 453 454
            # sid = self.regStr(sid, "/video/(\\S+).html")
            videos.append({
                "vod_id": link,
                "vod_name": title,
                "vod_pic": img,
                "vod_remarks": desc,
                "vod_content": content,
            })
        result['list'] = videos
H
hjdhnx 已提交
455
        result['page'] = fypage
H
hjdhnx 已提交
456
        result['pagecount'] = 9999
457
        result['limit'] = 9999
H
hjdhnx 已提交
458
        result['total'] = 999999
H
hjdhnx 已提交
459
        
H
hjdhnx 已提交
460 461
        return result

462 463 464
    def detailOneVod(self,id):
        detailUrl = str(id)
        vod = {}
465 466
        if not detailUrl.startswith('http'):
            url = self.detailUrl.replace('fyid', detailUrl)
H
hjdhnx 已提交
467
        else:
468
            url = detailUrl
469
        # print(url)
470
        r = requests.get(url, headers=self.headers,timeout=self.timeout)
H
hjdhnx 已提交
471
        r.encoding = self.encoding
H
hjdhnx 已提交
472 473 474
        html = r.text
        # print(html)
        p = self.二级  # 解析
475 476 477
        if p == '*':
            vod = self.blank_vod()
            vod['vod_play_from'] = '道长在线'
H
hjdhnx 已提交
478
            vod['desc'] = self.play_url+detailUrl
479 480 481
            vod['vod_actor'] = '没有二级,只有一级链接直接嗅探播放'
            vod['content'] = detailUrl
            vod['vod_play_url'] = '嗅探播放$'+detailUrl
482
            return vod
483 484

        if not isinstance(p,dict):
485
            return vod
486

H
hjdhnx 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
        jsp = jsoup(self.url)
        pdfh = jsp.pdfh
        pdfa = jsp.pdfa
        pd = jsp.pd
        pq = jsp.pq
        obj = {}
        vod_name = ''
        if p.get('title'):
            p1 = p['title'].split(';')
            vod_name = pdfh(html,p1[0]).replace('\n',' ')
            title = '\n'.join([pdfh(html,i).replace('\n',' ') for i in p1])
            # print(title)
            obj['title'] = title
        if p.get('desc'):
            p1 = p['desc'].split(';')
            desc = '\n'.join([pdfh(html,i).replace('\n',' ') for i in p1])
            obj['desc'] = desc

        if p.get('content'):
            p1 = p['content'].split(';')
            content = '\n'.join([pdfh(html,i).replace('\n',' ') for i in p1])
            obj['content'] = content

        if p.get('img'):
            p1 = p['img'].split(';')
            img = '\n'.join([pdfh(html,i).replace('\n',' ') for i in p1])
            obj['img'] = img

        vod = {
516
            "vod_id": detailUrl,
H
hjdhnx 已提交
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
            "vod_name": vod_name,
            "vod_pic": obj.get('img',''),
            "type_name": obj.get('title',''),
            "vod_year": "",
            "vod_area": "",
            "vod_remarks": obj.get('desc',''),
            "vod_actor": "",
            "vod_director": "",
            "vod_content": obj.get('content','')
        }

        vod_play_from = '$$$'
        playFrom = []
        if p.get('tabs'):
            vodHeader = pdfa(html,p['tabs'])
H
hjdhnx 已提交
532 533
            # print(f'线路列表数:{len((vodHeader))}')
            # print(vodHeader)
H
hjdhnx 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547
            vodHeader = [pq(v).text() for v in vodHeader]
        else:
            vodHeader = ['道长在线']

        for v in vodHeader:
            playFrom.append(v)
        vod_play_from = vod_play_from.join(playFrom)

        vod_play_url = '$$$'
        vod_tab_list = []
        if p.get('lists'):
            for i in range(len(vodHeader)):
               p1 = p['lists'].replace('#id',str(i))
               vodList = pdfa(html,p1) # 1条线路的选集列表
H
hjdhnx 已提交
548 549
               # vodList = [pq(i).text()+'$'+pd(i,'a&&href') for i in vodList]  # 拼接成 名称$链接
               vodList = [pq(i).text()+'$'+self.play_url+pd(i,'a&&href') for i in vodList]  # 拼接成 名称$链接
H
hjdhnx 已提交
550 551 552 553 554 555 556
               vlist = '#'.join(vodList) # 拼多个选集
               vod_tab_list.append(vlist)
            vod_play_url = vod_play_url.join(vod_tab_list)
        # print(vod_play_url)
        vod['vod_play_from'] = vod_play_from
        vod['vod_play_url'] = vod_play_url

557 558 559 560 561 562 563 564
        return vod

    def detailContent(self, fypage, array):
        """
        cms二级数据
        :param array:
        :return:
        """
H
hjdhnx 已提交
565
        t1 = time()
566 567 568 569 570 571 572 573
        array = array[(fypage-1)*self.limit:min(self.limit*fypage,len(array))]
        thread_pool = ThreadPoolExecutor(min(self.limit,len(array)))  # 定义线程池来启动多线程执行此任务
        obj_list = []
        for vod_url in array:
            obj = thread_pool.submit(self.detailOneVod, vod_url)
            obj_list.append(obj)
        thread_pool.shutdown(wait=True)  # 等待所有子线程并行完毕
        vod_list = [obj.result() for obj in obj_list]
H
hjdhnx 已提交
574
        result = {
575
            'list': vod_list
H
hjdhnx 已提交
576
        }
H
hjdhnx 已提交
577
        logger.info(f'{self.getName()}获取详情页耗时:{get_interval(t1)}毫秒,共计{round(len(str(result))/1000,2)} kb')
H
hjdhnx 已提交
578
        # print(result)
H
hjdhnx 已提交
579 580
        return result

H
hjdhnx 已提交
581
    def searchContent(self, key, fypage=1):
H
hjdhnx 已提交
582
        pg = str(fypage)
583 584
        if not self.searchUrl:
            return self.blank()
H
hjdhnx 已提交
585
        url = self.searchUrl.replace('**', key).replace('fypage',pg)
H
hjdhnx 已提交
586
        logger.info(f'{self.getName()}搜索链接:{url}')
587
        r = requests.get(url, headers=self.headers)
H
hjdhnx 已提交
588
        r.encoding = self.encoding
H
hjdhnx 已提交
589
        html = r.text
590 591 592 593 594 595
        if not self.搜索:
            return self.blank()
        p = self.一级.split(';') if self.搜索 == '*' and self.一级 else self.搜索.split(';')  # 解析
        if len(p) < 5:
            return self.blank()

H
hjdhnx 已提交
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
        jsp = jsoup(self.url)
        pdfh = jsp.pdfh
        pdfa = jsp.pdfa
        pd = jsp.pd
        pq = jsp.pq
        items = pdfa(html, p[0])
        videos = []
        for item in items:
            # print(item)
            title = pdfh(item, p[1])
            img = pd(item, p[2])
            desc = pdfh(item, p[3])
            link = pd(item, p[4])
            content = '' if len(p) < 6 else pdfh(item, p[5])
            # sid = self.regStr(sid, "/video/(\\S+).html")
            videos.append({
                "vod_id": link,
                "vod_name": title,
                "vod_pic": img,
                "vod_remarks": desc,
                "vod_content": content,
            })
        result = {
            'list': videos
        }
        return result

H
hjdhnx 已提交
623 624 625
    def playContent(self, play_url,jxs=None):
        if not jxs:
            jxs = []
H
hjdhnx 已提交
626 627
        if self.lazy:
            print(f'{play_url}->开始执行免嗅代码->{self.lazy}')
H
hjdhnx 已提交
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
            if not str(self.lazy).startswith('js:'):
                pycode = runPy(self.lazy)
                if pycode:
                    # print(pycode)
                    pos = pycode.find('def lazyParse')
                    if pos < 0:
                        return play_url
                    pyenv = safePython(self.lazy,pycode[pos:])
                    lazy_url = pyenv.action_task_exec('lazyParse',[play_url,self.d])
                    logger.info(f'播放免嗅结果:{lazy_url}')
                    if isinstance(lazy_url,str) and lazy_url.startswith('http'):
                        play_url = lazy_url
            else:
                jscode = str(self.lazy).split('js:')[1]
                # jscode = f'var input={play_url};{jscode}'
                # print(jscode)
H
hjdhnx 已提交
644 645 646
                py_ctx.update({
                    'input': play_url,
                    'd': self.d,
H
hjdhnx 已提交
647
                    'jxs':jxs,
H
hjdhnx 已提交
648 649 650 651
                    'pdfh': self.d.jsp.pdfh,
                    'pdfa': self.d.jsp.pdfa, 'pd': self.d.jsp.pd,
                })
                ctx = py_ctx
H
hjdhnx 已提交
652
                # print(ctx)
653 654
                jscode = getPreJs() + jscode
                # print(jscode)
H
hjdhnx 已提交
655
                loader,_ = runJScode(jscode,ctx=ctx)
H
hjdhnx 已提交
656 657
                # print(loader.toString())
                play_url = loader.eval('input')
H
hjdhnx 已提交
658
                logger.info(f'免嗅播放地址:{play_url}')
H
hjdhnx 已提交
659 660


H
hjdhnx 已提交
661 662 663 664 665
            return play_url
        else:
            logger.info(f'播放重定向到:{play_url}')
            return play_url

H
hjdhnx 已提交
666 667
if __name__ == '__main__':
    from utils import parser
H
hjdhnx 已提交
668
    # js_path = f'js/玩偶姐姐.js'
H
hjdhnx 已提交
669
    # js_path = f'js/555影视.js'
H
hjdhnx 已提交
670
    js_path = f'js/cokemv.js'
H
hjdhnx 已提交
671 672 673
    ctx, js_code = parser.runJs(js_path)
    rule = ctx.eval('rule')
    cms = CMS(rule)
H
hjdhnx 已提交
674
    print(cms.title)
H
hjdhnx 已提交
675
    print(cms.homeContent())
H
hjdhnx 已提交
676
    # print(cms.categoryContent('5',1))
677
    # print(cms.categoryContent('latest',1))
H
hjdhnx 已提交
678
    # print(cms.detailContent(['https://www.2345ka.com/v/45499.html']))
H
hjdhnx 已提交
679
    # print(cms.detailContent(1,['https://cokemv.me/voddetail/40573.html']))
H
hjdhnx 已提交
680
    # cms.categoryContent('dianying',1)
H
hjdhnx 已提交
681
    # print(cms.detailContent(['67391']))
H
hjdhnx 已提交
682
    # print(cms.searchContent('斗罗大陆'))