Exemplo n.º 1
0
def encode(s):
    return base64.b64encode(bxor(s.encode("u8"), key2))
Exemplo n.º 2
0
def get_videos_for_episode(anime_id,
                           episode,
                           video_id=None,
                           decode_urls="encode",
                           sort_by_kinds=True,
                           filter_by_kwargs={}):
    anime_videos = sort_videos_by_hostings(
        AnimeVideo.query.filter_by(anime_id=anime_id,
                                   episode=episode).order_by(
                                       AnimeVideo.kind).all(), hostings_order)
    if sort_by_kinds:
        res = OrderedDict()
        for k in video_kinds.values():
            res[k] = []
    else:
        res = []

    if len(anime_videos) < 1:
        if sort_by_kinds:
            res["active_kind"] = "fansub"
            res["active_video"] = {"episode": 0}
        return res

    #print(video_id)
    try:
        video_id = int(video_id)
    except:
        video_id = None

    if not video_id in [a.id for a in anime_videos]:
        video_id = anime_videos[0].id

    keys = [
        "url", "video_hosting", "author", "uploader", "language", "id",
        "anime_id", "active", "episode"
    ]
    if (not sort_by_kinds):
        keys.append("kind")

    active_video = None

    video_ids = []

    for n, v in enumerate(anime_videos):
        if decode_urls == "decode":
            v.url = bxor(v.url, KEY)
        elif decode_urls == "encode":
            v.url = base64.b64encode(bxor(v.url.encode("u8"),
                                          KEY)).decode("u8")

        v.video_hosting = urllib.parse.urlparse(v.url).netloc
        if (video_id is None) and n == 0:
            v.active = " active"
        else:
            v.active = " active" if (video_id == v.id) else ""

        #print("(%s == %s) is %d" % (video_id, v.id, video_id == v.id))

        if v.active:
            active_video = v

        if not v.language:
            v.language = "unknown"

        skip = False
        for key, val in filter_by_kwargs.items():
            if getattr(v, key) != val:
                skip = True
                break

        if skip:
            continue

        video_dict = {key: getattr(v, key) for key in keys}
        video_ids.append(v.id)

        if (sort_by_kinds):
            res[video_kinds[v.kind]].append(video_dict)
        else:
            res.append(video_dict)

    if (sort_by_kinds):
        res["ids"] = video_ids

        #print(res, active_video)
        if active_video is not None:
            res["active_kind"] = video_kinds[active_video.kind]
            res["active_video"] = serialize(active_video)
        else:
            res["active_kind"] = "fansub"
            res["active_video"] = {"episode": 0}

    return res
Exemplo n.º 3
0
#!/usr/bin/env python3

import sys

from shikimori import app
from shikimori import models
import xor


def usage():
    print("usage: encode_db_urls.py <key>")
    sys.exit()


if len(sys.argv) != 2:
    usage()

KEY = open(sys.argv[1], "rb").read()

videos = models.AnimeVideo.query.all()
for v in videos:
    v.url = xor.bxor(v.url.encode("u8"), KEY)

app.db.session.commit()