Skip to content

Instantly share code, notes, and snippets.

@gubatron
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gubatron/a818187fe9a1dc9687d6 to your computer and use it in GitHub Desktop.
Save gubatron/a818187fe9a1dc9687d6 to your computer and use it in GitHub Desktop.
Notes on FrostWire+Azureus aditional info properties.
Classes to look at when porting this to frostwire-jlibtorrent:
TorrentInfoManipulator - goes to TOTOrrentImpl and temporarily makes the field "additional_info_properties" accesible, and creates a reference to it that can be used from FrostWire's code base.
Azureus uses this "additional_info_properties" Map, at the end of torrent bencoding serialization and whatever is in it gets added to the info map.
With TorrentInfoManipulator we can add whatever we want to a torrent's info map.
CreateTorrentDialog: here is where it all ties up, after all the data has been gathered from the different complex ui tabs, this uses TorrentInfoManipulator to add the new properties.
.addAvailableCopyrightLicense() ads the license under "license" as a map that contains the following:
```
public Map<String, Map<String, String>> asMap() {
Map<String, Map<String, String>> container = new HashMap<String, Map<String, String>>();
Map<String, String> innerMap = new HashMap<String, String>();
innerMap.put("licenseUrl", this.license.getUrl());
innerMap.put("attributionTitle", this.attributionTitle);
innerMap.put("attributionAuthor", this.attributionAuthor);
innerMap.put("attributionUrl", this.attributionUrl);
container.put(licenseCategory.toString(), innerMap);
return container;
}
```
that licenseCategory is a LicenseCategory enum, which is used as the sub-key (ideally a torrent might encompass more than one license so this is an area that could be updated.), the values are: "creative-commons", "open-source", "public-domain", "no-license"
For example:
```
'license' : {
'open-source' : {
'attributionAuthor' : 'FrostWire LLC',
'attributionTitle' : 'FrostWire 5.7.5',
'attributionUrl' : 'http://www.frostwire.com',
'licenseUrl' : 'https://www.gnu.org/licenses/gpl.html',
'isDct' : true
}
}
```
(notice how azureus ads a isDct parameter there, I still don't know if libtorrent does this)
Other field we might want to add to torrents created with jlibtorrent is ***name.utf-8*** which has the name of the file. I can't remember now, but I believe I've used this for something.
Payment Options!
Check CreateTorrentDialog.addAvailablePaymentOptions(), PaymentOptions.
These are added under a 'paymentOptions' dictionary again using the TorrentInfoManipulator
very straight forward map
```
public Map<String, Map<String, String>> asMap() {
Map<String, String> innerMap = new HashMap<String, String>();
if (!StringUtils.isNullOrEmpty(bitcoin)) {
innerMap.put("bitcoin", bitcoin);
}
if (!StringUtils.isNullOrEmpty(litecoin)) {
innerMap.put("litecoin", litecoin);
}
if (!StringUtils.isNullOrEmpty(dogecoin)) {
innerMap.put("dogecoin", dogecoin);
}
if (!StringUtils.isNullOrEmpty(paypalUrl)) {
innerMap.put("paypalUrl", paypalUrl);
}
Map<String, Map<String, String>> paymentOptions = new HashMap<String, Map<String, String>>();
if (!innerMap.isEmpty()) {
paymentOptions.put("paymentOptions", innerMap);
}
return paymentOptions;
}
```
Looks like this
```
paymentOptions : {
'bitcoin' : 'bitcoin:14F6JPXK2fR5b4gZp3134qLRGgYtvabMWL',
'dogecoin' : 'dogecoin:DJ7zB7c5BsB9UJLy1rKQtY7c6CQfGiaRLM',
'litecoin' : 'litecoin:LZ2L61M8rCoZmK7SemTBqfxuFZv5Uj4peR',
'paypalUrl' : 'http://www.frostwire.com/donate',
'isDct' : true
}
```
All crypto address are normalized to include their rightful prefix:,and the last one 'paypalUrl' is actually open to be used for whatever else, but the UI suggests you should use a paypalUrl.
This example confirms the isDct is there to mark the array as a dictionary in bencoding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment