1+ //jDownloader - Downloadmanager
2+ //Copyright (C) 2009 JD-Team support@jdownloader.org
3+ //
4+ //This program is free software: you can redistribute it and/or modify
5+ //it under the terms of the GNU General Public License as published by
6+ //the Free Software Foundation, either version 3 of the License, or
7+ //(at your option) any later version.
8+ //
9+ //This program is distributed in the hope that it will be useful,
10+ //but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ //GNU General Public License for more details.
13+ //
14+ //You should have received a copy of the GNU General Public License
15+ //along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ package jd .plugins .hoster ;
17+
18+ import java .io .IOException ;
19+ import java .util .ArrayList ;
20+ import java .util .HashMap ;
21+ import java .util .List ;
22+ import java .util .Map ;
23+
24+ import org .appwork .storage .JSonStorage ;
25+ import org .appwork .storage .TypeRef ;
26+ import org .appwork .utils .DebugMode ;
27+ import org .appwork .utils .StringUtils ;
28+ import org .appwork .utils .formatter .SizeFormatter ;
29+ import org .jdownloader .captcha .v2 .challenge .cloudflareturnstile .CaptchaHelperHostPluginCloudflareTurnstile ;
30+
31+ import jd .PluginWrapper ;
32+ import jd .http .Browser ;
33+ import jd .http .Request ;
34+ import jd .nutils .encoding .Encoding ;
35+ import jd .parser .Regex ;
36+ import jd .plugins .Account ;
37+ import jd .plugins .DownloadLink ;
38+ import jd .plugins .DownloadLink .AvailableStatus ;
39+ import jd .plugins .HostPlugin ;
40+ import jd .plugins .LinkStatus ;
41+ import jd .plugins .PluginException ;
42+ import jd .plugins .PluginForHost ;
43+
44+ @ HostPlugin (revision = "$Revision: 51786 $" , interfaceVersion = 3 , names = {}, urls = {})
45+ public class VexfileCom extends PluginForHost {
46+ public VexfileCom (PluginWrapper wrapper ) {
47+ super (wrapper );
48+ }
49+
50+ @ Override
51+ public Browser createNewBrowserInstance () {
52+ final Browser br = super .createNewBrowserInstance ();
53+ br .setFollowRedirects (true );
54+ return br ;
55+ }
56+
57+ @ Override
58+ public String getAGBLink () {
59+ return "https://" + getHost () + "/tos" ;
60+ }
61+
62+ private static List <String []> getPluginDomains () {
63+ final List <String []> ret = new ArrayList <String []>();
64+ // each entry in List<String[]> will result in one PluginForHost, Plugin.getHost() will return String[0]->main domain
65+ ret .add (new String [] { "vexfile.com" });
66+ return ret ;
67+ }
68+
69+ public static String [] getAnnotationNames () {
70+ return buildAnnotationNames (getPluginDomains ());
71+ }
72+
73+ @ Override
74+ public String [] siteSupportedNames () {
75+ return buildSupportedNames (getPluginDomains ());
76+ }
77+
78+ public static String [] getAnnotationUrls () {
79+ final List <String > ret = new ArrayList <String >();
80+ for (final String [] domains : getPluginDomains ()) {
81+ ret .add ("https?://(?:www\\ .)?" + buildHostsPatternPart (domains ) + "/download/([A-Za-z0-9]+)" );
82+ }
83+ return ret .toArray (new String [0 ]);
84+ }
85+
86+ @ Override
87+ public String getLinkID (final DownloadLink link ) {
88+ final String fid = getFID (link );
89+ if (fid != null ) {
90+ return this .getHost () + "://" + fid ;
91+ } else {
92+ return super .getLinkID (link );
93+ }
94+ }
95+
96+ private String getFID (final DownloadLink link ) {
97+ return new Regex (link .getPluginPatternMatcher (), this .getSupportedLinks ()).getMatch (0 );
98+ }
99+
100+ @ Override
101+ public boolean isResumeable (final DownloadLink link , final Account account ) {
102+ return true ;
103+ }
104+
105+ public int getMaxChunks (final DownloadLink link , final Account account ) {
106+ return 0 ;
107+ }
108+
109+ @ Override
110+ protected String getDefaultFileName (DownloadLink link ) {
111+ return this .getFID (link );
112+ }
113+
114+ @ Override
115+ public AvailableStatus requestFileInformation (final DownloadLink link ) throws IOException , PluginException {
116+ this .setBrowserExclusive ();
117+ br .getPage (link .getPluginPatternMatcher ());
118+ if (br .getHttpConnection ().getResponseCode () == 404 ) {
119+ throw new PluginException (LinkStatus .ERROR_FILE_NOT_FOUND );
120+ }
121+ String filename = br .getRegex ("class=\" card-dt\" [^>]*>\\ s*<h4>([^<]+)</h4>" ).getMatch (0 );
122+ if (StringUtils .isEmpty (filename )) {
123+ filename = br .getRegex ("title:\\ s*'([^'\" ]+)" ).getMatch (0 );
124+ }
125+ String filesize = br .getRegex ("class=\" file-size\" [^>]*>\\ s*<[^>]*>\\ s*</i>([^<]+)" ).getMatch (0 );
126+ if (filename != null ) {
127+ filename = Encoding .htmlDecode (filename ).trim ();
128+ link .setName (filename );
129+ } else {
130+ logger .warning ("Failed to find filename" );
131+ }
132+ if (filesize != null ) {
133+ link .setDownloadSize (SizeFormatter .getSize (filesize ));
134+ } else {
135+ logger .warning ("Failed to find filesize" );
136+ }
137+ return AvailableStatus .TRUE ;
138+ }
139+
140+ @ Override
141+ public void handleFree (final DownloadLink link ) throws Exception , PluginException {
142+ handleDownload (link );
143+ }
144+
145+ private void handleDownload (final DownloadLink link ) throws Exception , PluginException {
146+ final String directlinkproperty = "directurl" ;
147+ if (!attemptStoredDownloadurlDownload (link , directlinkproperty )) {
148+ requestFileInformation (link );
149+ final String continuelink = br .getRegex ("href=\" ([^\" ]+)\" [^>]*class=\" generate-link blocked\" " ).getMatch (0 );
150+ if (continuelink == null ) {
151+ throw new PluginException (LinkStatus .ERROR_PLUGIN_DEFECT , "Failed to find continuelink" );
152+ }
153+ final String file_id = br .getRegex ("id=\" file_id\" value=\" (\\ d+)\" " ).getMatch (0 );
154+ if (file_id == null ) {
155+ throw new PluginException (LinkStatus .ERROR_PLUGIN_DEFECT , "Failed to find file_id" );
156+ }
157+ final String csrftoken = br .getRegex ("'X-CSRF-TOKEN':\\ s*'([^\" ']+)" ).getMatch (0 );
158+ if (csrftoken == null ) {
159+ throw new PluginException (LinkStatus .ERROR_PLUGIN_DEFECT , "Failed to find file_id" );
160+ }
161+ if (!DebugMode .TRUE_IN_IDE_ELSE_FALSE ) {
162+ throw new PluginException (LinkStatus .ERROR_PLUGIN_DEFECT , "Unfinished plugin!" );
163+ }
164+ final String cfTurnstileResponse = new CaptchaHelperHostPluginCloudflareTurnstile (this , br ).getToken ();
165+ final Map <String , Object > postdata = new HashMap <String , Object >();
166+ postdata .put ("file_id" , csrftoken );
167+ postdata .put ("token" , cfTurnstileResponse );
168+ final Request req = br .createJSonPostRequest ("/verify-cf-captcha" , JSonStorage .serializeToJson (postdata ));
169+ req .getHeaders ().put ("Content-Type" , "application/json" );
170+ req .getHeaders ().put ("X-CSRF-TOKEN" , csrftoken );
171+ /* This should set at least two cookies: XSRF-TOKEN, vexfilecom_session */
172+ br .getPage (req );
173+ final Map <String , Object > entries = restoreFromString (br .getRequest ().getHtmlCode (), TypeRef .MAP );
174+ if (Boolean .FALSE .equals (entries .get ("success" ))) {
175+ /* This should be a rare case. */
176+ throw new PluginException (LinkStatus .ERROR_CAPTCHA );
177+ }
178+ br .getPage (continuelink );
179+ String dllink = br .getRegex ("\" (/[^\" ]+)\" [^>]*class=\" generate-link\" " ).getMatch (0 );
180+ if (StringUtils .isEmpty (dllink )) {
181+ throw new PluginException (LinkStatus .ERROR_PLUGIN_DEFECT , "Failed to find final downloadurl" );
182+ }
183+ dl = jd .plugins .BrowserAdapter .openDownload (br , link , dllink , this .isResumeable (link , null ), this .getMaxChunks (link , null ));
184+ this .handleConnectionErrors (br , dl .getConnection ());
185+ link .setProperty (directlinkproperty , dl .getConnection ().getURL ().toExternalForm ());
186+ }
187+ dl .startDownload ();
188+ }
189+
190+ @ Override
191+ public boolean hasCaptcha (DownloadLink link , jd .plugins .Account acc ) {
192+ return true ;
193+ }
194+
195+ private boolean attemptStoredDownloadurlDownload (final DownloadLink link , final String directlinkproperty ) throws Exception {
196+ final String url = link .getStringProperty (directlinkproperty );
197+ if (StringUtils .isEmpty (url )) {
198+ return false ;
199+ }
200+ try {
201+ final Browser brc = br .cloneBrowser ();
202+ dl = new jd .plugins .BrowserAdapter ().openDownload (brc , link , url , this .isResumeable (link , null ), this .getMaxChunks (link , null ));
203+ if (this .looksLikeDownloadableContent (dl .getConnection ())) {
204+ return true ;
205+ } else {
206+ brc .followConnection (true );
207+ throw new IOException ();
208+ }
209+ } catch (final Throwable e ) {
210+ logger .log (e );
211+ try {
212+ dl .getConnection ().disconnect ();
213+ } catch (Throwable ignore ) {
214+ }
215+ return false ;
216+ }
217+ }
218+
219+ @ Override
220+ public int getMaxSimultanFreeDownloadNum () {
221+ return Integer .MAX_VALUE ;
222+ }
223+ }
0 commit comments