Beispiel #1
0

def cluster_kwargs(args, plugin):
    if args['pluginattrs']:
        attrs = split_pluginattrs(args['<pluginattrs>'])
        params = plugin.parameters()
        return {key: constructor(attrs[key]) for key, constructor in params.items()}
    return {}


if __name__ == '__main__':
    args = docopt(__doc__, version="Libhugin 'freki' clitool v0.1")
    MASK = attr_mapping()

    if args['create']:
        s = Session(args['<database>'], attr_mask=MASK)
        path = args['<datapath>']
        metadata = data_import(path)
        for nfofile in metadata:
            s.add(nfofile, attr_import_func)
        s.database_close()

    if args['export']:
        s = Session(args['<database>'], attr_mask=MASK)
        database = s.get_database()
        data_export(database.values())

    if args['list']:
        s = Session(args['<database>'], attr_mask=MASK)
        database = s.get_database()
        for num, movie in enumerate(database.values()):
Beispiel #2
0
#nfo read helper
def read_attrs(nfofile, mask):
    try:
        with open(nfofile, 'r') as f:
            #xml = xmltodict.parse(f.read())
            xml = json.loads(f.read())
            attributes = {key: None for key in mask.keys()}
            for key, filekey in mask.items():
                attributes[key] = xml[filekey]
            return attributes
    except Exception as e:
        print('Exception', e)


if __name__ == '__main__':
    s = Session('movie.db', attr_mask=MASK)
    path = sys.argv[1]
    c = Counter()
    for moviefolder in os.listdir(path):
        full_movie_path = os.path.join(path, moviefolder)
        nfofile = glob.glob1(full_movie_path, '*.nfo')
        if nfofile == []:
            nfofile = full_movie_path
            c['no_nfo'] += 1
        else:
            nfofile = os.path.join(full_movie_path, nfofile.pop())
        s.add(nfofile, read_attrs)

    for item in dict(s._database).values():
        if item.attributes and item.attributes.get('plot'):
            c[guess_language(item.attributes['plot'])] += 1