bugfix
This commit is contained in:
parent
7762c1a358
commit
4a8e8fdfcc
37
app/iptv.py
37
app/iptv.py
@ -1,37 +0,0 @@
|
|||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
from appPublic.worker import awaitify
|
|
||||||
from appPublic.jsonConfig import getConfig
|
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
from sqlor.dbpools import DBPools
|
|
||||||
from ahserver.webapp import webapp
|
|
||||||
from downloadchannels import load_url_iptv
|
|
||||||
from time import time
|
|
||||||
from appbase.init import load_appbase
|
|
||||||
from rbac.init import load_rbac
|
|
||||||
|
|
||||||
def get_module_dbname(m):
|
|
||||||
return 'iptvdb'
|
|
||||||
|
|
||||||
async def get_channel_by_id(id):
|
|
||||||
db = DBPools()
|
|
||||||
async with db.sqlorContext('iptvdb') as sor:
|
|
||||||
sql = "select * from iptvchannels where id=${id}$"
|
|
||||||
recs = await sor.sqlExe(sql, {'id':id})
|
|
||||||
if len(recs) < 1:
|
|
||||||
return None
|
|
||||||
return recs[0]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def init_func():
|
|
||||||
g = ServerEnv()
|
|
||||||
load_appbase()
|
|
||||||
load_rbac()
|
|
||||||
g.get_module_dbname = get_module_dbname
|
|
||||||
g.load_url_iptv = load_url_iptv
|
|
||||||
g.get_channel_by_id = get_channel_by_id
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
webapp(init_func)
|
|
||||||
|
|
||||||
19
iptv/init.py
Normal file
19
iptv/init.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from iptv.downloadchannels import load_url_iptv
|
||||||
|
from iptv.m3u8test import kickout_badchannels
|
||||||
|
|
||||||
|
async def get_channel_by_id(id):
|
||||||
|
db = DBPools()
|
||||||
|
env = ServerEnv()
|
||||||
|
dbname = env.get_module_dbname('iptv')
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
recs = await sor.R('iptvchannels', {'id':id, 'del_flg':'0'})
|
||||||
|
if len(recs) < 1:
|
||||||
|
return None
|
||||||
|
return recs[0]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def load_iptv():
|
||||||
|
env = ServerEnv()
|
||||||
|
env.load_url_iptv = load_url_iptv
|
||||||
|
env.kickout_badchannels = kickout_badchannels
|
||||||
|
env.get_channel_by_id = get_channel_by_id
|
||||||
39
iptv/m3u8test.py
Normal file
39
iptv/m3u8test.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from appPublic.log import debug, exception
|
||||||
|
from aiohttp import client, ClientConnectionError
|
||||||
|
from ahserver.serverenv import ServerEnv
|
||||||
|
from sqlor.dbpools import DBPools
|
||||||
|
|
||||||
|
async def test_channels(channels):
|
||||||
|
goodchannels = []
|
||||||
|
badchannels = []
|
||||||
|
for c in channels:
|
||||||
|
try:
|
||||||
|
x = await client.get(c.url)
|
||||||
|
x.close()
|
||||||
|
goodchannels.append(c)
|
||||||
|
except ClientConnectionError as e:
|
||||||
|
c.error_code = 499
|
||||||
|
badchannels.append(c)
|
||||||
|
except Exception as e
|
||||||
|
debug(f'{c.url}, {e}')
|
||||||
|
c.errorcode = x.status_code
|
||||||
|
badchannels.append(c)
|
||||||
|
return goodchannels, badchannels
|
||||||
|
|
||||||
|
async def kickout_badchannels():
|
||||||
|
db = DBPools()
|
||||||
|
env = ServerEnv()
|
||||||
|
dbname = env.get_module_dbname('iptv')
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
channels = await sor.R('iptvchannels', {'del_flg':'0'})
|
||||||
|
good, bad = await test_channels(channels)
|
||||||
|
for b in bad:
|
||||||
|
await sor.C('baschannels', {
|
||||||
|
'id':getID(),
|
||||||
|
'channelid': b.id,
|
||||||
|
'errorcode': b.errorcode
|
||||||
|
})
|
||||||
|
await sor.U('iptvchannels', {
|
||||||
|
'id': b.id,
|
||||||
|
'del_flg': '1'
|
||||||
|
})
|
||||||
78
m3u.py
78
m3u.py
@ -1,78 +0,0 @@
|
|||||||
import codecs
|
|
||||||
|
|
||||||
def tvgParser(txt):
|
|
||||||
d = {}
|
|
||||||
buf = ''
|
|
||||||
k = ''
|
|
||||||
inbrace = False
|
|
||||||
for c in txt:
|
|
||||||
if c == '"':
|
|
||||||
if inbrace:
|
|
||||||
inbrace = False
|
|
||||||
d[k] = buf
|
|
||||||
buf = ''
|
|
||||||
k = ''
|
|
||||||
else:
|
|
||||||
inbrace = True
|
|
||||||
continue
|
|
||||||
|
|
||||||
if c == '=':
|
|
||||||
k = buf
|
|
||||||
buf = ''
|
|
||||||
continue
|
|
||||||
|
|
||||||
if c == ' ':
|
|
||||||
if inbrace:
|
|
||||||
buf = '%s%s' % (buf,c)
|
|
||||||
continue
|
|
||||||
|
|
||||||
buf = '%s%s' % (buf,c)
|
|
||||||
|
|
||||||
if k != '':
|
|
||||||
v = buf
|
|
||||||
d[k] = v
|
|
||||||
return d
|
|
||||||
|
|
||||||
def channelInfo(l):
|
|
||||||
g = {}
|
|
||||||
e = l.split(',')
|
|
||||||
info = e[-2]
|
|
||||||
fo=info.split(' ',1)
|
|
||||||
if len(fo) == 2:
|
|
||||||
_,tvginfo=info.split(' ',1)
|
|
||||||
g = tvgParser(tvginfo)
|
|
||||||
g['name'] = e[-1]
|
|
||||||
return g
|
|
||||||
|
|
||||||
def m3uParser(text):
|
|
||||||
text = ''.join(text.split('\r'))
|
|
||||||
newchannel = False
|
|
||||||
channels = []
|
|
||||||
for i,line in enumerate(text.split('\n')):
|
|
||||||
if i==0 and not line.startswith('#EXTM3U'):
|
|
||||||
return None
|
|
||||||
if i == 0:
|
|
||||||
continue
|
|
||||||
if line == '':
|
|
||||||
continue
|
|
||||||
if line.startswith('#EXTINF'):
|
|
||||||
channel = channelInfo(line)
|
|
||||||
status = 'url'
|
|
||||||
continue
|
|
||||||
if line.startswith('http://') or line.startswith('https://'):
|
|
||||||
channel['url'] = line
|
|
||||||
channels.append(channel)
|
|
||||||
continue
|
|
||||||
return channels
|
|
||||||
|
|
||||||
def testfile(filename):
|
|
||||||
with codecs.open(filename,'r','utf-8') as f:
|
|
||||||
text = f.read()
|
|
||||||
m3uParser(text)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
import sys
|
|
||||||
testfile(sys.argv[1])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user