Attempting to write CT script, need help

Post any problems / bugs / issues that are Mylar-related in here.
Post Reply
senorsmartypants
Posts: 86
Joined: Sun Sep 02, 2018 10:00 pm

Attempting to write CT script, need help

Post by senorsmartypants »

I'm trying to write a ComicTagger script that I can make Mylar use. But I'm running into a problem and think it maybe related to how mylar's CT is different from the standalone version.

I'm following some examples from the standalone CT that I found
http://comictagger.forumotion.com/t80-p-t-m-combination
https://github.com/davide-romanini/comi ... op/scripts

Here's my code based on some of the above.

Code: Select all

#!/usr/bin/python
from comictaggerlib.settings import *
from comictaggerlib.comicarchive import *


def main():

    utils.fix_output_encoding()
    settings = ComicTaggerSettings()

    if len(sys.argv) < 3:
        print >> sys.stderr, "Usage: {0} [comicfile]".format(
            sys.argv[0])
        return

    filename = sys.argv[1]

    if not os.path.exists(filename):
        print >> sys.stderr, filename + ": not found!"
        return

    ca = ComicArchive(filename, settings)
    if not ca.seemsToBeAComicArchive():
        print >> sys.stderr, "Sorry, but " + \
            filename + " is not a comic archive!"
        return

    if ca.hasMetadata( style ):
        md = ca.readMetadata( style )
        print "{0} #{1} ({2})".format(md.series, md.issue, md.year)


if __name__ == '__main__':
    main()
But I get an error on ComicArchive creation

Code: Select all

Script raised an unhandled exception:  coercing to Unicode: need string or buffer, NoneType found
Traceback (most recent call last):
  File "/app/mylar/lib/comictaggerlib/options.py", line 233, in launch_script
    script.main()
  File "/comics/ComicTagger-AlternateSeries/alternate-series.py", line 22, in main
    ca = ComicArchive(filename, settings)
  File "/app/mylar/lib/comictaggerlib/comicapi/comicarchive.py", line 648, in __init__
    with open(fname, 'rb') as fd:
TypeError: coercing to Unicode: need string or buffer, NoneType found
Any help would be appreciated.
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: Attempting to write CT script, need help

Post by evilhero »

No idea to be honest - I tend not to delve into the CT code if I can avoid it due to it's a PITA.

However, you're calling sys.argv[1] without importing the sys library, nor actually passing the sys.argv[1] variable from the __main__ into the main function:

Code: Select all

...
import sys

def main(filename)
...

if __name__ == '__main__':
    if len(sys.argv) < 3:
        sys.exit(sys.stderr, "Usage: {0} [comicfile]".format(sys.argv[0]))
    else:
        main(sys.argv[1])
senorsmartypants
Posts: 86
Joined: Sun Sep 02, 2018 10:00 pm

Re: Attempting to write CT script, need help

Post by senorsmartypants »

I'm calling the script using the following format.

comictagger.py -S scriptname args

filename is passed in fine. And the check for the file existing passes.


I think the problem is with this code in comictaggerlib/comicapi/comicarchive.py. My guess is that self.default_image_path is null

Code: Select all

        if ComicArchive.logo_data is None:
            #fname = ComicTaggerSettings.getGraphic('nocover.png')
            fname = self.default_image_path
            with open(fname, 'rb') as fd:
                ComicArchive.logo_data = fd.read()
I was using mylar to display all the settings in the web ui yesterday, but now I can't find how I was doing that.
senorsmartypants
Posts: 86
Joined: Sun Sep 02, 2018 10:00 pm

Re: Attempting to write CT script, need help

Post by senorsmartypants »

The problem was indeed the image path being empty. IDK why there needs to be a logo to read a comic archive, but ok.

I changed my code to initialize the ComicArchive with a path to an image.

Code: Select all

ca = ComicArchive(filename, settings, "comictaggerlib/graphics/nocover.png")
And now things work.
senorsmartypants
Posts: 86
Joined: Sun Sep 02, 2018 10:00 pm

Re: Attempting to write CT script, need help

Post by senorsmartypants »

So here's my work in progress.

https://github.com/SenorSmartyPants/Com ... nateSeries

It will figure out alternate series numbers from the title if there is one to be found.

I've got it doing what I want, but it's not actually updating the CBZ archive. It seems like it should be and I'm not sure why it isn't.

If there are any CT experts (or more expert than I am, which isn't saying much) out there, please take a look and let me know what you think.
senorsmartypants
Posts: 86
Joined: Sun Sep 02, 2018 10:00 pm

Re: Attempting to write CT script, need help

Post by senorsmartypants »

I got my script figured out. Even have mylar calling it automatically now.

Here's the discussion for the new working script.

viewtopic.php?f=12&t=2124
Post Reply