|
18 | 18 | import java.util.ArrayList; |
19 | 19 |
|
20 | 20 | import jd.PluginWrapper; |
21 | | -import jd.config.SubConfiguration; |
22 | 21 | import jd.controlling.ProgressController; |
23 | | -import jd.nutils.encoding.Encoding; |
24 | | -import jd.parser.Regex; |
25 | 22 | import jd.plugins.CryptedLink; |
26 | 23 | import jd.plugins.DecrypterPlugin; |
27 | 24 | import jd.plugins.DownloadLink; |
28 | | -import jd.plugins.FilePackage; |
| 25 | +import jd.plugins.LinkStatus; |
| 26 | +import jd.plugins.PluginException; |
29 | 27 | import jd.plugins.PluginForDecrypt; |
30 | | -import jd.utils.JDUtilities; |
31 | 28 |
|
32 | | -@DecrypterPlugin(revision = "$Revision: 49222 $", interfaceVersion = 2, names = { "sta.sh" }, urls = { "https?://(?:www\\.)?sta\\.sh/(zip/)?[a-z0-9]+" }) |
| 29 | +@DecrypterPlugin(revision = "$Revision: 51281 $", interfaceVersion = 2, names = { "sta.sh" }, urls = { "https?://(?:www\\.)?sta\\.sh/(zip/)?[a-z0-9]+" }) |
33 | 30 | public class StaShDecrypter extends PluginForDecrypt { |
34 | 31 | public StaShDecrypter(PluginWrapper wrapper) { |
35 | 32 | super(wrapper); |
36 | 33 | } |
37 | 34 |
|
38 | | - private final String INVALIDLINKS = "https?://(www\\.)?sta\\.sh/(muro|writer|login)"; |
39 | | - private final String TYPE_ZIP = "https?://(www\\.)?sta\\.sh/zip/[a-z0-9]+"; |
40 | | - private static String FORCEHTMLDOWNLOAD = "FORCEHTMLDOWNLOAD"; |
41 | | - private static String USE_LINKID_AS_FILENAME = "USE_LINKID_AS_FILENAME"; |
42 | | - private static String DOWNLOAD_ZIP = "DOWNLOAD_ZIP"; |
43 | | - |
44 | 35 | public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress) throws Exception { |
45 | | - ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>(); |
46 | | - final String parameter = param.toString(); |
47 | | - if (parameter.matches(TYPE_ZIP)) { |
48 | | - final DownloadLink link = createDownloadlink(parameter); |
49 | | - link.setProperty("iszip", true); |
50 | | - link.setProperty("directlink", parameter); |
51 | | - decryptedLinks.add(link); |
52 | | - return decryptedLinks; |
53 | | - } |
54 | | - JDUtilities.getPluginForHost("sta.sh"); |
55 | | - final SubConfiguration cfg = SubConfiguration.getConfig("sta.sh"); |
56 | | - final boolean force_html_dl = cfg.getBooleanProperty(FORCEHTMLDOWNLOAD, false); |
57 | | - final boolean linkid_as_filename = cfg.getBooleanProperty(USE_LINKID_AS_FILENAME, false); |
58 | | - final String main_linkid = new Regex(parameter, "sta\\.sh/(.+)").getMatch(0); |
59 | | - final DownloadLink main = createDownloadlink(parameter); |
60 | | - if (parameter.matches(INVALIDLINKS)) { |
61 | | - decryptedLinks.add(this.createOfflinelink(parameter)); |
62 | | - return decryptedLinks; |
63 | | - } |
64 | | - br.getPage(parameter); |
65 | | - if (this.br.getHttpConnection().getResponseCode() == 404) { |
66 | | - decryptedLinks.add(this.createOfflinelink(parameter)); |
67 | | - return decryptedLinks; |
68 | | - } |
69 | | - final String linkid_general = new Regex(parameter, "([a-z0-9]+)$").getMatch(0); |
70 | | - String fpName = br.getRegex("name=\"og:title\" content=\"([^<>\"]*?)\"").getMatch(0); |
71 | | - if (fpName == null) { |
72 | | - /* Fallback */ |
73 | | - fpName = linkid_general; |
74 | | - } |
75 | | - fpName = Encoding.htmlDecode(fpName.trim()); |
76 | | - if (this.br.containsHTML("dev\\-metainfo\\-details\\-client\\-link")) { |
77 | | - /* We should have one or multiple pictures. */ |
78 | | - final String[][] picdata = br.getRegex("class=\"thumb\" href=\"(https?://(www\\.)?sta\\.sh/[a-z0-9]+)\" title=\"([^<>\"]*?)\"").getMatches(); |
79 | | - if (picdata == null || picdata.length == 0) { |
80 | | - decryptedLinks.add(main); |
81 | | - return decryptedLinks; |
82 | | - } |
83 | | - for (final String singleLinkData[] : picdata) { |
84 | | - final String url = singleLinkData[0]; |
85 | | - final String linkid = new Regex(url, "sta\\.sh/(.+)").getMatch(0); |
86 | | - String name = Encoding.htmlDecode(singleLinkData[2]); |
87 | | - final DownloadLink dl = createDownloadlink(url); |
88 | | - /* Obey user setting */ |
89 | | - if (linkid_as_filename) { |
90 | | - name = linkid; |
91 | | - } |
92 | | - if (force_html_dl) { |
93 | | - dl.setName(name + ".html"); |
94 | | - dl.setAvailable(true); |
95 | | - } else { |
96 | | - dl.setName(name); |
97 | | - dl.setAvailable(true); |
98 | | - } |
99 | | - decryptedLinks.add(dl); |
100 | | - } |
101 | | - } else { |
102 | | - /* These URLs will go back into the decrypter. */ |
103 | | - final String[] URLs = this.br.getRegex("href=\"(https?://sta\\.sh/[a-z0-9]{10,})\"").getColumn(0); |
104 | | - for (final String url : URLs) { |
105 | | - if (url.contains(linkid_general)) { |
106 | | - /* Fail-safe to prevent infinite loops! */ |
107 | | - continue; |
108 | | - } else { |
109 | | - decryptedLinks.add(this.createDownloadlink(url)); |
110 | | - } |
111 | | - } |
| 36 | + final ArrayList<DownloadLink> ret = new ArrayList<DownloadLink>(); |
| 37 | + final String contenturl = param.getCryptedUrl().replaceFirst("(?i)http://", "https://"); |
| 38 | + br.getPage(contenturl); |
| 39 | + if (br.getHttpConnection().getResponseCode() == 404) { |
| 40 | + throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
112 | 41 | } |
113 | | - /* Download zip if it exists and user wants it. */ |
114 | | - final String zipLink = br.getRegex("\"(/zip/[a-z0-9]+)\"").getMatch(0); |
115 | | - if (cfg.getBooleanProperty(DOWNLOAD_ZIP, false) && zipLink != null) { |
116 | | - final DownloadLink zip = createDownloadlink(parameter); |
117 | | - zip.setProperty("iszip", true); |
118 | | - zip.setProperty("directlink", zipLink); |
119 | | - String zip_filename; |
120 | | - if (linkid_as_filename) { |
121 | | - zip_filename = main_linkid; |
122 | | - } else { |
123 | | - zip_filename = fpName; |
124 | | - } |
125 | | - if (force_html_dl) { |
126 | | - zip.setName(zip_filename + ".html"); |
127 | | - } else { |
128 | | - zip.setName(zip_filename + ".zip"); |
129 | | - } |
130 | | - zip.setAvailable(true); |
131 | | - decryptedLinks.add(zip); |
| 42 | + final String redirect = br.getRedirectLocation(); |
| 43 | + if (redirect == null) { |
| 44 | + throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
132 | 45 | } |
133 | | - final FilePackage fp = FilePackage.getInstance(); |
134 | | - fp.setName(fpName); |
135 | | - fp.addLinks(decryptedLinks); |
136 | | - return decryptedLinks; |
| 46 | + ret.add(this.createDownloadlink(redirect)); |
| 47 | + return ret; |
137 | 48 | } |
138 | 49 | } |
0 commit comments