-
Notifications
You must be signed in to change notification settings - Fork 7
/
source_tving.py
67 lines (59 loc) · 2.46 KB
/
source_tving.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os, sys, traceback, requests, re
from framework import SystemModelSetting
from .plugin import logger, package_name
from .model import ModelSetting, ModelChannel
from .source_base import SourceBase
from support.site.tving import SupportTving
#########################################################
class SourceTving(SourceBase):
@classmethod
def prepare(cls, source_id, source_pw, arg):
cls.login_data = None
@classmethod
def get_channel_list(cls):
try:
data = SupportTving.ins.get_live_list(list_type='live', include_drm=ModelSetting.get_bool('tving_include_drm'))
ret = []
for item in data:
c = ModelChannel(cls.source_name, item['id'], item['title'], item['img'], True)
if item['is_drm']:
c.is_drm_channel = True
c.current = item['episode_title']
ret.append(c)
except Exception as e:
logger.error(f'Exception:{str(e)}')
logger.error(traceback.format_exc())
return ret
@classmethod
def get_url(cls, source_id, quality, mode):
try:
quality = SupportTving.ins.get_quality_to_tving(quality)
data = SupportTving.ins.get_info(source_id, quality)
if SupportTving.ins.is_drm_channel(source_id):
return data
else:
return 'return_after_read', data['url']
except Exception as e:
logger.error(f'Exception:{str(e)}')
logger.error(traceback.format_exc())
@classmethod
def get_return_data(cls, source_id, url, mode):
try:
data = requests.get(url).text
matches = re.finditer(r"BANDWIDTH=(?P<bandwidth>\d+)", data, re.MULTILINE)
max_bandwidth = 0
for match in matches:
bw = int(match.group('bandwidth'))
if bw > max_bandwidth:
max_bandwidth = bw
temp = url.split('playlist.m3u8')
url1 = f"{temp[0]}chunklist_b{max_bandwidth}.m3u8{temp[1]}"
data1 = requests.get(url1).text
data1 = data1.replace('media', '%smedia' % temp[0]).replace('.ts', '.ts%s' % temp[1])
if mode == 'web_play':
data1 = cls.change_redirect_data(data1)
return data1
except Exception as e:
logger.error(f'Exception:{str(e)}')
logger.error(traceback.format_exc())
return url