예제 #1
0
파일: bpexport.py 프로젝트: nano23823/bpm
def encode(emote, context):
    # Info: is_nsfw?, source, size, tags
    base = emote.base_variant()
    root = emote.source.variant_matches[emote]
    all_tags = root.all_tags(context) | emote.all_tags(context)

    for tag in list(all_tags):
        all_tags |= set(context.tag_config["TagAliases"].get(tag, []))

    is_nsfw = "+nsfw" in all_tags
    size = max(base.size) if hasattr(base, "size") else 0
    emitted_tags = [tag for tag in all_tags if tag not in context.tag_config["HiddenTags"]]

    info = {"source": emote.source.name, "tags": emitted_tags, "size": size}
    if is_nsfw:
        info["is_nsfw"] = is_nsfw
    if base.css:
        info["css"] = base.css
    if hasattr(base, "image_url"): # FIXME
        info["image_url"] = bplib.image_download_url(base.image_url)
        info["size"] = base.size
        info["offset"] = base.offset
    if emote.name != root.name: # Redirect
        info["primary"] = root.name
    return info
예제 #2
0
파일: objects.py 프로젝트: Ajedi32/bpm
 def to_css(self):
     download_url = bplib.image_download_url(self.image_url)
     css = {
         "float": "left",
         "background-image": "url(%s)" % (download_url),
         "width": "%spx" % (self.size[0]),
         "height": "%spx" % (self.size[1]),
         }
     if self.offset != (0, 0) or self.suffix:
         css["background-position"] = "%spx %spx" % (self.offset[0], self.offset[1])
     css.update(self.css)
     return css
예제 #3
0
파일: objects.py 프로젝트: nano23823/bpm
 def to_css(self):
     download_url = bplib.image_download_url(self.image_url)
     css = {
         "float": "left",
         "background-image": "url(%s)" % (download_url),
         "width": "%spx" % (self.size[0]),
         "height": "%spx" % (self.size[1]),
     }
     if self.offset != (0, 0) or self.suffix:
         css["background-position"] = "%spx %spx" % (self.offset[0],
                                                     self.offset[1])
     css.update(self.css)
     return css
예제 #4
0
def update_cache(images):
    for (i, url) in enumerate(images):
        gif_filename = image_path(url)
        if os.path.exists(gif_filename):
            continue

        download_url = bplib.image_download_url(url)
        print("[%s/%s] Original URL: %s" % (i + 1, len(images), url))
        print("[%s/%s] Download URL: %s" % (i + 1, len(images), download_url))
        print("[%s/%s] Target file: %s" % (i + 1, len(images), gif_filename))
        print()
        req = urllib.request.Request(download_url)
        with urllib.request.urlopen(req) as stream:
            data = stream.read()
        open(TempFilename, "wb").write(data)
        subprocess.call(["apng2gif", TempFilename, gif_filename])
        os.remove(TempFilename)
예제 #5
0
파일: dlanimotes.py 프로젝트: Ajedi32/bpm
def update_cache(images):
    for (i, url) in enumerate(images):
        gif_filename = image_path(url)
        if os.path.exists(gif_filename):
            continue

        download_url = bplib.image_download_url(url)
        print("[%s/%s] Original URL: %s" % (i + 1, len(images), url))
        print("[%s/%s] Download URL: %s" % (i + 1, len(images), download_url))
        print("[%s/%s] Target file: %s" % (i + 1, len(images), gif_filename))
        print()
        req = urllib.request.Request(download_url)
        with urllib.request.urlopen(req) as stream:
            data = stream.read()
        open(TempFilename, "wb").write(data)
        subprocess.call(["apng2gif", TempFilename, gif_filename])
        os.remove(TempFilename)