update
This commit is contained in:
parent
bdc74957aa
commit
ed692199be
@ -18,6 +18,9 @@ import java.util.TimerTask;
|
|||||||
public class ApplicationInit implements ApplicationRunner {
|
public class ApplicationInit implements ApplicationRunner {
|
||||||
@Resource
|
@Resource
|
||||||
MusicToolsServiceImpl musicTools;
|
MusicToolsServiceImpl musicTools;
|
||||||
|
|
||||||
|
private static String oldTime = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
AudioTools.init();
|
AudioTools.init();
|
||||||
@ -25,6 +28,10 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
||||||
|
if (time.equals(oldTime)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oldTime = time;
|
||||||
switch (time) {
|
switch (time) {
|
||||||
case "00:00":
|
case "00:00":
|
||||||
musicTools.scanMusic();
|
musicTools.scanMusic();
|
||||||
@ -38,6 +45,33 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
switch (time) {
|
||||||
|
case "00:00":
|
||||||
|
case "01:00":
|
||||||
|
case "02:00":
|
||||||
|
case "03:00":
|
||||||
|
case "04:00":
|
||||||
|
case "05:00":
|
||||||
|
case "06:00":
|
||||||
|
case "07:00":
|
||||||
|
case "08:00":
|
||||||
|
case "09:00":
|
||||||
|
case "10:00":
|
||||||
|
case "11:00":
|
||||||
|
case "12:00":
|
||||||
|
case "13:00":
|
||||||
|
case "14:00":
|
||||||
|
case "15:00":
|
||||||
|
case "16:00":
|
||||||
|
case "17:00":
|
||||||
|
case "18:00":
|
||||||
|
case "19:00":
|
||||||
|
case "20:00":
|
||||||
|
case "21:00":
|
||||||
|
case "22:00":
|
||||||
|
case "23:00":
|
||||||
|
BTDownloadManager.getInstance().start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 0, 35 * 1000);
|
}, 0, 35 * 1000);
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ public class BTDownloadManager implements ApplicationContextAware {
|
|||||||
List<BangumiItem> list = bangumiService.getAllBangumi();
|
List<BangumiItem> list = bangumiService.getAllBangumi();
|
||||||
AnimationData data = new AnimationData();
|
AnimationData data = new AnimationData();
|
||||||
for (BangumiItem item : list) {
|
for (BangumiItem item : list) {
|
||||||
|
item.setAuthor(data.nameToValue(item.getAuthor(), true) + "");
|
||||||
|
item.setCategories(data.nameToValue(item.getCategories(), false) + "");
|
||||||
String url = getRSSUrl(item);
|
String url = getRSSUrl(item);
|
||||||
String _json = HttpTools.get(url);
|
String _json = HttpTools.get(url);
|
||||||
if (!StringUtils.isEmpty(_json)) {
|
if (!StringUtils.isEmpty(_json)) {
|
||||||
JSONObject json = JSONObject.parseObject(_json);
|
JSONObject json = JSONObject.parseObject(_json);
|
||||||
item.setAuthor(data.nameToValue(item.getAuthor(),true)+"");
|
|
||||||
item.setCategories(data.nameToValue(item.getCategories(),false)+"");
|
|
||||||
download(item, json);
|
download(item, json);
|
||||||
} else {
|
} else {
|
||||||
QQBotManager.getInstance().sendMessage(item.getTitle() + "\n下载失败");
|
QQBotManager.getInstance().sendMessage(item.getTitle() + "\n下载失败");
|
||||||
@ -84,21 +84,8 @@ public class BTDownloadManager implements ApplicationContextAware {
|
|||||||
array.add(item.getString("title"));
|
array.add(item.getString("title"));
|
||||||
RedisTools.set(bangumiItem.getTitle(), array.toJSONString());
|
RedisTools.set(bangumiItem.getTitle(), array.toJSONString());
|
||||||
if (item.containsKey("thumbnail")) {
|
if (item.containsKey("thumbnail")) {
|
||||||
HttpTools.download(item.getString("thumbnail"), bangumiItem.getTitle() + ".jpg", new DownloadInterface() {
|
File file = HttpTools.syncDownload(item.getString("thumbnail"), bangumiItem.getTitle() + ".jpg");
|
||||||
@Override
|
|
||||||
public void onDownload(File file) {
|
|
||||||
super.onDownload(file);
|
|
||||||
onSend(file, item);
|
onSend(file, item);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Exception e) {
|
|
||||||
super.onError(e);
|
|
||||||
onSend(null, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
onSend(null, item);
|
onSend(null, item);
|
||||||
}
|
}
|
||||||
@ -120,12 +107,14 @@ public class BTDownloadManager implements ApplicationContextAware {
|
|||||||
|
|
||||||
public boolean download(String title, String url) {
|
public boolean download(String title, String url) {
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(new String[]{"sh"
|
String exec = String.format("transmission-remote -n yutou:34864394 -w /media/yutou/4t/public/download/anim/%s -a \"%s\" "
|
||||||
, "-c"
|
|
||||||
, String.format("transmission-remote -n yutou:34864394 -w /media/yutou/4t/public/download/anim/%s -a \"%s\" "
|
|
||||||
, title
|
, title
|
||||||
, url
|
, url
|
||||||
)});
|
);
|
||||||
|
Log.i(exec);
|
||||||
|
Runtime.getRuntime().exec(new String[]{"sh"
|
||||||
|
, "-c"
|
||||||
|
, exec});
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -3,6 +3,7 @@ package com.yutou.nas.utils;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.yutou.nas.interfaces.DownloadInterface;
|
import com.yutou.nas.interfaces.DownloadInterface;
|
||||||
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@ -14,7 +15,7 @@ public class HttpTools {
|
|||||||
public static String get(String url) {
|
public static String get(String url) {
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
connection.setRequestProperty("User-Agent", getKuKuUA());
|
connection.setRequestProperty("User-Agent", getExtUa());
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
String tmp;
|
String tmp;
|
||||||
@ -43,6 +44,7 @@ public class HttpTools {
|
|||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
|
connection.addRequestProperty("User-Agent", getExtUa());
|
||||||
connection.setConnectTimeout(5 * 1000);
|
connection.setConnectTimeout(5 * 1000);
|
||||||
connection.setReadTimeout(10 * 1000);
|
connection.setReadTimeout(10 * 1000);
|
||||||
//connection.addRequestProperty("Connection", "keep-alive");
|
//connection.addRequestProperty("Connection", "keep-alive");
|
||||||
@ -127,7 +129,9 @@ public class HttpTools {
|
|||||||
com.yutou.nas.utils.Log.i(url);
|
com.yutou.nas.utils.Log.i(url);
|
||||||
//String str=get(url);
|
//String str=get(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String donwloadPath = "tmp" + File.separator;
|
private static String donwloadPath = "tmp" + File.separator;
|
||||||
|
|
||||||
public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) {
|
public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -140,7 +144,7 @@ public class HttpTools {
|
|||||||
}
|
}
|
||||||
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
connection.addRequestProperty("User-Agent", getExtUa());
|
||||||
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||||
|
|
||||||
|
|
||||||
@ -183,4 +187,53 @@ public class HttpTools {
|
|||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized static File syncDownload(final String url, final String saveName) {
|
||||||
|
if(StringUtils.isEmpty(url)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
File jar = null;
|
||||||
|
try {
|
||||||
|
File savePath = new File(donwloadPath);
|
||||||
|
if (!savePath.exists()) {
|
||||||
|
savePath.mkdirs();
|
||||||
|
}
|
||||||
|
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
connection.addRequestProperty("User-Agent", getExtUa());
|
||||||
|
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||||
|
|
||||||
|
|
||||||
|
InputStream inputStream = connection.getInputStream();
|
||||||
|
jar = new File(donwloadPath + saveName + "_tmp.tmp");
|
||||||
|
jar.createNewFile();
|
||||||
|
Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath());
|
||||||
|
OutputStream outputStream = new FileOutputStream(jar);
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
double size = connection.getContentLength();
|
||||||
|
double downSize = 0;
|
||||||
|
int len;
|
||||||
|
while ((len = inputStream.read(bytes)) > 0) {
|
||||||
|
outputStream.write(bytes, 0, len);
|
||||||
|
downSize += len;
|
||||||
|
}
|
||||||
|
outputStream.close();
|
||||||
|
inputStream.close();
|
||||||
|
File oldJar = new File(donwloadPath + saveName);
|
||||||
|
if (oldJar.exists()) {
|
||||||
|
oldJar.delete();
|
||||||
|
}
|
||||||
|
connection.disconnect();
|
||||||
|
jar.renameTo(oldJar);
|
||||||
|
Log.i("DOWNLOAD", "实际保存:" + oldJar.getAbsolutePath() + " " + oldJar.getName());
|
||||||
|
return oldJar;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
if (jar != null) {
|
||||||
|
jar.delete();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user