Skip to content

Commit

Permalink
Fix emule link
Browse files Browse the repository at this point in the history
  • Loading branch information
a-pavlov committed Jun 10, 2022
1 parent bf004ce commit d47b928
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/src/main/java/org/dkf/jed2k/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import org.dkf.jed2k.protocol.Hash;
import org.dkf.jed2k.protocol.Serializable;

import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Comparator;
Expand Down Expand Up @@ -227,11 +230,11 @@ public static boolean isLowId(int v) {
}

public static String formatLink(final String fileName, long fileSize, final Hash hash) {
return "ed2k://|file|" +
fileName + "|" +
fileSize + "|" +
hash.toString() +
"|/";
return "ed2k://|file|"
+ fileName.replace(" ", "%20")
+ "|" + fileSize
+ "|" + hash.toString()
+ "|/";
}

public static boolean isBit(int value, int mask) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/org/dkf/jed2k/test/EMuleLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public void testLinkBadSize() throws JED2KException {
public void testRealLinks() throws JED2KException {
EMuleLink eml1 = EMuleLink.fromString("ed2k://|file|Ps2%20Game%20Virtual%20Tennis%203.iso|734107648|66DEA14BB64F1FB690735F5322A46ADF|h=TAV3XL3F6MKDYULZG55JKMR6RMTOUVJ7|/");
assertEquals("Ps2 Game Virtual Tennis 3.iso", eml1.getStringValue());
EMuleLink eml3 = EMuleLink.fromString("ed2k://|file|Ps2 Game Virtual Tennis 3.iso|734107648|66DEA14BB64F1FB690735F5322A46ADF|h=TAV3XL3F6MKDYULZG55JKMR6RMTOUVJ7|/");
assertEquals("Ps2 Game Virtual Tennis 3.iso", eml3.getStringValue());
EMuleLink eml2 = EMuleLink.fromString("ed2k://%7Cfile|SkypeSetupFull.exe|47026816|3636DF370FFDCC4783252183EC566A8C|h=O4F7O7NL7PWU4ATT3LRXWIG6CQBQXEVS|/");
assertEquals("SkypeSetupFull.exe", eml2.getStringValue());
}
Expand Down
1 change: 1 addition & 0 deletions core/src/test/java/org/dkf/jed2k/test/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void testIdDetector() throws UnknownHostException {
@Test
public void testLinksGeneration() {
assertEquals("ed2k://|file|some_file|100|31D6CFE0D16AE931B73C59D7E0C089C0|/", Utils.formatLink("some_file", 100L, Hash.TERMINAL));
assertEquals("ed2k://|file|Sinuhe%20L'egiziano%20(1954)%20(DVDRip.x264.ITA.ENG)%20(Ebleep).mkv|2277521653|157958B871FEE3017661FB1F6BC3C138|/", Utils.formatLink("Sinuhe L'egiziano (1954) (DVDRip.x264.ITA.ENG) (Ebleep).mkv", 2277521653L, Hash.fromString("157958B871FEE3017661FB1F6BC3C138")));
}

@Test
Expand Down

0 comments on commit d47b928

Please sign in to comment.