import json from Orm import Video from playhouse.shortcuts import model_to_dict, dict_to_model class VideoService: def getOneByVideoId(videoId): return Video.get_or_none(Video.videoId == videoId) def createOne(videoId, channelId, videoTitle, videoLen, videoType, videoPublishTime, videoLanguage, isDownload): Video.create(videoId=videoId, channelId=channelId, videoTitle=videoTitle, videoLen=videoLen, videoType=videoType, videoPublishTime=videoPublishTime, videoLanguage=videoLanguage, isDownload=isDownload) def updateLenByVideoId(videoId, len): Video.update(videoLen=len).where(Video.videoId == videoId).execute() def getLastVideoByChannelId(channelId): return Video.select().where(Video.channelId == channelId).order_by(Video.videoPublishTime.desc()).get() def getFirstVideoByChannelId(channelId): return Video.select().where(Video.channelId == channelId).order_by(Video.videoPublishTime).get() def checkExist(channelId): query = Video.select().where(Video.channelId == channelId) return query.exists() def getVideosByTime(startTime,endTime): return Video.select().where(Video.videoPublishTime >= startTime,Video.videoPublishTime <= endTime).execute()