- changed status to resolved
Anime "Duration" issue
Hello, wanna report another bug.
Some anime title causes a Notice: Undefined offset: 0 in \src\Atarashii\APIBundle\Parser\AnimeParser.php
Occurred when the anime duration is only hours. i.e; https://myanimelist.net/anime/30346/Doukyuusei_Movie (1 hr.) https://myanimelist.net/anime/18617/Girls_und_Panzer_der_Film (2 hr.)
Anime with duration in hr. min. (i.e. 2 hr. 10 min.) or min. (i.e. 45 min.) are not affected.
Thanks.
Note: i'm using develop branch & API 2.1
Comments (15)
-
-
-
reporter error occurred (undefined offset 0) on "Unknown" duration.
- https://myanimelist.net/anime/32801/Dungeon_ni_Deai_wo_Motomeru_no_wa_Machigatteiru_Darou_ka_OVA
- https://myanimelist.net/anime/31988/Hibike_Euphonium_2nd_Season
works properly;
- hr.
- hr. min.
- min.
-
reporter @ratan12 any update ?
-
I will take care of it soon.
-
reporter then, im trying to fix this issue myself.
# Duration: $extracted = $leftcolumn->filterXPath('//span[text()="Duration:"]'); if ($extracted->count() > 0) { $duration = trim(str_replace($extracted->text(), '', $extracted->parents()->text())); # match: # hr. # min if (strpos($duration, 'hr.') !== false && strpos($duration, 'min.') !== false) { preg_match('/(\d+) hr. (\d+) min/', $duration, $matches); $animerecord->setDuration((int) $matches[0] * 60 + $matches[2]); } # match: # hr. else if (strpos($duration, 'hr.') !== false) { preg_match('/(\d+) hr./', $duration, $matches); $animerecord->setDuration((int) $matches[0] * 60); } # match: # min else if (strpos($duration, 'min') !== false) { preg_match('/(\d+) min/', $duration, $matches); $animerecord->setDuration((int) $matches[0]); } # fallback (i.e. unknown) else { $animerecord->setDuration(0); } }
using !== false due strpos() has mixed return values and return false (boolean) if the needle was not found.
-
Your code does not match the codes in our repo. Did you modified it? In the code we do not have !==false.
-
reporter yes.
- 1st, i change the comparasion operator to not identical to prevent strpos() return value issue (0 treated as false, 1 as true)
- 2nd, adding strpos($duration, 'min') to match duration in min
- 3rd, adding fallback by using else and set the duration with 0 (zero, integer)
-
- changed status to open
Re-opening so we can make a better fix.
-
If we don't know the length, we shouldn't be returning a value. Returning 0 means that the length is 0, not "unknown" or something we couldn't parse.
I'm going to be committing a better fix that will handle hr, hr+min, and min situations.
-
reporter okay.
i'm using fallback for easier data handling.
also, please add sec. https://myanimelist.net/anime/29347/20-dai_no_Heya-hen = 15 sec.
-
Please add the seconds request as a new issue. The current API defines duration as an integer in minutes, so the API would need to be changed, which means an incompatible (breaking) change. For now, we won't return a value if the duration is under one minute.
You are welcome to modify the API for your needs. That's why the source is open. We won't normally accept a change where we return data when there isn't an existing value, however. The only exception is when we're already doing that because of legacy behavior.
-
reporter new issue created (marked as proposal).
-
- changed status to resolved
Fix Duration Parsing
Adjust the duration parser to handle all major styles including hour/minute, hour, and minute durations. Don’t break on “unknown” and unrecognized formats.
Fixes
#119→ <<cset c45ee61c1676>>
-
Fix Duration Parsing
Adjust the duration parser to handle all major styles including hour/minute, hour, and minute durations. Don’t break on “unknown” and unrecognized formats.
Fixes
#119→ <<cset 13aed2576400>>
- Log in to comment
Fix duration parsing issue because of boolean condition
Fixes
#119→ <<cset 98d4389b0daf>>