Skip to content

Commit 87d2834

Browse files
Stypoxlitetex
authored andcommitted
Fix checkstyle issues & more in DonationLinkHelper
Also add comment about the class being unused and replace the fixLink function with Utils.stringToUrl()
1 parent bd7b362 commit 87d2834

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.schabi.newpipe.extractor.utils;
22

33
import java.net.MalformedURLException;
4-
import java.net.URL;
54

6-
public class DonationLinkHelper {
5+
/**
6+
* Note: this class seems unused? Should it be removed?
7+
*/
8+
public final class DonationLinkHelper {
79
public enum DonationService {
810
NO_DONATION,
911
PATREON,
@@ -15,9 +17,12 @@ public enum AffiliateService {
1517
AMAZON,
1618
}
1719

18-
public static DonationService getDonationServiceByLink(String link) throws MalformedURLException {
19-
URL url = new URL(fixLink(link));
20-
switch (url.getHost()) {
20+
private DonationLinkHelper() {
21+
}
22+
23+
public static DonationService getDonationServiceByLink(final String link)
24+
throws MalformedURLException {
25+
switch (Utils.stringToURL(link).getHost()) {
2126
case "www.patreon.com":
2227
case "patreon.com":
2328
return DonationService.PATREON;
@@ -29,18 +34,11 @@ public static DonationService getDonationServiceByLink(String link) throws Malfo
2934
}
3035
}
3136

32-
public static AffiliateService getAffiliateServiceByLink(String link) throws MalformedURLException {
33-
URL url = new URL(fixLink(link));
34-
switch (url.getHost()) {
35-
case "amzn.to": return AffiliateService.AMAZON;
36-
default: return AffiliateService.NO_AFFILIATE;
37+
public static AffiliateService getAffiliateServiceByLink(final String link)
38+
throws MalformedURLException {
39+
if ("amzn.to".equals(Utils.stringToURL(link).getHost())) {
40+
return AffiliateService.AMAZON;
3741
}
42+
return AffiliateService.NO_AFFILIATE;
3843
}
39-
40-
private static String fixLink(String link) {
41-
return (link.startsWith("https://") || link.startsWith("http://"))
42-
? link
43-
: "https://" + link;
44-
}
45-
4644
}

0 commit comments

Comments
 (0)