Skip to content

Commit

Permalink
quickmedia 2.0 正式版
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyueyi committed Jun 20, 2019
1 parent 74d1988 commit a8b5d8d
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 131 deletions.
7 changes: 3 additions & 4 deletions plugins/audio-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>com.github.hui.media</groupId>
<version>1.1</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.hui.media</groupId>
<artifactId>audio-plugin</artifactId>
<version>1.1</version>
<version>2.0</version>

<dependencies>
<dependency>
<groupId>com.github.hui.media</groupId>
<artifactId>base-plugin</artifactId>
<version>1.1</version>
<version>2.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.hui.quick.plugin.audio;

import com.github.hui.quick.plugin.base.FileReadUtil;
import com.github.hui.quick.plugin.base.FileWriteUtil;
import com.github.hui.quick.plugin.base.ProcessUtil;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,20 +21,17 @@
public class AudioWrapper {

public static Builder<String> of(String str) {
Builder<String> builder = new Builder<>();
return builder.setSource(str);
return new Builder<String>().setSource(str);
}


public static Builder<URI> of(URI uri) {
Builder<URI> builder = new Builder<>();
return builder.setSource(uri);
return new Builder<URI>().setSource(uri);
}


public static Builder<InputStream> of(InputStream inputStream) {
Builder<InputStream> builder = new Builder<>();
return builder.setSource(inputStream);
return new Builder<InputStream>().setSource(inputStream);
}


Expand Down Expand Up @@ -75,7 +73,7 @@ public static class Builder<T> {
/**
* 命令行参数
*/
private Map<String, Object> options = new HashMap<>();
private Map<String, Object> options;


/**
Expand All @@ -86,6 +84,18 @@ public static class Builder<T> {

private String tempOutputFile;

public Builder() {
options = new HashMap<>(8);

// 添加兜底的配置信息

// 覆盖写
addOption("y", "")
// 解决mac/ios 显示音频时间不对的问题
.addOption("write_xing", 0)
// 不输出日志
.addOption("loglevel", "quiet");
}

public Builder<T> setSource(T source) {
this.source = source;
Expand Down Expand Up @@ -119,30 +129,18 @@ private String builder() throws Exception {

tempOutputFile = tempFileInfo.getPath() + "/" + tempFileInfo.getFilename() + "_out." + outputType;

return new AudioOptions().setSrc(tempFileInfo.getAbsFile())
.setDest(tempOutputFile)
.addOption("y", "") // 覆盖写
.addOption("write_xing", 0) // 解决mac/ios 显示音频时间不对的问题
.addOption("loglevel", "quiet") // 不输出日志
.build();
return new AudioOptions().setSrc(tempFileInfo.getAbsFile()).setDest(tempOutputFile).build();
}


public InputStream asStream() throws Exception {
String output = asFile();

if (output == null) {
return null;
}


return new FileInputStream(new File(output));
return output == null ? null : FileReadUtil.getStreamByFileName(output);
}


public String asFile() throws Exception {
String cmd = builder();
return !run(cmd) ? null : tempOutputFile;
return run(cmd) ? tempOutputFile : null;
}
}

Expand Down
7 changes: 2 additions & 5 deletions plugins/base-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>com.github.hui.media</groupId>
<version>1.1</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.hui.media</groupId>
<artifactId>base-plugin</artifactId>
<version>1.1</version>
<version>2.0</version>


<dependencies>
Expand All @@ -22,13 +21,11 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@
import java.io.*;
import java.net.URI;
import java.util.Date;
import java.util.Random;

/**
* Created by yihui on 2017/7/13.
*/
@Slf4j
public class FileWriteUtil {

public static String TEMP_PATH = "/tmp/quickmedia";
public static String TEMP_PATH = "/tmp/quickmedia/";

public static String getTmpPath() {
return TEMP_PATH + "/" + DateFormatUtils.format(new Date(), "yyyyMMdd");
// 优先从系统配置中获取获取临时目录参数,不存在时,用兜底的目录
String tmpPathEnvProperties = System.getProperty("quick.media.tmp.path");
if (StringUtils.isNotBlank(tmpPathEnvProperties)) {
if (tmpPathEnvProperties.endsWith("/")) {
TEMP_PATH = tmpPathEnvProperties;
} else {
TEMP_PATH = tmpPathEnvProperties + "/";
}
}

return TEMP_PATH + DateFormatUtils.format(new Date(), "yyyyMMdd");
}

public static <T> FileInfo saveFile(T src, String inputType) throws Exception {
Expand All @@ -34,7 +45,9 @@ public static <T> FileInfo saveFile(T src, String inputType) throws Exception {
// 输入流保存在到临时目录
return saveFileByStream((InputStream) src, inputType);
} else {
throw new IllegalStateException("save file parameter only support String/URI/InputStream type! but input type is: " + (src == null ? null : src.getClass()));
throw new IllegalStateException(
"save file parameter only support String/URI/InputStream type! but input type is: " +
(src == null ? null : src.getClass()));
}
}

Expand Down Expand Up @@ -68,7 +81,7 @@ private static FileInfo saveFileByPath(String path) throws Exception {


/**
* 下载远程文件, 保存到临时目录, 病生成文件信息
* 下载远程文件, 保存到临时目录, 生成文件信息
*
* @param uri
* @return
Expand Down Expand Up @@ -111,7 +124,8 @@ public static FileInfo saveFileByStream(InputStream inputStream, String fileType
* @param filename
* @return
*/
public static FileInfo saveFileByStream(InputStream stream, String path, String filename, String fileType) throws FileNotFoundException {
public static FileInfo saveFileByStream(InputStream stream, String path, String filename, String fileType)
throws FileNotFoundException {
return saveFileByStream(stream, new FileInfo(path, filename, fileType));
}

Expand Down Expand Up @@ -162,14 +176,18 @@ public static FileInfo saveFileByStream(InputStream stream, FileInfo fileInfo) t
}
}

/**
* 用于生成临时文件名后缀的随机生成器
*/
private static Random FILENAME_GEN_RANDOM = new Random();

/**
* 临时文件名生成: 时间戳 + 0-1000随机数
*
* @return
*/
private static String genTempFileName() {
return System.currentTimeMillis() + "_" + ((int) (Math.random() * 1000));
return System.currentTimeMillis() + "_" + FILENAME_GEN_RANDOM.nextInt(1000);
}


Expand Down Expand Up @@ -199,6 +217,11 @@ public static void mkDir(File file) throws FileNotFoundException {
}
}

/**
* 修改文件权限,设置为可读写
*
* @param file
*/
private static void modifyFileAuth(File file) {
boolean ans = file.setExecutable(true, false);
ans = file.setReadable(true, false) && ans;
Expand Down
5 changes: 2 additions & 3 deletions plugins/date-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>com.github.hui.media</groupId>
<version>1.1</version>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.hui.media</groupId>
<artifactId>date-plugin</artifactId>
<version>1.1</version>
<version>2.0</version>


<dependencies>
Expand Down
23 changes: 21 additions & 2 deletions plugins/date-plugin/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jar包引入,请注意使用最新的版本
<dependency>
<groupId>com.github.hui.media</groupId>
<artifactId>date-plugin</artifactId>
<version>1.0</version>
<version>2.0</version>
</dependency>
```

Expand All @@ -35,4 +35,23 @@ jar包引入,请注意使用最新的版本
- 一个扩展类 `ChineseDateExtendTool` 封装了农历输出


具体使用方法,可以参考方法签名
具体使用方法,可以参考方法签名,下面是一个简单的case

```java
@Test
public void testDate2Lunar() {
LocalDateTime now = LocalDateTime.now();
System.out.println(now + ">>>" + ChineseDateExtendTool.getNowLunarDate());

System.out.println(now + ">>>" +
ChineseDateExtendTool.getLunarDateByTimestamp(now.toInstant(ZoneOffset.ofHours(8)).toEpochMilli()));
}
```

输出结果如下


```bash
2019-06-20T08:08:19.758>>>己亥年伍月壹捌 辰时
2019-06-20T08:08:19.758>>>己亥年伍月壹捌 辰时
```
Loading

0 comments on commit a8b5d8d

Please sign in to comment.