tracker格式从bt客户端适用转换为aria适用

一、前言

近来在树莓派上搭建了一个aria下载服务器,在配置bt-tracker时发现网上的tracker列表很多都是给客户端用的单行格式文件,有些tracker有五六百行,自己手动操作显然不现实,于是写了个小程序用来自动转换格式。

二、代码


import java.util.*;
import java.io.*;

public class AriaTracker {
	public static void main(String[] args) {
		Scanner varScanner = new Scanner(System.in);
		System.out.print("input the tracker-list's path: ");
		String from = varScanner.nextLine();
		System.out.print("input the list's filename:");
		String filename = varScanner.nextLine();
		String temp = convert(from+filename);
                if(temp == null){
                    System.out.println("error! the program will exit!");
                    System.exit(-1);
                }
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(from+filename+"_aria.txt",true));
			out.write(temp);
			out.close();
		}catch(IOException e) {
			e.printStackTrace();
		}
		System.out.println("Format converted successfully");
	}
	
	private	static String convert(String filepath) {
        try {
            File file = new File(filepath);
            String res="";
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = bufferedReader.readLine();
                while (lineTxt != null) {
                	if(lineTxt.equals(""))
                	{
                		lineTxt = bufferedReader.readLine();
                		continue;
                	}
                	res=res+lineTxt+",";
                	lineTxt = bufferedReader.readLine();
                }
                return res.substring(0,res.length()-1);
            }
        } catch (UnsupportedEncodingException | FileNotFoundException e) {
            System.out.println("Cannot find the file specified!");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Error reading file content!");
            e.printStackTrace();
        }
        return null;
    }
}

三、使用方法及注意事项

  1. 输入文件路径,路径要输全,以linux为例,假如文件在comixhe文件夹下,则输入:

/home/comixhe/

最后一个分隔符不要忘记输入。

  1. 输入文件名,假如文件叫tracker,就输入

tracker

有后缀要带后缀输入。

  1. 本程序是使用字符串一次性写入文件,如果tracker文件的字符数超过String限制会出错,对于我来说这个足够用,如果有需求请自行改动。
posted @ 2020-05-11 23:38  comixH  阅读(352)  评论(0编辑  收藏  举报