bugfix
This commit is contained in:
parent
caa91cf9e4
commit
1a53694f75
@ -23,12 +23,77 @@ async def download(url):
|
|||||||
clist = m3u.m3uParser(txt)
|
clist = m3u.m3uParser(txt)
|
||||||
return clist
|
return clist
|
||||||
|
|
||||||
|
async def check_if_exists(url):
|
||||||
|
env = ServerEnv()
|
||||||
|
dbname = env.get_module_dbname('iptv')
|
||||||
|
db = DBPools()
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
sql = "select * from iptvchannles where url = ${url}$"
|
||||||
|
recs = await sor.sqlExe(sql, {'url': url})
|
||||||
|
if len(recs) > 0:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
async def load_url_iptv(media_type,url, dbname):
|
async def write_goodchannel(b):
|
||||||
|
debug(f'write badchannels({b.url})')
|
||||||
|
env = ServerEnv()
|
||||||
|
dbname = env.get_module_dbname('iptv')
|
||||||
|
db = DBPools()
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
sql = """insert into iptvchannels
|
||||||
|
(
|
||||||
|
id,
|
||||||
|
tv_group,
|
||||||
|
tv_name,
|
||||||
|
logo_url,
|
||||||
|
url,
|
||||||
|
media_type,
|
||||||
|
download_date,
|
||||||
|
del_flg
|
||||||
|
)
|
||||||
|
values
|
||||||
|
(
|
||||||
|
${id}$,
|
||||||
|
${tv_group}$,
|
||||||
|
${tv_name}$,
|
||||||
|
${logo_url}$,
|
||||||
|
${url}$,
|
||||||
|
${media_type}$,
|
||||||
|
${download_date}$,
|
||||||
|
'0'
|
||||||
|
)"""
|
||||||
|
query = """select * from iptvchannels where url=${url}$"""
|
||||||
|
q = await sor.sqlExe(query,{'url', b['url']})
|
||||||
|
if len(q) == 0:
|
||||||
|
r = copy(b)
|
||||||
|
r['media_type'] = 'iptv'
|
||||||
|
r['id'] = getID()
|
||||||
|
if not r.get('tv_group'):
|
||||||
|
r['tv_group'] = r.get('group-title','')[:500]
|
||||||
|
if not r.get('tv_name'):
|
||||||
|
r['tv_name'] = r.get('name','')[:500]
|
||||||
|
if not r.get('logo_url'):
|
||||||
|
r['logo_url'] = r.get('tvg-logo',None)
|
||||||
|
if r['logo_url'] and len(r['logo_url']) > 1000:
|
||||||
|
r['logo_url'] = None
|
||||||
|
if len(r['url']) >= 1000:
|
||||||
|
return
|
||||||
|
dt = datetime.now()
|
||||||
|
r['download_date'] = '%d-%02d-%02d' % (dt.year,dt.month,dt.day)
|
||||||
|
await sor.sqlExe(sql,r)
|
||||||
|
|
||||||
|
async def load_url_iptv(url):
|
||||||
clist = await download(url)
|
clist = await download(url)
|
||||||
if clist:
|
debug(f'clist={clist}')
|
||||||
debug('%d channels' % len(goodchannels))
|
newchannels = []
|
||||||
good, bad = await test_channels(clist, if_ok=write_goodchannel)
|
for c in clist:
|
||||||
|
b = await check_if_exists(c.url)
|
||||||
|
if not b:
|
||||||
|
newchannels.append(c)
|
||||||
|
|
||||||
|
if len(newchannels) > 0:
|
||||||
|
debug('%d new channels' % len(newchannels))
|
||||||
|
good, bad = await test_channels(newchannels, if_ok=write_goodchannel)
|
||||||
debug(f'{len(good)} new channels add {len(bad)} channels exists')
|
debug(f'{len(good)} new channels add {len(bad)} channels exists')
|
||||||
else:
|
else:
|
||||||
debug(f'{url} return None')
|
debug(f'{url} return None')
|
||||||
|
|||||||
124
iptv/m3u8test.py
124
iptv/m3u8test.py
@ -1,8 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
from appPublic.log import debug, exception
|
from appPublic.log import debug, exception
|
||||||
from appPublic.uniqueID import getID
|
from appPublic.uniqueID import getID
|
||||||
from sqlor.dbpools import DBPools
|
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
from aiohttp import (
|
from aiohttp import (
|
||||||
client,
|
client,
|
||||||
ClientSession
|
ClientSession
|
||||||
@ -14,85 +12,55 @@ from sqlor.dbpools import DBPools
|
|||||||
async def test_channels(channels,if_failed=None, if_ok=None):
|
async def test_channels(channels,if_failed=None, if_ok=None):
|
||||||
goodchannels = []
|
goodchannels = []
|
||||||
badchannels = []
|
badchannels = []
|
||||||
|
for c in channels:
|
||||||
|
try:
|
||||||
|
t1 = time.time()
|
||||||
|
async with ClientSession() as sess:
|
||||||
|
async with sess.get(c.url) as resp:
|
||||||
|
if resp.status != 200:
|
||||||
|
debug(f'{resp.status=}, {type(resp.status)=}')
|
||||||
|
badchannels.append(c)
|
||||||
|
if if_failed:
|
||||||
|
c['errorcode'] = resp.status
|
||||||
|
await if_failed(c)
|
||||||
|
else:
|
||||||
|
goodchannels.append(c)
|
||||||
|
if if_ok:
|
||||||
|
debug(f'write good channels')
|
||||||
|
t2 = time.time()
|
||||||
|
c['channel_delay'] = t2 - t1
|
||||||
|
await if_ok(c)
|
||||||
|
except Exception as e:
|
||||||
|
debug(f'{c.url}, {e}')
|
||||||
|
badchannels.append(c)
|
||||||
|
if if_failed:
|
||||||
|
c['errorcode'] = 600
|
||||||
|
await if_failed(c)
|
||||||
|
return goodchannels, badchannels
|
||||||
|
|
||||||
|
async def write_badchannel(b):
|
||||||
|
debug(f'write badchannels({b.url})')
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
dbname = env.get_module_dbname('iptv')
|
dbname = env.get_module_dbname('iptv')
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
for c in channels:
|
await sor.C('badchannels', {
|
||||||
try:
|
'id':getID(),
|
||||||
t1 = time.time()
|
'channelid': b.id,
|
||||||
async with ClientSession() as sess:
|
'errorcode': b.errorcode
|
||||||
async with sess.get(c.url) as resp:
|
})
|
||||||
debug(f'{resp.status=}, {type(resp.status)=}')
|
sql = "update iptvchannels set del_flg='1' where id=${id}$"
|
||||||
if resp.status != 200:
|
await sor.sqlExe(sql, {'id': b.id})
|
||||||
badchannels.append(c)
|
debug(f'write badchannels finished')
|
||||||
if if_ok:
|
|
||||||
t2 = time.time()
|
|
||||||
c['channel_delay'] = t2 - t1
|
|
||||||
await if_ok(sor, c)
|
|
||||||
else:
|
|
||||||
goodchannels.append(c)
|
|
||||||
if if_failed:
|
|
||||||
c['errorcode'] = resp.status
|
|
||||||
await if_failed(sor, c)
|
|
||||||
except Exception as e:
|
|
||||||
debug(f'{c.url}, {e}')
|
|
||||||
badchannels.append(c)
|
|
||||||
if if_failed:
|
|
||||||
await if_failed(sor, c)
|
|
||||||
return goodchannels, badchannels
|
|
||||||
|
|
||||||
async def write_badchannel(sor, b):
|
async def write_goodchannel(b):
|
||||||
await sor.C('badchannels', {
|
debug(f'write goodchannels({b.url})')
|
||||||
'id':getID(),
|
env = ServerEnv()
|
||||||
'channelid': b.id,
|
dbname = env.get_module_dbname('iptv')
|
||||||
'errorcode': b.errorcode
|
db = DBPools()
|
||||||
})
|
async with db.sqlorContext(dbname) as sor:
|
||||||
sql = "update iptvchannels set del_flg='1' where id=${id}$"
|
sql = "update iptvchannels set channel_delay = ${channel_delay}$ where id=${id}$"
|
||||||
await sor.sqlExe(sql, {'id': b.id})
|
await sor.sqlExe(sql, {'id':b.id, 'channel_delay': b.channel_delay})
|
||||||
|
|
||||||
async def write_goodchannel(sor, b):
|
|
||||||
sql = """insert into iptvchannels
|
|
||||||
(
|
|
||||||
id,
|
|
||||||
tv_group,
|
|
||||||
tv_name,
|
|
||||||
logo_url,
|
|
||||||
url,
|
|
||||||
media_type,
|
|
||||||
download_date,
|
|
||||||
del_flg
|
|
||||||
)
|
|
||||||
values
|
|
||||||
(
|
|
||||||
${id}$,
|
|
||||||
${tv_group}$,
|
|
||||||
${tv_name}$,
|
|
||||||
${logo_url}$,
|
|
||||||
${url}$,
|
|
||||||
${media_type}$,
|
|
||||||
${download_date}$,
|
|
||||||
'0'
|
|
||||||
)"""
|
|
||||||
query = """select * from iptvchannels where url=${url}$"""
|
|
||||||
q = await sor.sqlExe(query,{'url', b['url']})
|
|
||||||
if len(q) == 0:
|
|
||||||
r = copy(b)
|
|
||||||
r['media_type'] = media_type
|
|
||||||
r['id'] = getID()
|
|
||||||
if not r.get('tv_group'):
|
|
||||||
r['tv_group'] = r.get('group-title','')[:500]
|
|
||||||
if not r.get('tv_name'):
|
|
||||||
r['tv_name'] = r.get('name','')[:500]
|
|
||||||
if not r.get('logo_url'):
|
|
||||||
r['logo_url'] = r.get('tvg-logo',None)
|
|
||||||
if r['logo_url'] and len(r['logo_url']) > 1000:
|
|
||||||
r['logo_url'] = None
|
|
||||||
if len(r['url']) >= 1000:
|
|
||||||
return
|
|
||||||
dt = datetime.now()
|
|
||||||
r['download_date'] = '%d-%02d-%02d' % (dt.year,dt.month,dt.day)
|
|
||||||
await sor.sqlExe(sql,r)
|
|
||||||
|
|
||||||
async def kickout_badchannels():
|
async def kickout_badchannels():
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
@ -101,5 +69,7 @@ async def kickout_badchannels():
|
|||||||
channels = []
|
channels = []
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
channels = await sor.R('iptvchannels', {'del_flg':'0'})
|
channels = await sor.R('iptvchannels', {'del_flg':'0'})
|
||||||
good, bad2 = await test_channels(channels, if_failed=write_badchannel)
|
good, bad2 = await test_channels(channels,
|
||||||
|
if_ok=write_goodchannel,
|
||||||
|
if_failed=write_badchannel)
|
||||||
debug(f'{len(good)=},{len(bad)}')
|
debug(f'{len(good)=},{len(bad)}')
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
url = params_kw.url
|
url = params_kw.url
|
||||||
debug(f'{params_kw=}, {url=}')
|
debug(f'{params_kw=}, {url=}')
|
||||||
try:
|
try:
|
||||||
x = await load_url_iptv('iptv', url, 'iptvdb')
|
dbname = get_module_dbname('iptv')
|
||||||
|
x = background_reco(load_url_iptv, url)
|
||||||
return {
|
return {
|
||||||
"widgettype":"Message",
|
"widgettype":"Message",
|
||||||
"options":{
|
"options":{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user