forked from by275/klive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_streamlink.py
156 lines (122 loc) · 4.58 KB
/
source_streamlink.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
#########################################################
# python
import os
import sys
import logging
import traceback
import json
import re
import urllib
import requests
import threading
# third-party
# sjva 공용
# 패키지
from .plugin import logger, package_name
from .model import ModelSetting, ModelChannel
from .source_base import SourceBase
#########################################################
class StreamlinkItem:
ch_list = None
def __init__(self, id, title, url):
self.id = id.strip()
self.title = title.strip()
self.url = url.strip()
StreamlinkItem.ch_list[id] = self
class SourceStreamlink(SourceBase):
channel_list = None
@staticmethod
def install():
try:
def func():
import system
import framework.common.util as CommonUtil
commands = [['msg', u'잠시만 기다려주세요.']]
if CommonUtil.is_docker():
commands.append(['apk', 'add', '--no-cache', '--virtual', '.build-deps', 'gcc', 'g++', 'make', 'libffi-dev', 'openssl-dev'])
commands.append(['pip', 'install', '--upgrade', 'pip'])
commands.append(['pip', 'install', '--upgrade', 'setuptools'])
commands.append(['pip', 'install', 'streamlink'])
if CommonUtil.is_docker():
commands.append(['apk', 'del', '.build-deps'])
commands.append(['msg', u'설치가 완료되었습니다.'])
system.SystemLogicCommand.start('설치', commands)
t = threading.Thread(target=func, args=())
t.setDaemon(True)
t.start()
except Exception as e:
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
@staticmethod
def is_installed():
try:
import streamlink
return True
except Exception as e:
pass
return False
@classmethod
def get_channel_list(cls):
try:
tmp = ModelSetting.get('streamlink_list')
StreamlinkItem.ch_list = {}
ret = []
for item in tmp.splitlines():
if item.strip() == '':
continue
tmp2 = item.split('|')
if len(tmp2) != 3:
continue
c = ModelChannel(cls.source_name, tmp2[0], tmp2[1], None, True)
StreamlinkItem(tmp2[0], tmp2[1], tmp2[2])
c.current = ''
ret.append(c)
except Exception as e:
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
return ret
@classmethod
def get_url(cls, source_id, quality, mode):
try:
#logger.debug('source_id:%s, quality:%s, mode:%s', source_id, quality, mode)
"""
import streamlink
data = streamlink.streams(StreamlinkItem.ch_list[source_id].url)
url = data[ModelSetting.get('streamlink_quality')].url
"""
from streamlink import Streamlink
s = Streamlink()
#logger.debug(StreamlinkItem.ch_list[source_id].url)
data = s.streams(StreamlinkItem.ch_list[source_id].url)
#logger.debug(len(data))
try:
stream = data[ModelSetting.get('streamlink_quality')]
url = stream.url
except Exception as e:
#logger.error('Exception:%s', e)
#logger.error(traceback.format_exc())
if StreamlinkItem.ch_list[source_id].url.lower().find('youtube') != -1:
for k, t in data.items():
try:
url = t.url
except Exception as e:
#logger.error('Exception:%s', e)
#logger.error(traceback.format_exc())
pass
if mode == 'web_play':
return 'return_after_read', url
return 'redirect', url
except Exception as e:
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
return
@classmethod
def get_return_data(cls, source_id, url, mode):
try:
data = requests.get(url).text
return cls.change_redirect_data(data)
except Exception as e:
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
return data