iptv/wwwroot/get_default_iptv.dspy
2025-07-16 15:07:06 +08:00

26 lines
797 B
Plaintext

async def getDeviceLastPlay(deviceid):
db = DBPools()
async with db.sqlorContext('iptvdb') as sor:
recs = await sor.R('device', {'id':deviceid})
if len(recs) < 1:
await sor.C('device', {'id':deviceid})
return None
sql = "select a.deviceid, b.* from playhistory a, iptvchannels b where a.channelid = b.id and a.deviceid = ${deviceid}$ order by playtime desc"
recs = await sor.sqlExe(sql, {'deviceid':deviceid})
if len(recs) < 1:
return None
return recs[0]
debug(f'get_default_iptv.dspy:{params_kw=}')
rec = await getDeviceLastPlay(params_kw.deviceid)
if rec:
return rec
db = DBPools()
async with db.sqlorContext('iptvdb') as sor:
sql = "select * from iptvchannels order by download_date desc"
recs = await sor.sqlExe(sql, {})
i = random.randint(0, 10)
return recs[i]