Skip to content
Permalink
Browse files
seriesmeta: Added support for updating SeriesID (fixes #48)
A SeriesID is required for the new series view in 4.20.14601.

This implementation is compatible with @davidfor's one for the
Calibre driver. When there is a book from the Kobo store with an
identical series name which has a series ID, that series ID is
used. Otherwise, the series ID is just the series name.

The only place where this differs from @davidfor's one is that it
doesn't care about if the author is identical. My reasoning for
this was the amount of incorrect/inconsistent (e.g. do you put a
space between multiple initials?) author information I've seen in
books, the fact that some series are written by more than one
author, and the fact that nickel handles multiple authors in a
series fine (it just merges the list of authors when it displays
the series).
  • Loading branch information
pgaskin committed Mar 3, 2020
1 parent cd2ae60 commit cd976a04a1b96603afe38eabb5e1302555ce55f1
Showing with 12 additions and 4 deletions.
  1. +12 −4 seriesmeta/seriesmeta.go
@@ -172,7 +172,9 @@ func (k *Kobo) SeriesConfig(noReplace, noPersist, uninstall bool) error {
UPDATE content
SET
Series = (SELECT Series FROM _seriesmeta WHERE ImageId = new.ImageId),
SeriesNumber = (SELECT SeriesNumber FROM _seriesmeta WHERE ImageId = new.ImageId)
SeriesNumber = (SELECT SeriesNumber FROM _seriesmeta WHERE ImageId = new.ImageId),
/* Get the SeriesID from books from the Kobo Store (WorkId NOT NULL) where the series name matches, otherwise just use the series name as the SeriesID (https://www.mobileread.com/forums/showthread.php?p=3959768) */
SeriesID = coalesce((SELECT SeriesID FROM content WHERE Series = (SELECT Series FROM _seriesmeta WHERE ImageId = new.ImageId) AND WorkId NOT NULL AND SeriesID NOT NULL AND WorkId != "" AND SeriesID != "" LIMIT 1), (SELECT Series FROM _seriesmeta WHERE ImageId = new.ImageId))
WHERE ImageId = new.ImageId;
{{if .NoPersist}}DELETE FROM _seriesmeta WHERE ImageId = new.ImageId;{{end}}
END;
@@ -189,7 +191,9 @@ func (k *Kobo) SeriesConfig(noReplace, noPersist, uninstall bool) error {
UPDATE content
SET
Series = (SELECT Series FROM _seriesmeta WHERE ImageId = new.ImageId),
SeriesNumber = (SELECT SeriesNumber FROM _seriesmeta WHERE ImageId = new.ImageId)
SeriesNumber = (SELECT SeriesNumber FROM _seriesmeta WHERE ImageId = new.ImageId),
/* Get the SeriesID from books from the Kobo Store (WorkId NOT NULL) where the series name matches, otherwise just use the series name as the SeriesID (https://www.mobileread.com/forums/showthread.php?p=3959768) */
SeriesID = coalesce((SELECT SeriesID FROM content WHERE Series = (SELECT Series FROM _seriesmeta WHERE ImageId = new.ImageId) AND WorkId NOT NULL AND SeriesID NOT NULL AND WorkId != "" AND SeriesID != "" LIMIT 1), (SELECT Series FROM _seriesmeta WHERE ImageId = new.ImageId))
WHERE ImageId = new.ImageId;
{{if .NoPersist}}DELETE FROM _seriesmeta WHERE ImageId = new.ImageId;{{end}}
END;
@@ -216,7 +220,9 @@ func (k *Kobo) SeriesConfig(noReplace, noPersist, uninstall bool) error {
UPDATE content
SET
Series = new.Series,
SeriesNumber = new.SeriesNumber
SeriesNumber = new.SeriesNumber,
/* Get the SeriesID from books from the Kobo Store (WorkId NOT NULL) where the series name matches, otherwise just use the series name as the SeriesID (https://www.mobileread.com/forums/showthread.php?p=3959768) */
SeriesID = coalesce((SELECT SeriesID FROM content WHERE Series = new.Series AND WorkId NOT NULL AND SeriesID NOT NULL AND WorkId != "" AND SeriesID != "" LIMIT 1), new.Series)
WHERE ImageId = new.ImageId;
{{if .NoPersist}}DELETE FROM _seriesmeta WHERE ImageId = new.ImageId;{{end}}
END;
@@ -232,7 +238,9 @@ func (k *Kobo) SeriesConfig(noReplace, noPersist, uninstall bool) error {
UPDATE content
SET
Series = new.Series,
SeriesNumber = new.SeriesNumber
SeriesNumber = new.SeriesNumber,
/* Get the SeriesID from books from the Kobo Store (WorkId NOT NULL) where the series name matches, otherwise just use the series name as the SeriesID (https://www.mobileread.com/forums/showthread.php?p=3959768) */
SeriesID = coalesce((SELECT SeriesID FROM content WHERE Series = new.Series AND WorkId NOT NULL AND SeriesID NOT NULL AND WorkId != "" AND SeriesID != "" LIMIT 1), new.Series)
WHERE ImageId = new.ImageId;
{{if .NoPersist}}DELETE FROM _seriesmeta WHERE ImageId = new.ImageId;{{end}}
END;

1 comment on commit cd976a0

@pgaskin

This comment has been minimized.

Copy link
Owner Author

@pgaskin pgaskin commented on cd976a0 Mar 3, 2020

This has now been implemented in kovidgoyal/calibre@477d9ef.

Please sign in to comment.