예제 #1
0
def add_episode():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("opening", type=helpers.opening, location="json")
    parser.argument("position", type=helpers.position, required=True)
    parser.argument("slug", type=helpers.anime, required=True)
    parser.argument("ending", type=int)
    parser.argument("name", type=str)
    args = parser.parse()

    anime = args["slug"]
    helpers.is_member(request.account, anime.teams)

    index = AnimeService.position_index(anime, args["position"])
    if index is None:
        episode = AnimeService.get_episode(args["position"])
        AnimeService.add_episode(anime, episode)
    else:
        episode = anime.episodes[index]

    fields = ["name", "opening", "ending"]
    for field in fields:
        if args[field]:
            episode[field] = args[field]

    anime.save()
    result["data"] = anime.dict(True)

    return result
예제 #2
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("position", type=int, required=True)
        parser.add_argument("team", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        team = TeamService.get_by_slug(args["team"])
        if team is None:
            return abort("team", "not-found")

        if request.account not in team.members:
            return abort("account", "not-team-member")

        anime = AnimeService.get_by_slug(args["slug"])
        if anime is None:
            return abort("anime", "not-found")

        episode = AnimeService.find_position(anime, args["position"])
        if episode is None:
            return abort("episodes", "not-found")

        FileService.destroy(episode.video)
        AnimeService.remove_episode(anime, episode)

        result["data"] = anime.dict(True)
        return result
예제 #3
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("video", type=FileStorage, location="files")
        parser.add_argument("position", type=int, required=True)
        parser.add_argument("team", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        parser.add_argument("params", type=dict, default={})
        args = parser.parse_args()

        team = TeamService.get_by_slug(args["team"])
        if team is None:
            return abort("team", "not-found")

        if request.account not in team.members:
            return abort("account", "not-team-member")

        anime = AnimeService.get_by_slug(args["slug"])
        if anime is None:
            return abort("anime", "not-found")

        episode = AnimeService.find_position(anime, args["position"])
        if episode is None:
            return abort("episodes", "not-found")

        video = episode.video
        if args["video"] is not None:
            helper = UploadHelper(request.account, args["video"], "video")
            data = helper.upload_video()

            if type(data) is Response:
                return data

            FileService.destroy(episode.video)
            video = data

        name = episode.name
        if "name" in args["params"]:
            name = args["params"]["name"]

        position = episode.position
        if "position" in args["params"]:
            if args["position"] < 0:
                return abort("general", "out-of-range")

            episode_check = AnimeService.find_position(anime, args["position"])
            if episode_check is not None:
                return abort("episodes", "position-exists")

            position = args["params"]["position"]

        AnimeService.remove_episode(anime, episode)
        episode = AnimeService.get_episode(name, position, video)
        AnimeService.add_episode(anime, episode)

        result["data"] = anime.dict(True)
        return result
예제 #4
0
파일: anime.py 프로젝트: obasys/hikka
    def put(self):
        result = {"error": None, "data": []}
        choices = ("poster", "banner")

        parser = reqparse.RequestParser()
        parser.add_argument("file", type=FileStorage, location="files")
        parser.add_argument("type", type=str, choices=choices)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        anime = AnimeService.get_by_slug(args["slug"])
        if anime is None:
            return abort("anime", "not-found")

        if args["file"] is not None:
            helper = UploadHelper(request.account, args["file"], args["type"])
            data = helper.upload_image()

            if type(data) is Response:
                return data

            if anime[args["type"]] is not None:
                FileService.destroy(anime[args["type"]])

            anime[args["type"]] = data
            anime.save()

        result["data"] = anime.dict()
        return result
예제 #5
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("descriptors",
                            type=list,
                            default=[],
                            location="json")
        args = parser.parse_args()

        result["data"]["search"] = {}
        data = {}

        for service in args["descriptors"]:
            if service not in choices:
                return abort("general", "service-not-found")

            data[service] = []
            descriptors = DescriptorService.list(service)
            for descriptor in descriptors:
                data[service].append(descriptor.dict())

        result["data"]["search"]["descriptors"] = data
        result["data"]["search"]["years"] = AnimeService.years()

        return result
예제 #6
0
def selected_anime():
    result = {"error": None, "data": []}

    anime = AnimeService.selected()
    for item in anime:
        result["data"].append(item.dict())

    return result
예제 #7
0
def watch_anime(slug, position):
    result = {"error": None, "data": {}}

    anime = helpers.anime(slug)
    index = AnimeService.position_index(anime, position)
    if index is None:
        return abort("episode", "not-found")

    result["data"] = anime.episodes[index].dict(True)
    return result
예제 #8
0
def delete_episode():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("position", type=helpers.position, required=True)
    parser.argument("slug", type=helpers.anime, required=True)
    args = parser.parse()

    anime = args["slug"]
    helpers.is_member(request.account, anime.teams)

    index = AnimeService.position_index(anime, args["position"])
    if index is None:
        return abort("episode", "not-found")

    FileService.destroy(anime.episodes[index].video)
    FileService.destroy(anime.episodes[index].thumbnail)
    AnimeService.remove_episode(anime, anime.episodes[index])

    result["data"] = anime.dict(True)
    return result
예제 #9
0
def anime(slug):
    anime = AnimeService.get_by_slug(slug)
    valid = False

    if anime:
        if anime.hidden is True:
            if hasattr(request, "account"):
                valid = check.member(request.account, anime.teams)
                if check.permission(request.account, "global", "admin"):
                    valid = True

        else:
            valid = True

    if not valid:
        response = abort("anime", "not-found")
        flask_abort(response)

    return anime
예제 #10
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("subject",
                            type=str,
                            required=True,
                            choices=choices)
        parser.add_argument("text", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        subject = None
        if args["subject"] == "anime":
            subject = AnimeService.get_by_slug(args["slug"])

        comment = CommentService.create(subject, request.account, args["text"])
        result["data"] = comment.dict()

        return result
예제 #11
0
파일: votes.py 프로젝트: obasys/hikka
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("rating",
                            type=int,
                            required=True,
                            choices=range(1, 11))
        parser.add_argument("subject",
                            type=str,
                            required=True,
                            choices=choices)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        subject = None
        if args["subject"] == "anime":
            subject = AnimeService.get_by_slug(args["slug"])

        vote = VoteService.submit(subject, request.account, args["rating"])
        result["data"] = vote.dict()

        return result
예제 #12
0
def static_data():
    result = {"error": None, "data": {}}
    result["data"]["years"] = AnimeService.years()
    return result
예제 #13
0
파일: anime.py 프로젝트: obasys/hikka
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("franchises",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("subtitles",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("voiceover",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("aliases", type=list, default=[], location="json")
        parser.add_argument("genres", type=list, default=[], location="json")
        parser.add_argument("description", type=str, required=True)
        parser.add_argument("category", type=str, required=True)
        parser.add_argument("title", type=dict, required=True)
        parser.add_argument("team", type=str, required=True)
        parser.add_argument("year", type=int, required=True)
        parser.add_argument("state", type=str, default=None)
        args = parser.parse_args()

        title_parser = reqparse.RequestParser()
        title_parser.add_argument("jp",
                                  type=str,
                                  default=None,
                                  location=("title", ))
        title_parser.add_argument("ua", type=str, location=("title", ))
        title_args = title_parser.parse_args(req=args)

        for alias in args["aliases"]:
            if type(alias) is not str:
                return abort("general", "alias-invalid-type")

        team = TeamService.get_by_slug(args["team"])
        if team is None:
            return abort("team", "not-found")

        if request.account not in team.members:
            return abort("account", "not-team-member")

        if not PermissionService.check(request.account, "global",
                                       "publishing"):
            return abort("account", "permission")

        category = DescriptorService.get_by_slug("category", args["category"])
        if category is None:
            return abort("category", "not-found")

        state = DescriptorService.get_by_slug("state", args["state"])
        if state is None:
            return abort("state", "not-found")

        if args["description"] is None:
            return abort("general", "missing-field")

        genres = []
        for slug in args["genres"]:
            genre = DescriptorService.get_by_slug("genre", slug)
            if genre is not None:
                genres.append(genre)
            else:
                return abort("genre", "not-found")

        franchises = []
        for slug in args["franchises"]:
            franchise = DescriptorService.get_by_slug("franchise", slug)
            if franchise is not None:
                franchises.append(franchise)
            else:
                return abort("franchise", "not-found")

        subtitles = []
        for username in args["subtitles"]:
            subtitles_account = UserService.get_by_username(username)
            if subtitles_account is not None:
                subtitles.append(subtitles_account)

            else:
                return abort("account", "not-found")

        voiceover = []
        for username in args["voiceover"]:
            voiceover_account = UserService.get_by_username(username)
            if voiceover_account is not None:
                voiceover.append(voiceover_account)

            else:
                return abort("account", "not-found")

        title = AnimeService.get_title(title_args["ua"], title_args["jp"])
        search = utils.create_search(title_args["ua"], title_args["jp"],
                                     args["aliases"])
        slug = utils.create_slug(title_args["ua"])

        anime = AnimeService.create(title, slug, args["description"],
                                    args["year"], search, category, state,
                                    genres, franchises, [team], subtitles,
                                    voiceover, args["aliases"])

        result["data"] = anime.dict()
        return result
예제 #14
0
파일: anime.py 프로젝트: obasys/hikka
    def post(self):
        result = {"error": None, "data": []}

        parser = reqparse.RequestParser()
        parser.add_argument("franchises",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("categories",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("states", type=list, default=[], location="json")
        parser.add_argument("genres", type=list, default=[], location="json")
        parser.add_argument("teams", type=list, default=[], location="json")
        parser.add_argument("query", type=str, default="")
        parser.add_argument("page", type=int, default=0)
        parser.add_argument("year", type=dict)
        args = parser.parse_args()

        year_parser = reqparse.RequestParser()
        year_parser.add_argument("min",
                                 type=int,
                                 default=None,
                                 location=("year", ))
        year_parser.add_argument("max",
                                 type=int,
                                 default=None,
                                 location=("year", ))
        year_args = year_parser.parse_args(req=args)

        query = utils.search_query(args["query"])
        categories = []
        franchises = []
        genres = []
        states = []
        teams = []

        for slug in args["categories"]:
            category = DescriptorService.get_by_slug("category", slug)
            if category is not None:
                categories.append(category)
            else:
                return abort("category", "not-found")

        for slug in args["genres"]:
            genre = DescriptorService.get_by_slug("genre", slug)
            if genre is not None:
                genres.append(genre)
            else:
                return abort("genre", "not-found")

        for slug in args["franchises"]:
            franchise = DescriptorService.get_by_slug("franchise", slug)
            if franchise is not None:
                franchises.append(franchise)
            else:
                return abort("franchise", "not-found")

        for slug in args["states"]:
            state = DescriptorService.get_by_slug("state", slug)
            if state is not None:
                genres.append(state)
            else:
                return abort("state", "not-found")

        for slug in args["teams"]:
            team = TeamService.get_by_slug(slug)
            if team is not None:
                teams.append(team)
            else:
                return abort("team", "not-found")

        anime = AnimeService.search(query, year_args, categories, genres,
                                    franchises, states, teams, args["page"])

        for anime in anime:
            result["data"].append(anime.dict())

        return result
예제 #15
0
파일: anime.py 프로젝트: obasys/hikka
    def get(self, slug):
        anime = AnimeService.get_by_slug(slug)
        if anime is None:
            return abort("anime", "not-found")

        return anime.dict(True)
예제 #16
0
def new_anime():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("franchises", type=list, default=[], location="json")
    parser.argument("subtitles", type=list, default=[], location="json")
    parser.argument("voiceover", type=list, default=[], location="json")
    parser.argument("aliases", type=list, default=[], location="json")
    parser.argument("genres", type=list, default=[], location="json")
    parser.argument("category", type=helpers.category, required=True)
    parser.argument("description", type=helpers.string, required=True)
    parser.argument("state", type=helpers.state, required=True)
    parser.argument("team", type=helpers.team, required=True)
    parser.argument("season", type=int, choices=range(1, 5))
    parser.argument("title", type=dict, required=True)
    parser.argument("year", type=int, required=True)
    parser.argument("external", type=dict)
    parser.argument("total", type=int)
    args = parser.parse()

    title_parser = RequestParser()
    title_parser.argument("ua",
                          type=helpers.string,
                          location="title",
                          required=True)
    title_parser.argument("jp", type=helpers.string, location="title")
    title_args = title_parser.parse(req=args)

    external_parser = RequestParser()
    external_parser.argument("myanimelist", type=int, location="external")
    external_parser.argument("toloka", type=int, location="external")
    external_args = external_parser.parse(req=args)

    title = AnimeService.get_title(title_args["ua"], title_args["jp"])
    slug = utils.create_slug(title_args["ua"])
    team = args["team"]

    helpers.is_member(request.account, [team])

    anime = AnimeService.create(title, args["description"], args["category"],
                                args["state"], slug)

    for alias in args["aliases"]:
        if type(alias) is not str:
            return abort("general", "alias-invalid-type")

    anime.genres = []
    for slug in args["genres"]:
        genre = helpers.genre(slug)
        anime.genres.append(genre)

    anime.franchises = []
    for slug in args["franchises"]:
        franchise = helpers.franchise(slug)
        anime.franchises.append(franchise)

    fields = ["aliases", "year", "total"]
    for field in fields:
        anime[field] = args[field]

    fields = ["subtitles", "voiceover"]
    for field in fields:
        anime[field] = []
        for username in args[field]:
            account = helpers.account(username)
            anime[field].append(account)

    search = utils.create_search(anime.title.ua, anime.title.jp, anime.aliases)
    external = AnimeService.get_external(external_args["myanimelist"],
                                         external_args["toloka"])

    anime.external = external
    anime.search = search
    anime.teams = [team]

    if anime.external.myanimelist:
        anime.rating = utils.rating(anime.external.myanimelist)
        anime.save()

    result["data"] = anime.dict()
    anime.save()

    return result
예제 #17
0
def list_anime():
    result = {"error": None, "data": []}

    parser = RequestParser()
    parser.argument("franchises", type=list, default=[], location="json")
    parser.argument("categories", type=list, default=[], location="json")
    parser.argument("ordering", type=list, default=[], location="json")
    parser.argument("states", type=list, default=[], location="json")
    parser.argument("genres", type=list, default=[], location="json")
    parser.argument("teams", type=list, default=[], location="json")
    parser.argument("query", type=str, default="")
    parser.argument("page", type=int, default=0)
    parser.argument("year", type=dict)
    args = parser.parse()

    year_parser = RequestParser()
    year_parser.argument("min", type=int, location="year")
    year_parser.argument("max", type=int, location="year")
    year_args = year_parser.parse(req=args)

    query = utils.search_query(args["query"])
    categories = []
    franchises = []
    ordering = []
    genres = []
    states = []
    teams = []

    for slug in args["categories"]:
        category = helpers.category(slug)
        categories.append(category)

    for slug in args["genres"]:
        genre = helpers.genre(slug)
        genres.append(genre)

    for slug in args["franchises"]:
        franchise = helpers.franchise(slug)
        franchises.append(franchise)

    for slug in args["states"]:
        state = helpers.state(slug)
        states.append(state)

    for slug in args["teams"]:
        team = helpers.team(slug)
        teams.append(team)

    for item in args["ordering"]:
        check = item
        if item[0] in ["+", "-"]:
            check = item[1:]

        if check in ("rating"):
            ordering.append(check)

    anime = AnimeService.search(query,
                                year_args,
                                categories,
                                genres,
                                franchises,
                                states,
                                teams,
                                ordering,
                                False,
                                args["page"],
                                account=request.account)

    for item in anime:
        result["data"].append(item.dict())

    return result
예제 #18
0
from hikka.tools import helpers
from jikanpy import Jikan
from hikka import utils
import time

jikan = Jikan()
top = jikan.top(type="anime")

for index, item in enumerate(top["top"]):
    data = jikan.anime(item["mal_id"])
    myanimelist = data["mal_id"]

    if data["synopsis"] is None:
        data["synopsis"] = "Lorem ipsum dolor sit amet."

    title = AnimeService.get_title(data["title"])
    anime = AnimeService.create(title, data["synopsis"],
                                helpers.category(data["type"].lower()),
                                helpers.state("released"),
                                utils.create_slug(data["title"]))

    anime.search = utils.create_search(anime.title.ua, data["title_synonyms"])
    anime.external = AnimeService.get_external(myanimelist)
    anime.year = data["aired"]["prop"]["from"]["year"]
    anime.teams = [helpers.team("fanvox")]
    anime.aliases = data["title_synonyms"]
    anime.total = data["episodes"]
    anime.rating = data["score"]

    for genre_data in data["genres"]:
        genre_slug = genre_data["name"].lower().replace("-",
예제 #19
0
def file_upload():
    result = {"error": None, "data": {}}
    choices = ("account", "anime", "episode")

    parser = RequestParser()
    parser.argument("subject", type=str, choices=choices, required=True)
    parser.argument("type", type=helpers.string, required=True)
    parser.argument("file", type=FileStorage, location="files")
    parser.argument("uuid", type=helpers.uuid, required=True)
    parser.argument("offset", type=int, required=True)
    parser.argument("index", type=int, required=True)
    parser.argument("total", type=int, required=True)
    parser.argument("size", type=int, required=True)
    parser.argument("slug", type=helpers.string)
    parser.argument("position", type=int)
    args = parser.parse()

    upload_type = args["type"]
    uuid = args["uuid"]

    if args["subject"] == "account":
        if upload_type not in ("avatar"):
            return abort("file", "bad-upload-type")

        subject = request.account
        folder = subject.username

    if args["subject"] == "anime":
        if upload_type not in ("poster", "banner"):
            return abort("file", "bad-upload-type")

        subject = helpers.anime(args["slug"])
        folder = subject.slug

    if args["subject"] == "episode":
        if upload_type not in ("video", "thumbnail"):
            return abort("file", "bad-upload-type")

        subject = helpers.anime(args["slug"])
        index = AnimeService.position_index(subject, args["position"])
        if index is None:
            return abort("episode", "not-found")

        folder = subject.slug + "/" + str(args["position"])

    chunks = upload.ChunkHelper(request.account, folder, args["file"],
                                upload_type, uuid)
    chunks.load(args["size"], args["index"], args["total"], args["offset"])

    if args["index"] + 1 == args["total"]:
        helper = upload.UploadHelper(request.account, chunks.blob_file,
                                     upload_type)

        if args["subject"] in ("account", "anime"):
            file = helper.upload_image()
            FileService.destroy(subject[upload_type])
            subject[upload_type] = file

        if args["subject"] == "episode":
            if upload_type == "video":
                file = helper.upload_video()

            else:
                file = helper.upload_image()

            FileService.destroy(subject.episodes[index][upload_type])
            subject.episodes[index][upload_type] = file

        subject.save()
        result["data"] = subject.dict()
        chunks.clean(True)

    else:
        result["data"]["chunk"] = True

    return result