-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from mdaubie/master
Releasing v1.0.2
- Loading branch information
Showing
16 changed files
with
261 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/io/github/mdaubie/subtitlesparser/toolbox/ShiftSubtitles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.mdaubie.subtitlesparser.toolbox; | ||
|
||
import io.github.mdaubie.subtitlesparser.model.Subtitle; | ||
import io.github.mdaubie.subtitlesparser.model.SubtitlesFile; | ||
|
||
import java.security.InvalidParameterException; | ||
|
||
public class ShiftSubtitles { | ||
/** | ||
* Shifts the subtitle timestamps by a given offset | ||
* | ||
* @param sf The SubtitleFile object for which to shift the subtitles | ||
* @param millisOffset The offset, from which the subtitles are shifted, can be negative | ||
* @throws InvalidParameterException if the offset provided is negative and larger than the first timestamp (resulting in a negative timestamp) | ||
*/ | ||
static void shift(SubtitlesFile sf, long millisOffset) { | ||
long nanosOffset = millisOffset * 1000000; | ||
if (millisOffset < 0 && sf.getSubtitles().get(0).start.toNanoOfDay() + nanosOffset < 0) | ||
throw new InvalidParameterException("Too large negative offset provided"); | ||
for (int i = 0; i < sf.getSubtitles().size() - 1; i++) { | ||
Subtitle first = sf.getSubtitles().get(i); | ||
first.start = first.start.plusNanos(nanosOffset); | ||
first.end = first.end.plusNanos(nanosOffset); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.