mateusz-bak / openreads

A mobile books tracker written in Flutter that respects your privacy.
GNU General Public License v2.0
918 stars 57 forks source link

[FEATURE_REQUEST] Import books from StoryGraph csv #525

Open AmbivalentMonkey opened 7 months ago

AmbivalentMonkey commented 7 months ago

Is your feature request related to a problem? Please describe. As with Issue 57, it would be helpful to make migration from other platforms quicker and easier, in this case from StoryGraph.

Describe the solution you'd like

Describe alternatives you've considered n/a

Additional context Essentially just a new type of import similar to PR 97.

The column headers from the CSV are:

Title | Authors | Contributors | ISBN/UID | Format | Read Status | Date Added | Last Date Read | Dates Read | Read Count | Moods | Pace | Character- or Plot-Driven? | Strong Character Development? | Loveable Characters? | Diverse Characters? | Flawed Characters? | Star Rating | Review | Content Warnings | Content Warning Description | Tags | Owned?

I think the relevant mapping would be:

// assuming input is row: Map<String, String>

var isbn10 = Constants.DATABASE_EMPTY_VALUE;
var isbn13 = Constants.DATABASE_EMPTY_VALUE;
if (row["ISBN/UID"]?.length == 10) {
    isbn10 = row["ISBN/UID"];
} else if (row["ISBN/UID"]?.length == 13) {
    isbn13 = row["ISBN/UID"];
}

Book(
    bookTitle = row["Title"],
    bookAuthor = row["Authors"], // hopefully no additional parsing for multiple authors e.g. 'Michael Foreman, Michael Morpurgo'
    bookRating = row["Star Rating"] ?: 0F, // probably needs normalising - StoryGraph goes from 0.0-5.0
    bookStatus = row["ReadStatus"],
    bookPriority = Constants.DATABASE_EMPTY_VALUE,
    bookStartDate = row["DatesRead"].split("-")[0], // probably breaks if there are multiple reads
    bookFinishDate = row["DatesRead"].split("-")[1], // as above
    bookNumberOfPages = 0,
    bookTitle_ASCII = row["Title"].unaccented().replace("ł", "l", false),
    bookAuthor_ASCII = row["Authors"].unaccented().replace("ł", "l", false),
    bookIsDeleted = false,
    bookCoverUrl = Constants.DATABASE_EMPTY_VALUE,
    bookOLID = Constants.DATABASE_EMPTY_VALUE,
    bookISBN10 = isbn10,
    bookISBN13 = isbn13,
    bookPublishYear = 0,
    bookIsFav = false,
    bookCoverImg = null,
    bookNotes = row["Review"] ?: Constants.DATABASE_EMPTY_VALUE,
    bookTags = row["Tags"], // likely needs parsing first
)

I've never touched a .kt file so hopefully this syntax is okay.

mateusz-bak commented 7 months ago

I think we could implement this. Do you have example values of the columns? Or maybe you spotted some documentation?

AmbivalentMonkey commented 7 months ago

Awesome, thank you!

I've not had any luck finding documentation, but I've downloaded and picked out some representative rows of my own data which are in this csv: StoryGraph-reduced.csv

mateusz-bak commented 7 months ago

Great, I'll take a look whenever I find a chance