Пример #1
0
    def episode_detail(self, episode_id):
        session = SessionManager.Session()
        try:
            (episode, bangumi) = session.query(Episode, Bangumi).\
                join(Bangumi).\
                filter(Episode.id == episode_id).one()
            episode_dict = row2dict(episode)
            episode_dict['bangumi'] = row2dict(bangumi)
            episode_dict['thumbnail'] = utils.generate_thumbnail_link(
                episode, bangumi)

            if episode.status == Episode.STATUS_DOWNLOADED:
                episode_dict['videos'] = []
                torrent_file_cur = session.query(TorrentFile).filter(
                    TorrentFile.episode_id == episode_id)
                for torrent_file in torrent_file_cur:
                    episode_dict['videos'].append(
                        utils.generate_video_link(str(bangumi.id),
                                                  torrent_file.file_path))

            return json_resp(episode_dict)
        except NoResultFound:
            raise ClientError(ClientError.NOT_FOUND, 404)
        except Exception as error:
            raise error
        finally:
            SessionManager.Session.remove()
Пример #2
0
    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_dict['bangumi'] = row2dict(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)

            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:
                    video_file_dict = row2dict(video_file)
                    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()
Пример #3
0
    def episode_detail(self, episode_id):
        session = SessionManager.Session()
        try:
            (episode, bangumi) = session.query(Episode, Bangumi).\
                join(Bangumi).\
                filter(Episode.id == episode_id).one()
            episode_dict = row2dict(episode)
            episode_dict['bangumi'] = row2dict(bangumi)
            episode_dict['thumbnail'] = utils.generate_thumbnail_link(episode, bangumi)

            if episode.status == Episode.STATUS_DOWNLOADED:
                episode_dict['videos'] = []
                torrent_file_cur = session.query(TorrentFile).filter(TorrentFile.episode_id == episode_id)
                for torrent_file in torrent_file_cur:
                    episode_dict['videos'].append(utils.generate_video_link(str(bangumi.id), torrent_file.file_path))

            return json_resp(episode_dict)
        except NoResultFound:
            raise ClientError(ClientError.NOT_FOUND, 404)
        except Exception as error:
            raise error
        finally:
            SessionManager.Session.remove()