fix bug https://github.com/AriaLyy/Aria/issues/508
fix bug https://github.com/AriaLyy/Aria/issues/503
修复m3u8创建索引不成功的问题
This commit is contained in:
laoyuyu
2019-11-10 13:25:21 +08:00
parent 012f94511b
commit 5ad485890c
44 changed files with 753 additions and 242 deletions

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.sftp;
import com.arialyy.aria.core.inf.OnFileInfoCallback;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
/**
* 获取sftp文件信息
*
* @author lyy
*/
public class AbsSFtpFileInfoThread<WP extends AbsTaskWrapper> implements Runnable {
private WP mWrapper;
private SFtpUtil mUtil;
private OnFileInfoCallback mCallback;
public AbsSFtpFileInfoThread(SFtpUtil util, WP wrapper, OnFileInfoCallback callback) {
mWrapper = wrapper;
mUtil = util;
mCallback = callback;
}
@Override public void run() {
startFlow();
}
private void startFlow() {
}
private ChannelSftp createChannel() {
ChannelSftp sftp = null;
try {
sftp = (ChannelSftp) mUtil.getSession().openChannel(SFtpUtil.CMD_TYPE_SFTP);
sftp.connect();
} catch (JSchException e) {
e.printStackTrace();
}
return sftp;
}
}

View File

@@ -16,24 +16,39 @@
package com.arialyy.aria.sftp;
import android.text.TextUtils;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* sftp登录
* sftp工具类
*
* @author lyy
*/
public class SFtpLogin {
public class SFtpUtil {
private final String TAG = CommonUtil.getClassName(getClass());
/**
* 用于执行命令
*/
public static final String CMD_TYPE_EXEC = "exec";
/**
* 用于处理文件
*/
public static final String CMD_TYPE_SFTP = "sftp";
private String ip, userName, password;
private int port;
private Session session;
private boolean isLogin = false;
private SFtpLogin() {
private SFtpUtil() {
createClient();
}
@@ -55,6 +70,7 @@ public class SFtpLogin {
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);// 为Session对象设置properties
session.setTimeout(3000);// 设置超时
login();
isLogin = true;
} catch (JSchException e) {
e.printStackTrace();
@@ -83,6 +99,65 @@ public class SFtpLogin {
isLogin = false;
}
public Session getSession() {
return session;
}
/**
* 执行命令
*
* @param cmd sftp命令
*/
public void execCommand(String cmd) {
if (TextUtils.isEmpty(cmd)) {
ALog.e(TAG, "命令为空");
return;
}
if (!isLogin) {
ALog.e(TAG, "没有登录");
return;
}
ChannelExec channel = null;
try {
channel = (ChannelExec) session.openChannel(CMD_TYPE_EXEC);
channel.setCommand(cmd);
channel.connect();
String rst = getResult(channel.getInputStream());
ALog.i(TAG, String.format("result: %s", rst));
} catch (IOException e) {
e.printStackTrace();
} catch (JSchException e) {
e.printStackTrace();
} finally {
if (channel != null) {
channel.disconnect();
}
}
}
/**
* 执行命令后获取服务器端返回的数据
*
* @return 服务器端返回的数据
*/
private String getResult(InputStream in) throws IOException {
if (in == null){
ALog.e(TAG, "输入流为空");
return null;
}
StringBuilder sb = new StringBuilder();
BufferedReader isr = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = isr.readLine()) != null) {
sb.append(line);
}
in.close();
isr.close();
return sb.toString();
}
public static class Builder {
private String ip, userName, password;
private int port = 22;
@@ -107,8 +182,8 @@ public class SFtpLogin {
return this;
}
public SFtpLogin build() {
SFtpLogin login = new SFtpLogin();
public SFtpUtil build() {
SFtpUtil login = new SFtpUtil();
login.ip = ip;
login.userName = userName;
login.password = password;

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.sftp.download;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.task.IThreadTask;
import com.arialyy.aria.core.task.ThreadTask;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.ftp.download.FtpDLoaderAdapter;
/**
* sftp下载适配器
*
* @author lyy
*/
final class SFtpDLoaderAdapter extends FtpDLoaderAdapter {
SFtpDLoaderAdapter(ITaskWrapper wrapper) {
super(wrapper);
}
@Override public IThreadTask createThreadTask(SubThreadConfig config) {
ThreadTask threadTask = new ThreadTask(config);
SFtpDThreadTaskAdapter adapter = new SFtpDThreadTaskAdapter(config);
threadTask.setAdapter(adapter);
return threadTask;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.sftp.download;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.OnFileInfoCallback;
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.loader.AbsLoader;
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
import com.arialyy.aria.core.loader.NormalLoader;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.ftp.FtpTaskOption;
import com.arialyy.aria.sftp.AbsSFtpFileInfoThread;
import com.arialyy.aria.sftp.SFtpUtil;
/**
* sftp下载工具
*
* @author lyy
*/
public class SFtpDLoaderUtil extends AbsNormalLoaderUtil {
private SFtpUtil mSftpUtil;
protected SFtpDLoaderUtil(AbsTaskWrapper wrapper, IEventListener listener) {
super(wrapper, listener);
wrapper.generateTaskOption(FtpTaskOption.class);
FtpTaskOption option = (FtpTaskOption) wrapper.getTaskOption();
mSftpUtil = new SFtpUtil.Builder()
.setIp(option.getUrlEntity().hostName)
.setPort(Integer.parseInt(option.getUrlEntity().port))
.setUserName(option.getUrlEntity().user)
.setPassword(option.getUrlEntity().password)
.build();
}
@Override protected AbsLoader createLoader() {
NormalLoader loader = new NormalLoader(getListener(), getTaskWrapper());
loader.setAdapter(new SFtpDLoaderAdapter(getTaskWrapper()));
return loader;
}
@Override protected Runnable createInfoThread() {
return new AbsSFtpFileInfoThread<>(mSftpUtil, (DTaskWrapper) getTaskWrapper(), new OnFileInfoCallback() {
@Override public void onComplete(String key, CompleteInfo info) {
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
mSftpUtil.logout();
}
});
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.sftp.download;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.task.AbsThreadTaskAdapter;
/**
* sftp 线程任务适配器
*
* @author lyy
*/
public class SFtpDThreadTaskAdapter extends AbsThreadTaskAdapter {
SFtpDThreadTaskAdapter(SubThreadConfig config) {
super(config);
}
@Override protected void handlerThreadTask() {
}
}