Skip to main content

A Pyhon parser for sff files.

Project description

sfflib

sfflib is an opensource, miltiplatform Scanlation File Format (sff) parser made for CanScanlate.

.sff files are basically xml files with some custom tags.

Below is the basic sff file:

<Document>
    <Metadata>
        <Script>Scanlation Script File v0.1.0</Script>
        <App></App>
        <Info>Made by NandeMD.</Info>
        <TLLength>0</TLLength>
        <PRLength>0</PRLength>
        <CMLength>0</CMLength>
        <BalloonCount>0</BalloonCount>
        <LineCount>0</LineCount>
    </Metadata>
    <Baloon type="Square" has_image="No">
        <text>
            şşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşş
        </text>
        <text>
            şşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşşş
        </text>
  </Baloon>
</Document>

Installing

Python 3.8 or higher is required!

# Linux/MacOS
python3 -m pip install -U libssf

# Windows
py -m pip install -U libsff

Example

from libsff import Document, Balloon, Out
from random import randint

# open a test image
with open("testimg.jpg", "rb") as file:
    imagefile = file.read()

# Create a blank document object
doc = Document.create_blank()

# Generate random 100 balloons
for _ in range(100):
    # Randomize imge
    has_image = randint(0, 1)

    # Add a Balloon object to our document
    docasd.add_balloon(
        Balloon(
            tl_content=[
                "Hi, this is tl line 1",
                "Hi, this is tl line 2"
            ],
            btype=randint(0, 4),
            has_img=has_image, # Yes, this is int
            balloon_img=imagefile if has_image else b"",
            img_type="jpg"
        )
    )

# Save as raw xml:
doc.save_sff("test", Out.RAW)

# Save as gzip compressed xml:
doc.save_sff("test", Out.GZIP)

# Save as lzma compressed xml:
doc.save_sff("test", Out.LZMA)

# Save as formatted text:
doc.save_sff("test", Out.TXT)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libsff-0.1.3.tar.gz (17.9 kB view hashes)

Uploaded Source

Built Distribution

libsff-0.1.3-py3-none-any.whl (18.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page