i2psnark: Add support for comment and url_list to Storage CLI

Add support for multiple urls to MetaInfo CLI
Add comment to release torrent
This commit is contained in:
zzz
2020-10-30 16:37:54 +00:00
parent 5c1a529df0
commit 90aab37002
3 changed files with 55 additions and 9 deletions

View File

@ -792,7 +792,7 @@ public class MetaInfo
boolean error = false;
String created_by = null;
String announce = null;
String url = null;
List<String> url_list = null;
String comment = null;
Getopt g = new Getopt("Storage", args, "a:c:m:w:");
try {
@ -812,7 +812,9 @@ public class MetaInfo
break;
case 'w':
url = g.getOptarg();
if (url_list == null)
url_list = new ArrayList<String>();
url_list.add(g.getOptarg());
break;
case '?':
@ -827,7 +829,7 @@ public class MetaInfo
error = true;
}
if (error || args.length - g.getOptind() <= 0) {
System.err.println("Usage: MetaInfo [-a announceURL] [-c created-by] [-m comment] [-w web-seed-url] file.torrent [file2.torrent...]");
System.err.println("Usage: MetaInfo [-a announceURL] [-c created-by] [-m comment] [-w webseed-url]* file.torrent [file2.torrent...]");
System.exit(1);
}
for (int i = g.getOptind(); i < args.length; i++) {
@ -842,11 +844,11 @@ public class MetaInfo
"\nWebSeed URLs: " + meta.getWebSeedURLs() +
"\nCreated By: " + meta.getCreatedBy() +
"\nComment: " + meta.getComment());
if (created_by != null || announce != null || url != null || comment != null) {
if (created_by != null || announce != null || url_list != null || comment != null) {
String cb = created_by != null ? created_by : meta.getCreatedBy();
String an = announce != null ? announce : meta.getAnnounce();
String cm = comment != null ? comment : meta.getComment();
List<String> urls = url != null ? Collections.singletonList(url) : meta.getWebSeedURLs();
List<String> urls = url_list != null ? url_list : meta.getWebSeedURLs();
// changes/adds creation date
MetaInfo meta2 = new MetaInfo(an, meta.getName(), null, meta.getFiles(), meta.getLengths(),
meta.getPieceLength(0), meta.getPieceHashes(), meta.getTotalLength(), meta.isPrivate(),

View File

@ -144,6 +144,30 @@ public class Storage implements Closeable
String created_by,
boolean privateTorrent, StorageListener listener)
throws IOException
{
this(util, baseFile, announce, announce_list, created_by, privateTorrent, null, null, listener);
}
/**
* Creates a storage from the existing file or directory.
* Creates an in-memory metainfo but does not save it to
* a file, caller must do that.
*
* Creates the metainfo, this may take a LONG time. BLOCKING.
*
* @param announce may be null
* @param listener may be null
* @param created_by may be null
* @param url_list may be null
* @param comment may be null
* @throws IOException when creating and/or checking files fails.
* @since 0.9.48
*/
public Storage(I2PSnarkUtil util, File baseFile, String announce,
List<List<String>> announce_list,
String created_by,
boolean privateTorrent, List<String> url_list, String comment, StorageListener listener)
throws IOException
{
_util = util;
_base = baseFile;
@ -210,7 +234,7 @@ public class Storage implements Closeable
byte[] piece_hashes = fast_digestCreate();
metainfo = new MetaInfo(announce, baseFile.getName(), null, files,
lengthsList, piece_size, piece_hashes, total, privateTorrent,
announce_list, created_by, null, null);
announce_list, created_by, url_list, comment);
}
@ -1685,7 +1709,9 @@ public class Storage implements Closeable
boolean error = false;
String created_by = null;
String announce = null;
Getopt g = new Getopt("Storage", args, "a:c:");
List<String> url_list = null;
String comment = null;
Getopt g = new Getopt("Storage", args, "a:c:m:w:");
try {
int c;
while ((c = g.getopt()) != -1) {
@ -1698,6 +1724,16 @@ public class Storage implements Closeable
created_by = g.getOptarg();
break;
case 'm':
comment = g.getOptarg();
break;
case 'w':
if (url_list == null)
url_list = new ArrayList<String>();
url_list.add(g.getOptarg());
break;
case '?':
case ':':
default:
@ -1710,7 +1746,7 @@ public class Storage implements Closeable
error = true;
}
if (error || args.length - g.getOptind() != 1) {
System.err.println("Usage: Storage [-a announceURL] [-c created-by] file-or-dir");
System.err.println("Usage: Storage [-a announceURL] [-c created-by] [-m comment] [-w webseed-url]* file-or-dir");
System.exit(1);
}
File base = new File(args[g.getOptind()]);
@ -1719,7 +1755,7 @@ public class Storage implements Closeable
File file = null;
FileOutputStream out = null;
try {
Storage storage = new Storage(util, base, announce, null, created_by, false, null);
Storage storage = new Storage(util, base, announce, null, created_by, false, url_list, comment, null);
MetaInfo meta = storage.getMetaInfo();
file = new File(storage.getBaseName() + ".torrent");
out = new FileOutputStream(file);