def get_bangumi(self, id, user_id): try: session = SessionManager.Session() bangumi = session.query(Bangumi).\ options(joinedload(Bangumi.episodes).joinedload(Episode.thumbnail_image)).\ options(joinedload(Bangumi.cover_image)).\ filter(Bangumi.delete_mark == None).\ filter(Bangumi.id == id).\ one() favorite = session.query(Favorites).\ filter(Favorites.bangumi_id == id).\ filter(Favorites.user_id == user_id).\ first() watch_progress_list = session.query(WatchProgress).\ filter(WatchProgress.bangumi_id == bangumi.id).\ filter(WatchProgress.user_id == user_id).\ all() episodes = [] watch_progress_hash_table = {} for watch_progress in watch_progress_list: watch_progress_dict = row2dict(watch_progress) watch_progress_hash_table[ watch_progress.episode_id] = watch_progress_dict for episode in bangumi.episodes: if episode.delete_mark is not None: continue eps = row2dict(episode) eps['thumbnail'] = utils.generate_thumbnail_link( episode, bangumi) utils.process_episode_dict(episode, eps) if episode.id in watch_progress_hash_table: eps['watch_progress'] = watch_progress_hash_table[ episode.id] episodes.append(eps) bangumi_dict = row2dict(bangumi) if favorite is not None: bangumi_dict['favorite_status'] = favorite.status bangumi_dict['episodes'] = episodes bangumi_dict['cover'] = utils.generate_cover_link(bangumi) utils.process_bangumi_dict(bangumi, bangumi_dict) return json_resp({'data': bangumi_dict}) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) finally: SessionManager.Session.remove()
def get_bangumi(self, id, user_id): try: session = SessionManager.Session() bangumi = session.query(Bangumi).\ options(joinedload(Bangumi.episodes).joinedload(Episode.thumbnail_image)).\ options(joinedload(Bangumi.cover_image)).\ filter(Bangumi.delete_mark == None).\ filter(Bangumi.id == id).\ one() favorite = session.query(Favorites).\ filter(Favorites.bangumi_id == id).\ filter(Favorites.user_id == user_id).\ first() watch_progress_list = session.query(WatchProgress).\ filter(WatchProgress.bangumi_id == bangumi.id).\ filter(WatchProgress.user_id == user_id).\ all() episodes = [] watch_progress_hash_table = {} for watch_progress in watch_progress_list: watch_progress_dict = row2dict(watch_progress, WatchProgress) watch_progress_hash_table[watch_progress.episode_id] = watch_progress_dict for episode in bangumi.episodes: if episode.delete_mark is not None: continue eps = row2dict(episode, Episode) eps['thumbnail'] = utils.generate_thumbnail_link(episode, bangumi) utils.process_episode_dict(episode, eps) if episode.id in watch_progress_hash_table: eps['watch_progress'] = watch_progress_hash_table[episode.id] episodes.append(eps) bangumi_dict = row2dict(bangumi, Bangumi) if favorite is not None: bangumi_dict['favorite_status'] = favorite.status bangumi_dict['episodes'] = episodes bangumi_dict['cover'] = utils.generate_cover_link(bangumi) utils.process_bangumi_dict(bangumi, bangumi_dict) return json_resp({'data': bangumi_dict}) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) finally: SessionManager.Session.remove()
def get_episode(self, episode_id): try: session = SessionManager.Session() episode = session.query(Episode).\ options(joinedload(Episode.thumbnail_image)).\ filter(Episode.id == episode_id).\ filter(Episode.delete_mark == None).\ all() episode_dict = row2dict(episode, Episode) utils.process_episode_dict(episode, episode_dict) return json_resp({'data': episode_dict}) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) finally: SessionManager.Session.remove()
def query_episode(): session = SessionManager.Session() try: (episode, bangumi) = session.query(Episode, Bangumi). \ join(Bangumi). \ options(joinedload(Bangumi.cover_image)). \ options(joinedload(Episode.thumbnail_image)). \ filter(Episode.delete_mark == None). \ filter(Episode.id == episode_id).\ one() episode_dict = row2dict(episode, Episode) episode_dict['bangumi'] = row2dict(bangumi, Bangumi) utils.process_bangumi_dict(bangumi, episode_dict['bangumi']) utils.process_episode_dict(episode, episode_dict) return episode_dict finally: SessionManager.Session.remove()
def episode_detail(self, episode_id, user_id): session = SessionManager.Session() try: (episode, bangumi) = session.query(Episode, Bangumi).\ join(Bangumi).\ options(joinedload(Bangumi.cover_image)).\ options(joinedload(Episode.thumbnail_image)).\ filter(Episode.delete_mark == None).\ filter(Episode.id == episode_id).\ one() watch_progress = session.query(WatchProgress).\ filter(WatchProgress.episode_id == episode_id).\ filter(WatchProgress.user_id == user_id).\ first() episode_dict = row2dict(episode, Episode) episode_dict['bangumi'] = row2dict(bangumi, Bangumi) episode_dict['bangumi']['cover'] = utils.generate_cover_link( bangumi) utils.process_bangumi_dict(bangumi, episode_dict['bangumi']) episode_dict['thumbnail'] = utils.generate_thumbnail_link( episode, bangumi) utils.process_episode_dict(episode, episode_dict) if watch_progress is not None: episode_dict['watch_progress'] = row2dict( watch_progress, WatchProgress) if episode.status == Episode.STATUS_DOWNLOADED: episode_dict['video_files'] = [] video_file_list = session.query(VideoFile).filter( VideoFile.episode_id == episode_id).all() for video_file in video_file_list: if video_file.status != VideoFile.STATUS_DOWNLOADED: continue video_file_dict = row2dict(video_file, VideoFile) video_file_dict['url'] = utils.generate_video_link( str(bangumi.id), video_file.file_path) episode_dict['video_files'].append(video_file_dict) return json_resp(episode_dict) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) finally: SessionManager.Session.remove()
def episode_detail(self, episode_id, user_id): session = SessionManager.Session() try: (episode, bangumi) = session.query(Episode, Bangumi).\ join(Bangumi).\ options(joinedload(Bangumi.cover_image)).\ options(joinedload(Episode.thumbnail_image)).\ filter(Episode.delete_mark == None).\ filter(Episode.id == episode_id).\ one() watch_progress = session.query(WatchProgress).\ filter(WatchProgress.episode_id == episode_id).\ filter(WatchProgress.user_id == user_id).\ first() episode_dict = row2dict(episode, Episode) episode_dict['bangumi'] = row2dict(bangumi, Bangumi) episode_dict['bangumi']['cover'] = utils.generate_cover_link(bangumi) utils.process_bangumi_dict(bangumi, episode_dict['bangumi']) episode_dict['thumbnail'] = utils.generate_thumbnail_link(episode, bangumi) utils.process_episode_dict(episode, episode_dict) if watch_progress is not None: episode_dict['watch_progress'] = row2dict(watch_progress, WatchProgress) if episode.status == Episode.STATUS_DOWNLOADED: episode_dict['video_files'] = [] video_file_list = session.query(VideoFile).filter(VideoFile.episode_id == episode_id).all() for video_file in video_file_list: if video_file.status != VideoFile.STATUS_DOWNLOADED: continue video_file_dict = row2dict(video_file, VideoFile) video_file_dict['url'] = utils.generate_video_link(str(bangumi.id), video_file.file_path) episode_dict['video_files'].append(video_file_dict) return json_resp(episode_dict) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) finally: SessionManager.Session.remove()
def get_bangumi(self, id): try: session = SessionManager.Session() bangumi = session.query(Bangumi).\ options(joinedload(Bangumi.episodes).joinedload(Episode.thumbnail_image)).\ options(joinedload(Bangumi.cover_image)). \ options(joinedload(Bangumi.created_by)). \ options(joinedload(Bangumi.maintained_by)). \ filter(Bangumi.id == id).\ filter(Bangumi.delete_mark == None).\ one() episodes = [] for episode in bangumi.episodes: if episode.delete_mark is not None: continue eps = row2dict(episode, Episode) eps['thumbnail'] = utils.generate_thumbnail_link( episode, bangumi) utils.process_episode_dict(episode, eps) episodes.append(eps) bangumi_dict = row2dict(bangumi, Bangumi) bangumi_dict['episodes'] = episodes utils.process_bangumi_dict(bangumi, bangumi_dict) self.__process_user_obj_in_bangumi(bangumi, bangumi_dict) bangumi_dict['cover'] = utils.generate_cover_link(bangumi) return json_resp({'data': bangumi_dict}) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) except Exception as exception: raise exception finally: SessionManager.Session.remove()
def get_bangumi(self, id): try: session = SessionManager.Session() bangumi = session.query(Bangumi).\ options(joinedload(Bangumi.episodes).joinedload(Episode.thumbnail_image)).\ options(joinedload(Bangumi.cover_image)). \ options(joinedload(Bangumi.created_by)). \ options(joinedload(Bangumi.maintained_by)). \ filter(Bangumi.id == id).\ filter(Bangumi.delete_mark == None).\ one() episodes = [] for episode in bangumi.episodes: if episode.delete_mark is not None: continue eps = row2dict(episode, Episode) eps['thumbnail'] = utils.generate_thumbnail_link(episode, bangumi) utils.process_episode_dict(episode, eps) episodes.append(eps) bangumi_dict = row2dict(bangumi, Bangumi) bangumi_dict['episodes'] = episodes utils.process_bangumi_dict(bangumi, bangumi_dict) self.__process_user_obj_in_bangumi(bangumi, bangumi_dict) bangumi_dict['cover'] = utils.generate_cover_link(bangumi) return json_resp({'data': bangumi_dict}) except NoResultFound: raise ClientError(ClientError.NOT_FOUND, 404) except Exception as exception: raise exception finally: SessionManager.Session.remove()