p0ody / ff2ebook

WIP.
http://www.ff2ebook.com
18 stars 2 forks source link

[FFnet] Incorrect word-count #62

Closed StarWolf3000 closed 2 years ago

StarWolf3000 commented 2 years ago

One of your last commits broke the word-counter for stories from FFnet. A few days ago it still worked correctly, but now it seems to cut away after the thousand-separator comma for stories with more than 999 words. Example: I updated one of my followed stories and instead of 55,232 words, it only says 55 in the epub.

StarWolf3000 commented 2 years ago

The commit in question might be 500d4a2, with the intval() on $matches[1]:

private function popWordsCount(?string $source): ?int
{
    if (strlen($source) === 0)
        $this->errorHandler()->addNew(ErrorCode::ERROR_CRITICAL, "Couldn't get source.");

    if (Utils::regexOnSource("#- Words: (.+?) -#si", $source, $matches) === 1)
        return intval($matches[1]);
    else
    {
        $this->errorHandler()->addNew(ErrorCode::ERROR_WARNING, "Couldn't find words count.");
        return null;
    }
}
p0ody commented 2 years ago

You might be right, I can't touch it today, I'll check it tomorrow.

Thanks

On Sat., Apr. 23, 2022, 4:10 a.m. StarWolf3000, @.***> wrote:

The commit in question might be 500d4a2 https://github.com/p0ody/ff2ebook/commit/500d4a23d6143fded5f7e5fd279d8e2a02b2058d, with the intval() on $matches[1]:

private function popWordsCount(?string $source): ?int { if (strlen($source) === 0) $this->errorHandler()->addNew(ErrorCode::ERROR_CRITICAL, "Couldn't get source.");

if (Utils::regexOnSource("#- Words: (.+?) -#si", $source, $matches) === 1)
    return intval($matches[1]);
else
{
    $this->errorHandler()->addNew(ErrorCode::ERROR_WARNING, "Couldn't find words count.");
    return null;
}

}

— Reply to this email directly, view it on GitHub https://github.com/p0ody/ff2ebook/issues/62#issuecomment-1107425091, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEJWQB3UVCCSCYZ4Y6YT2DVGOWAHANCNFSM5UEG4HFQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

p0ody commented 2 years ago

Thanks @StarWolf3000 for the quick find.

Latest commit should fix it. Pushed it to live website.

StarWolf3000 commented 2 years ago

Thanks for fixing this, though it's still a bit weird now. I don't know why you declare the function's return value as an integer, because before this change, it would simply return the pre-formatted number from the website, with using the comma as thousand-separator. But now it simply returns the raw integer value without any number formatting, in my case it's 55232 instead of 55,232, which can be harder to read as number for very high numbers (≥1,000,000) in large stories.

I don't know how the other sites format their word count on the website (or API, if present, though in this case it's most likely a raw integer), but maybe you wanted to have it consistent for the epub generator across all sources.

€dit: For the output file, you can do a simple number_format($variable) to add the separators.

p0ody commented 2 years ago

From now on i'll use stricter types with php 8+, thats why I decided switching everything to int.

I added the number_format as you suggested.

It's now live on ff2ebook.com