iptv/iptv/m3u8test.py
2025-09-20 12:00:56 +08:00

40 lines
923 B
Python

from appPublic.log import debug, exception
from appPublic.uniqueID import getID
from aiohttp import (
client
)
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 Exception as e:
debug(f'{c.url}, {e}')
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'
})