Python script for converting Papagayo files to lst files.

Hi. I cobbled together a quick script to help automatically import/convert .dat files for use in Synfig. The code is fairly crude, but it seems to work. I have mine set up to import png files by default.

Basically, I take all the dat files and drop them into their own directory where I place the script. It first makes the changes to the files and then changes them to lst files. The changes are permanent, so you want to make sure you only run the script in the directory where you have the files stored. Anyway, here is the script (which I called datalst.py):

import os
import sys
import fileinput
import glob
for line in fileinput.input(glob.glob(’*.dat’), inplace=True):
sys.stdout.write(line.replace(‘MohoSwitch1’, ‘MohoSwitch1’ ‘\n’ ‘FPS 24’ ‘\n’ ‘png’))
for filename in os.listdir(os.path.dirname(os.path.abspath(file))):
base_file, ext = os.path.splitext(filename)
if ext == “.dat”:
os.rename(filename, base_file + “.lst”)

I am sure more experienced programmers could come up with a better method, but this is what I came up with. Feel free to use or modify it.

Update: The forum formatting seems a bit off, so here is a jpg file that shows the formatting.
datalst.jpg

Hello and welcome here,

thank’s for sharing that … but where come from the .dat file ?

also, to kepp the formatting, you can share your script by attaching the .py file to the forum.

I used Papagayo to create lipsync files. However, I found the process of manually converting each exported .dat file to a Synfig useable format time consuming. Looking at suggestions from threads on stackoverflow, I eventually cobbled together a small python script to automate the process.

Basically, if you use Papagayo and save the file, it saves it in pgo format. Papagayo people just export the file for use in other programs as a .dat file using the export button in Papagayo. The export format is .dat and Synfig needs to have the lines indicating the FPS and format (i.e. png) inserted and saved as an lst file.

Background on the Synfig list importer is at

wiki.synfig.org/wiki/Doc:ListImporter

Tom Head already did a tutorial on using Papagayo and Synfig that is on youtube.

I set the python script up for the most common scenario, FPS 24 with png files, but obviously, people could edit datalst.py with a text editor like jedit as they wanted for other formats or configurations.

First six lines of script make the changes to the file to make it useable in Synfig with FPS 24 and png files. The last four lines convert all the files in the directory from .dat to .lst files.

The major caveat is that the changes are permanent and that it coverts ALL .dat files in the directory you run the program in. So don’t run it in a directory with .dat files you don’t want converted to .lst files.

I just create a separate directory for datalst.py and copy my exported .dat files to it, then run the program. i’m using python3 on Linux Mint.

From my terminal in the directory where I have datalst and the .dat files I want to convert I just execute the program: python3 datalst.py

All files with the .dat extension are converted with the changes to make them ready for importing into Synfig.

I can’t attach datalst.py, but I cant attach datalst.txt and you can rename it datalst.py
datalst.txt (384 Bytes)

a verbose explanation…
(topic moved)