View Single Post
Old 10-11-2020, 11:17 AM   #10
geek1011
Wizard
geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.
 
Posts: 2,805
Karma: 7423683
Join Date: May 2016
Location: Ontario, Canada
Device: Kobo Mini, Aura Edition 2 v1, Clara HD
If you have multiple EPUB3-style series entries in the OPF, it should be trivial to modify my NickelSeries mod to put the second one in the subtitle.

Here are the relevant parts:
Spoiler:
NickelSeries@a06f1ac/metadata.h:13-25
Code:
    // series is a map of the element ID to its series name and index. The
    // series index is returned as-is and may not be a number, but both the name
    // and index will not be empty.
    //
    // Sources:
    // - Calibre: meta[name="calibre:series"][content]          source =  ns_metadata_t::calibre
    //                                                          series =  [content]
    //            meta[name="calibre:series_index"][content]    index  =  [content]
    // - EPUB3:   meta[property="belongs-to-collection"][id]    source =  [id]
    //                                                          series =  text
    //            meta[property="group-position"][refines=#id]  index  =  text
    //            meta[property="collection-type"][refines=#id] text   == "series"  || none
    QMap<QString, QPair<QString, QString>> series;
NickelSeries@a06f1ac/nickelseries.cc:60-127
Code:
static void ns_update_series(Volume *v, QString const& filename) {
    nh_log("hook: updating metadata for '%s'", qPrintable(filename));


    NSMetadata meta(filename);
    if (!meta.error().isNull()) {
        nh_log("... error: '%s', ignoring", qPrintable(meta.error()));
        return;
    }


    if (!meta.series.isEmpty()) {
        QString series;
        QString index;


        for (QString id : meta.series.keys()) {
            series = meta.series[id].first;
            index  = meta.series[id].second;
            nh_log("... found metadata: id='%s' series='%s' index='%s'", qPrintable(id), qPrintable(series), qPrintable(index));
        }


        if (meta.series.contains(NSMetadata::calibre)) {
            series = meta.series[NSMetadata::calibre].first;
            index = meta.series[NSMetadata::calibre].second;
        }


        nh_log("... using ('%s', %s)", qPrintable(series), qPrintable(index));


        bool ok;
        double d = QVariant(index).toDouble(&ok);
        if (ok) {
            nh_log("... simplified series index '%s' to '%s'", qPrintable(index), qPrintable(QString::number(d)));
            index = d
                ? QString::number(d)
                : QString();
        }


        nh_log("... Volume::setSeriesName('%s')", qPrintable(series));
        Volume__setSeriesName(v, series);


        nh_log("... Volume::setSeriesNumber('%s')", qPrintable(index));
        Volume__setSeriesNumber(v, index);


        if (Volume__setSeriesNumberFloat) {
            nh_log("... Volume::setSeriesNumberFloat('%s')", qPrintable(index));
            Volume__setSeriesNumberFloat(v, index);
        }


        if (Volume__setSeriesId) {
            nh_log("... Volume::setSeriesId('%s')", qPrintable(series));
            Volume__setSeriesId(v, series); // matches the Calibre Kobo plugin's behaviour for compatibility
        }
    }


    if (!meta.subtitle.isEmpty()) {
        QString subtitle;
        for (QString id : meta.subtitle.keys()) {
            subtitle = meta.subtitle[id];
            nh_log("... found metadata: id='%s' subtitle='%s'", qPrintable(id), qPrintable(subtitle));
        }


        if (meta.subtitle.contains(NSMetadata::calibre))
            subtitle = meta.subtitle[NSMetadata::calibre];


        nh_log("... using '%s'", qPrintable(subtitle));


        nh_log("... Volume::setSubtitle('%s')", qPrintable(subtitle));
        Volume__setSubtitle(v, subtitle);
    }
}

Last edited by geek1011; 10-11-2020 at 11:20 AM.
geek1011 is offline   Reply With Quote