-
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.
Showing
60 changed files
with
2,172 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test/** linguist-vendored | ||
|
||
build_dita2audiobook.xml linguist-language=Ant-Build-System |
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,45 @@ | ||
name: CI | ||
'on': | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
jobs: | ||
sonarcloud: | ||
name: SonarCloud Scan | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
- name: Use Java 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'zulu' | ||
- name: SonarCloud Scan | ||
uses: jason-fox/sonarcloud-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_CLOUD_LOGIN: ${{ secrets.SONAR_CLOUD_LOGIN }} | ||
|
||
unit-test: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
- name: Run DITA-OT Unit Test | ||
uses: jason-fox/dita-unit-test-action@master | ||
with: | ||
dita-ot-version: '4.0' | ||
plugin: 'fox.jason.audiobook' | ||
setup-script: 'test/setup.sh' | ||
env: | ||
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: test-results | ||
path: test-results.html |
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,33 @@ | ||
**/out/** | ||
**/temp/** | ||
**/tmp/** | ||
|
||
target/ | ||
classes/ | ||
lib/ant-*.jar | ||
lib/ant-launcher-*.jar | ||
.scannerwork/ | ||
|
||
*~ | ||
.fuse_hidden* | ||
.directory | ||
.Trash-* | ||
.nfs* | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
Icon | ||
._* | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
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,99 @@ | ||
/* | ||
* This file is part of the DITA-OT Audio Plug-in project. | ||
* See the accompanying LICENSE file for applicable licenses. | ||
*/ | ||
|
||
package fox.jason.audiobook.tasks; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import org.apache.tools.ant.BuildException; | ||
import org.apache.tools.ant.Task; | ||
import org.apache.tools.ant.taskdefs.Copy; | ||
import org.apache.tools.ant.util.FileUtils; | ||
|
||
// | ||
// Copy existing file to avoid running a real text-speech service | ||
// | ||
|
||
public class CopyFromCacheTask extends Task { | ||
/** | ||
* Field md5. | ||
*/ | ||
private String md5; | ||
/** | ||
* Field out. | ||
*/ | ||
private String out; | ||
|
||
/** | ||
* Creates a new <code>CopyFromCacheTask</code> instance. | ||
*/ | ||
public CopyFromCacheTask() { | ||
super(); | ||
this.md5 = null; | ||
this.out = null; | ||
} | ||
|
||
/** | ||
* Method setMd5. | ||
* | ||
* @param md5 String | ||
*/ | ||
public void setMd5(String md5) { | ||
this.md5 = md5; | ||
} | ||
|
||
/** | ||
* Method setOut. | ||
* | ||
* @param out String | ||
*/ | ||
public void setOut(String out) { | ||
this.out = out; | ||
} | ||
|
||
/** | ||
* Method execute. | ||
* | ||
* @throws BuildException if something goes wrong | ||
*/ | ||
@Override | ||
public void execute() { | ||
// @param md5 - The location of the files to process | ||
// @param out - The location of the files to process | ||
if (this.md5 == null) { | ||
throw new BuildException("You must supply an md5 hash"); | ||
} | ||
if (this.out == null) { | ||
throw new BuildException("You must supply a destination directory"); | ||
} | ||
|
||
try { | ||
String cachefile = getProject().getProperty("mp3.cachefile"); | ||
String fileslist = FileUtils.readFully(new java.io.FileReader(cachefile)); | ||
|
||
for (String line : fileslist.split("\n")) { | ||
line = line.trim(); | ||
if (line.endsWith(md5)) { | ||
String[] parts = line.split("."); | ||
String file = | ||
cachefile.substring(0, cachefile.lastIndexOf('/')) + | ||
"/" + | ||
String.join(".", Arrays.copyOf(parts, parts.length - 1)) + | ||
".mp3"; | ||
|
||
Copy task = (Copy) getProject().createTask("copy"); | ||
task.setTaskName("mp3-cache-copy"); | ||
task.setFile(new java.io.File(file)); | ||
task.setTofile(new java.io.File(out)); | ||
task.setOverwrite(true); | ||
task.perform(); | ||
break; | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new BuildException(e); | ||
} | ||
} | ||
} |
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,84 @@ | ||
/* | ||
* This file is part of the DITA-OT Audio Plug-in project(. | ||
* See the accompanying LICENSE file for applicable licenses. | ||
*/ | ||
|
||
package fox.jason.audiobook.tasks; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import org.apache.tools.ant.BuildException; | ||
import org.apache.tools.ant.Task; | ||
import org.apache.tools.ant.taskdefs.Echo; | ||
|
||
// Function to create a Chapter entry | ||
|
||
public class CreateChapterEntryTask extends Task { | ||
private static final String DURATION = "audiobook.duration"; | ||
private static final String CHAPTER_FILE = "chapter.temp.file"; | ||
private static final String METADATA = "ffmpeg.meta.out"; | ||
|
||
/** | ||
* Creates a new <code>CreateChapterEntryTask</code> instance. | ||
*/ | ||
public CreateChapterEntryTask() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Method execute. | ||
* | ||
* @throws BuildException if something goes wrong | ||
*/ | ||
@Override | ||
public void execute() { | ||
String chapter = getProject().getProperty(CHAPTER_FILE); | ||
String[] inputs = getProject().getProperty(METADATA).split("\n"); | ||
long oldDuration = getProject().getProperty(DURATION) == null | ||
? 0 | ||
: Long.parseLong(getProject().getProperty(DURATION)); | ||
|
||
String timeString = null; | ||
String titleString = null; | ||
|
||
for (String input : inputs) { | ||
String line = input.trim(); | ||
int start = line.indexOf(':'); | ||
if (line.startsWith("Duration")) { | ||
timeString = line.substring(start + 2, start + 13); | ||
} else if (line.startsWith("title")) { | ||
titleString = line.substring(start + 2); | ||
} | ||
} | ||
|
||
SimpleDateFormat iso8601DateFormat = new SimpleDateFormat( | ||
"yyyy-MM-dd'T'HH:mm:ssZ" | ||
); | ||
|
||
try { | ||
Date datetime = iso8601DateFormat.parse("1970-01-01T" + timeString + "Z"); | ||
long duration = datetime.getTime(); | ||
|
||
String output = | ||
"\n[CHAPTER]\nTIMEBASE=1/1000\nSTART=" + | ||
oldDuration + | ||
"\nEND=" + | ||
(oldDuration + duration) + | ||
"\ntitle=" + | ||
titleString + | ||
"\n#chapter duration " + | ||
timeString; | ||
|
||
Echo task = (Echo) getProject().createTask("echo"); | ||
task.setFile(new java.io.File(chapter)); | ||
task.setMessage(output); | ||
task.setAppend(true); | ||
task.perform(); | ||
|
||
getProject() | ||
.setProperty(DURATION, String.valueOf(oldDuration + duration)); | ||
} catch (Exception e) { | ||
throw new BuildException(e); | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
src/fox/jason/audiobook/tasks/IterateTracklistTask.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,126 @@ | ||
/* | ||
* This file is part of the DITA-OT Audio Plug-in project. | ||
* See the accompanying LICENSE file for applicable licenses. | ||
*/ | ||
|
||
package fox.jason.audiobook.tasks; | ||
|
||
import java.io.IOException; | ||
import org.apache.tools.ant.BuildException; | ||
import org.apache.tools.ant.Task; | ||
import org.apache.tools.ant.taskdefs.MacroInstance; | ||
import org.apache.tools.ant.util.FileUtils; | ||
|
||
// | ||
// Iterator function to run a given macro against a set of files | ||
// | ||
|
||
public class IterateTracklistTask extends Task { | ||
/** | ||
* Field macro. | ||
*/ | ||
private String macro; | ||
/** | ||
* Field dir. | ||
*/ | ||
private String file; | ||
|
||
/** | ||
* Field dir. | ||
*/ | ||
private String dir; | ||
|
||
/** | ||
* Creates a new <code>IterateTracklistTask</code> instance. | ||
*/ | ||
public IterateTracklistTask() { | ||
super(); | ||
this.dir = null; | ||
this.file = null; | ||
this.macro = null; | ||
} | ||
|
||
/** | ||
* Method setDir. | ||
* | ||
* @param dir String | ||
*/ | ||
public void setDir(String dir) { | ||
this.dir = dir; | ||
} | ||
|
||
/** | ||
* Method setFile. | ||
* | ||
* @param file String | ||
*/ | ||
public void setFile(String file) { | ||
this.file = file; | ||
} | ||
|
||
/** | ||
* Method setMacro. | ||
* | ||
* @param macro String | ||
*/ | ||
public void setMacro(String macro) { | ||
this.macro = macro; | ||
} | ||
|
||
/** | ||
* Method execute. | ||
* | ||
* @throws BuildException if something goes wrong | ||
*/ | ||
@Override | ||
public void execute() { | ||
// @param file - A file holding the location of the mp3 files | ||
// @param dir - The location of the files to process | ||
// @param macro - A macro to run. | ||
if (this.dir == null) { | ||
throw new BuildException( | ||
"You must supply the location of the files to process" | ||
); | ||
} | ||
if (this.file == null) { | ||
throw new BuildException( | ||
"You must supply a file holding the location of the mp3 files" | ||
); | ||
} | ||
if (this.macro == null) { | ||
throw new BuildException("You must supply a macro"); | ||
} | ||
|
||
try { | ||
String tracklist = FileUtils.readFully(new java.io.FileReader(file)); | ||
|
||
boolean failed = false; | ||
int index = 1; | ||
|
||
for (String track : tracklist.split("\n")) { | ||
if (!"".equals(track)) { | ||
MacroInstance task = (MacroInstance) getProject().createTask(macro); | ||
track = track.substring(5); | ||
try { | ||
task.setDynamicAttribute( | ||
"src", | ||
track.substring(0, track.length() - 3) + "ssml" | ||
); | ||
task.setDynamicAttribute("dest", track); | ||
task.setDynamicAttribute("dir", dir); | ||
task.setDynamicAttribute("track", String.valueOf(index)); | ||
task.execute(); | ||
} catch (Exception err) { | ||
failed = true; | ||
} | ||
index++; | ||
} | ||
} | ||
if (failed) { | ||
getProject().setProperty("ssml.failed", "true"); | ||
} | ||
} catch (IOException e) { | ||
throw new BuildException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.