-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch errors while processing timestamp-links #6851
Catch errors while processing timestamp-links #6851
Conversation
Otherwise the complete app crashes, which is bad
Why is that method even called? This fixes the symtoms of parsing an unexpactedly structured URL. Shouldn't we take a closer look at the
This regex looks like it is accepting more than it should. |
Maybe we should use: (\\d{1,2}:)?(\\d{1,2})?:(\\d{1,2}) |
app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Stypox <stypox@pm.me>
Oh ok, then nevermind. Just keep the current one, but check that minutes and seconds are <= 60
|
Wait, but why isn't (?:^|(?!:)\W)(?:([0-5]?[0-9]):)?([0-5]?[0-9]):([0-5][0-9])(?=$|(?!:)\W) |
Using private final Linkify.TransformFilter timestampLink = new Linkify.TransformFilter() {
@Override
public String transformUrl(final Matcher match, final String url) {
final int timestampStart = match.start(2);
final int timestampEnd = match.end(3);
final String parsedTimestamp = commentText.substring(timestampStart, timestampEnd);
final String[] timestampParts = parsedTimestamp.split(":");
final int seconds;
if (timestampParts.length == 3) { // timestamp format: XX:XX:XX
seconds = Integer.parseInt(timestampParts[0]) * 3600 // hours
+ Integer.parseInt(timestampParts[1]) * 60 // minutes
+ Integer.parseInt(timestampParts[2]); // seconds
} else if (timestampParts.length == 2) { // timestamp format: XX:XX
seconds = Integer.parseInt(timestampParts[0]) * 60 // minutes
+ Integer.parseInt(timestampParts[1]); // seconds
} else {
return url;
}
return streamUrl + url.replace(match.group(0), "#timestamp=" + seconds);
}
}; |
I'm also currently writing some unit-tests and fun fact: So e.g. 1:23:45 becomes 1425s (23:45) when it should be 5025s Fixing it on the fly |
Also extracted overhead code into ``TimestampExtractor``
app/src/main/java/org/schabi/newpipe/util/external_communication/TimestampExtractor.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I like this implementation :-)
app/src/test/java/org/schabi/newpipe/util/external_communication/TimestampExtractorTest.java
Show resolved
Hide resolved
@litetex Remember to always add a PR to the draft release whenever you merge it. |
What is it?
Description of the changes in your PR
Catches errors while processing timestamp-links.
Fixes the following issue(s)
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.
Due diligence