fix json exception

This commit is contained in:
jxxghp 2024-05-20 09:13:51 +08:00
parent fa47d9adeb
commit 07a6abde0e
2 changed files with 33 additions and 8 deletions

View File

@ -42,7 +42,10 @@ def read_subscribes(
subscribes = Subscribe.list(db) subscribes = Subscribe.list(db)
for subscribe in subscribes: for subscribe in subscribes:
if subscribe.sites: if subscribe.sites:
subscribe.sites = json.loads(str(subscribe.sites)) try:
subscribe.sites = json.loads(str(subscribe.sites))
except json.JSONDecodeError:
subscribe.sites = []
else: else:
subscribe.sites = [] subscribe.sites = []
return subscribes return subscribes
@ -168,7 +171,10 @@ def subscribe_mediaid(
meta.begin_season = season meta.begin_season = season
result = Subscribe.get_by_title(db, title=meta.name, season=meta.begin_season) result = Subscribe.get_by_title(db, title=meta.name, season=meta.begin_season)
if result and result.sites: if result and result.sites:
result.sites = json.loads(result.sites) try:
result.sites = json.loads(result.sites)
except json.JSONDecodeError:
result.sites = []
return result if result else Subscribe() return result if result else Subscribe()
@ -322,7 +328,10 @@ def read_subscribe(
historys = SubscribeHistory.list_by_type(db, mtype=mtype, page=page, count=count) historys = SubscribeHistory.list_by_type(db, mtype=mtype, page=page, count=count)
for history in historys: for history in historys:
if history and history.sites: if history and history.sites:
history.sites = json.loads(history.sites) try:
history.sites = json.loads(history.sites)
except json.JSONDecodeError:
history.sites = []
return historys return historys
@ -396,7 +405,10 @@ def read_subscribe(
return Subscribe() return Subscribe()
subscribe = Subscribe.get(db, subscribe_id) subscribe = Subscribe.get(db, subscribe_id)
if subscribe and subscribe.sites: if subscribe and subscribe.sites:
subscribe.sites = json.loads(subscribe.sites) try:
subscribe.sites = json.loads(subscribe.sites)
except json.JSONDecodeError:
subscribe.sites = []
return subscribe return subscribe

View File

@ -2,6 +2,7 @@ import json
import random import random
import time import time
from datetime import datetime from datetime import datetime
from json import JSONDecodeError
from typing import Dict, List, Optional, Union, Tuple from typing import Dict, List, Optional, Union, Tuple
from app.chain import ChainBase from app.chain import ChainBase
@ -459,7 +460,10 @@ class SubscribeChain(ChainBase):
获取订阅中涉及的站点清单 获取订阅中涉及的站点清单
""" """
if subscribe.sites: if subscribe.sites:
return json.loads(subscribe.sites) try:
return json.loads(subscribe.sites)
except JSONDecodeError:
return []
# 默认站点 # 默认站点
return self.systemconfig.get(SystemConfigKey.RssSites) or [] return self.systemconfig.get(SystemConfigKey.RssSites) or []
@ -780,7 +784,10 @@ class SubscribeChain(ChainBase):
return return
note = [] note = []
if subscribe.note: if subscribe.note:
note = json.loads(subscribe.note) try:
note = json.loads(subscribe.note)
except JSONDecodeError:
note = []
for context in downloads: for context in downloads:
meta = context.meta_info meta = context.meta_info
mediainfo = context.media_info mediainfo = context.media_info
@ -811,7 +818,10 @@ class SubscribeChain(ChainBase):
return False return False
if not episodes: if not episodes:
return False return False
note = json.loads(subscribe.note) try:
note = json.loads(subscribe.note)
except JSONDecodeError:
return False
if set(episodes).issubset(set(note)): if set(episodes).issubset(set(note)):
return True return True
return False return False
@ -1023,7 +1033,10 @@ class SubscribeChain(ChainBase):
for subscribe in self.subscribeoper.list(): for subscribe in self.subscribeoper.list():
if not subscribe.sites: if not subscribe.sites:
continue continue
sites = json.loads(subscribe.sites) or [] try:
sites = json.loads(subscribe.sites)
except JSONDecodeError:
sites = []
if site_id not in sites: if site_id not in sites:
continue continue
sites.remove(site_id) sites.remove(site_id)