Skip to content

Commit

Permalink
Revert "Release preparation"
Browse files Browse the repository at this point in the history
This reverts commit da97503.
  • Loading branch information
actions-user committed Nov 14, 2022
1 parent 8d4f3d4 commit 38beab3
Show file tree
Hide file tree
Showing 60 changed files with 2,172 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
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
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
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
33 changes: 33 additions & 0 deletions .gitignore
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

99 changes: 99 additions & 0 deletions src/fox/jason/audiobook/tasks/CopyFromCacheTask.java
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);
}
}
}
84 changes: 84 additions & 0 deletions src/fox/jason/audiobook/tasks/CreateChapterEntryTask.java
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 src/fox/jason/audiobook/tasks/IterateTracklistTask.java
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);
}
}
}
Loading

0 comments on commit 38beab3

Please sign in to comment.