Skip to content

Commit 7bb87ff

Browse files
author
updating-bot
committed
mirroring bot - 2024/10/24
1 parent 197ec4c commit 7bb87ff

34 files changed

+936
-626
lines changed

svn_trunk/src/jd/controlling/AccountController.java

Lines changed: 178 additions & 165 deletions
Large diffs are not rendered by default.

svn_trunk/src/jd/controlling/downloadcontroller/AccountCache.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.List;
77
import java.util.concurrent.atomic.AtomicReference;
88

9-
import org.appwork.utils.DebugMode;
109
import org.appwork.utils.StringUtils;
1110
import org.jdownloader.DomainInfo;
1211
import org.jdownloader.controlling.hosterrule.AccountGroup.Rules;
@@ -16,8 +15,6 @@
1615
import jd.plugins.Account;
1716
import jd.plugins.AccountInfo;
1817
import jd.plugins.DownloadLink;
19-
import jd.plugins.MultiHostHost;
20-
import jd.plugins.MultiHostHost.MultihosterHostStatus;
2118
import jd.plugins.PluginForHost;
2219

2320
public class AccountCache implements Iterable<CachedAccount> {
@@ -98,51 +95,6 @@ public boolean canHandle(DownloadLink link) throws Exception {
9895
/* Host is not supported (anymore) */
9996
return false;
10097
}
101-
/* Verify again because plugins can modify list on runtime */
102-
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
103-
/* Check for domain specific limits of multihost items. */
104-
final MultiHostHost hostinfo = ai.getMultihostSupportedHost(link.getHost());
105-
if (hostinfo == null) {
106-
/* Host is not supported (anymore) */
107-
return false;
108-
}
109-
final MultihosterHostStatus status = hostinfo.getStatus();
110-
if (status != MultihosterHostStatus.WORKING && status != MultihosterHostStatus.WORKING_UNSTABLE) {
111-
/* Download of that host is currently not possible. */
112-
return false;
113-
} else if (!hostinfo.isUnlimitedLinks() && hostinfo.getLinksLeft() <= 0) {
114-
/* Max limits link is reached -> Cannot download */
115-
return false;
116-
}
117-
// TODO: Refactor this
118-
if (!hostinfo.isUnlimitedTraffic()) {
119-
/* Traffic limit exists -> Check if enough traffic is left. */
120-
if (hostinfo.getTrafficLeft() <= 0) {
121-
/* No traffic left at all. */
122-
return false;
123-
}
124-
if (link.isSizeSet()) {
125-
/* File size is known so we can check if we have enough traffic left to download that link. */
126-
final long trafficCalcFactor = hostinfo.getTrafficCalculationFactorPercent();
127-
final long downloadSize = link.getView().getBytesTotalEstimated();
128-
final long minimum = 1024;
129-
final long downloadLeft;
130-
if (downloadSize >= 0) {
131-
downloadLeft = Math.max(minimum, downloadSize - link.getView().getBytesLoaded());
132-
} else {
133-
downloadLeft = minimum;
134-
}
135-
final long neededTraffic = (downloadLeft * trafficCalcFactor) / 100;
136-
if (!ai.isUnlimitedTraffic() && neededTraffic > ai.getTrafficLeft()) {
137-
/* Not enough account traffic */
138-
return false;
139-
} else if (neededTraffic > hostinfo.getTrafficLeft()) {
140-
/* Not enough individual file host traffic */
141-
return false;
142-
}
143-
}
144-
}
145-
}
14698
}
14799
return true;
148100
}

svn_trunk/src/jd/plugins/Account.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
import java.util.concurrent.CopyOnWriteArrayList;
2525
import java.util.concurrent.atomic.AtomicBoolean;
2626

27-
import jd.config.Property;
28-
import jd.controlling.AccountController;
29-
import jd.http.Browser;
30-
import jd.http.Cookie;
31-
import jd.http.Cookies;
32-
3327
import org.appwork.storage.JSonStorage;
3428
import org.appwork.storage.SimpleMapper;
3529
import org.appwork.storage.TypeRef;
@@ -43,6 +37,12 @@
4337
import org.jdownloader.settings.staticreferences.CFG_GENERAL;
4438
import org.jdownloader.translate._JDT;
4539

40+
import jd.config.Property;
41+
import jd.controlling.AccountController;
42+
import jd.http.Browser;
43+
import jd.http.Cookie;
44+
import jd.http.Cookies;
45+
4646
public class Account extends Property {
4747
private static final String VALID_UNTIL = "VALID_UNTIL";
4848
private static final String ACCOUNT_TYPE = "ACCOUNT_TYPE";
@@ -220,12 +220,10 @@ public Cookies loadUserCookies(final boolean loadUserAgent) {
220220
}
221221

222222
/**
223-
* @since JD2
224-
*
225-
* true = Multiple accounts of this host can be used at the same time <br/>
226-
* false = Multiple accounts of this host can NOT be used at the same time. <br/>
227-
* For most hosts, this should be set to false for free accounts as the traffic limit of those sits on current IP + account which
228-
* means that if a traffic-limit of one free account is reached, all accounts will be out of traffic!
223+
* true = Multiple accounts of this host can be used at the same time <br/>
224+
* false = Multiple accounts of this host can NOT be used at the same time. <br/>
225+
* For most hosts, this should be set to false for free accounts as the traffic limit of those sits on current IP + account which means
226+
* that if a traffic-limit of one free account is reached, all accounts will be out of traffic!
229227
*/
230228
public void setConcurrentUsePossible(boolean concurrentUsePossible) {
231229
this.concurrentUsePossible = concurrentUsePossible;
@@ -268,7 +266,7 @@ public PluginForHost getPlugin() {
268266
return plugin;
269267
}
270268

271-
public void setPlugin(PluginForHost plugin) {
269+
public void setPlugin(final PluginForHost plugin) {
272270
this.plugin = plugin;
273271
if (plugin != null) {
274272
isMultiPlugin = plugin.isHandlingMultipleHosts();
@@ -282,9 +280,9 @@ public boolean isMultiPlugin() {
282280
}
283281

284282
/**
285-
* Set this to true to indicate that changing the IP address will also reset this accounts' limits. </br> Most of all services will
286-
* store the limits on account (+ IP) but some will only rely on the IP thus allowing users to reset account limits by changing their
287-
* IP.
283+
* Set this to true to indicate that changing the IP address will also reset this accounts' limits. </br>
284+
* Most of all services will store the limits on account (+ IP) but some will only rely on the IP thus allowing users to reset account
285+
* limits by changing their IP.
288286
*/
289287
public void setAllowReconnectToResetLimits(final boolean b) {
290288
/* 2022-07-19: TODO: Dummy function, see: https://svn.jdownloader.org/issues/87351 */
@@ -658,17 +656,31 @@ public void setEnabled(final boolean enabled, final boolean forceAccountCheckOnC
658656
}
659657
}
660658

659+
private static final long DEFAULT_REFRESH_TIMEOUT = 30 * 60 * 1000l;
660+
private static final long MIN_REFRESH_TIMEOUT = 5 * 60 * 1000l;
661+
661662
/** In which interval (milliseconds) will this account get checked? Min. = 5 minutes, default = 30 minutes. */
662663
public long getRefreshTimeout() {
663-
/* default refresh timeout is 30 mins */
664-
long defaultRefreshTimeout = 30 * 60 * 1000l;
665-
/* TODO: Also maybe check if e.g. timeout > time until account expires. */
666-
final long minRefreshTimeout = 5 * 60 * 1000l;
667-
Long timeout = this.getLongProperty(PROPERTY_REFRESH_TIMEOUT, defaultRefreshTimeout);
664+
Long timeout = this.getLongProperty(PROPERTY_REFRESH_TIMEOUT, DEFAULT_REFRESH_TIMEOUT);
668665
if (timeout == null || timeout <= 0) {
669-
timeout = defaultRefreshTimeout;
670-
} else if (timeout < minRefreshTimeout) {
671-
timeout = minRefreshTimeout;
666+
timeout = DEFAULT_REFRESH_TIMEOUT;
667+
} else if (timeout < MIN_REFRESH_TIMEOUT) {
668+
timeout = MIN_REFRESH_TIMEOUT;
669+
}
670+
final AccountInfo ai = this.getAccountInfo();
671+
if (ai != null) {
672+
/*
673+
* Check if account is is about to expire. If that happens earlier than our next planned check, return time until account
674+
* expires.
675+
*/
676+
final long validUntil = ai.getValidUntil();
677+
if (validUntil == -1) {
678+
return timeout;
679+
}
680+
final long timeValid = validUntil - System.currentTimeMillis();
681+
if (timeValid > 0 && timeValid < timeout) {
682+
return timeValid;
683+
}
672684
}
673685
return timeout;
674686
}
@@ -680,6 +692,7 @@ public void setRefreshTimeout(long refresh_timeout) {
680692

681693
public boolean refreshTimeoutReached() {
682694
if (updatetime <= 0) {
695+
/* Account has never been checked so far. */
683696
return true;
684697
}
685698
return System.currentTimeMillis() - updatetime >= getRefreshTimeout();

svn_trunk/src/jd/plugins/AccountInfo.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public boolean isTrafficRefill() {
6868
return account_trafficRefill;
6969
}
7070

71+
/**
72+
* Set this to true if we expect this account to automatically get fresh traffic every X time (typically every day). </br>
73+
* Set this to false if no auto refill is expected e.g. account contains static amount of bought traffic so once used up, the account
74+
* stays empty.
75+
*/
7176
public void setTrafficRefill(boolean account_trafficRefill) {
7277
this.account_trafficRefill = account_trafficRefill;
7378
}
@@ -499,9 +504,9 @@ public List<String> setMultiHostSupportV2(final PluginForHost multiHostPlugin, f
499504
plugins.add(hit);
500505
}
501506
}
502-
final List<String> finalresults = new ArrayList<String>();
507+
final List<String> finalresults_old = new ArrayList<String>();
503508
/* TODO: Return this once refactoring is done. */
504-
final List<MultiHostHost> finalresults2 = new ArrayList<MultiHostHost>();
509+
final List<MultiHostHost> finalresults_new = new ArrayList<MultiHostHost>();
505510
final HashSet<String> unassignedMultiHostSupport = new HashSet<String>();
506511
cleanListLoop: for (final Entry<String, MultiHostHost> entry : cleanList.entrySet()) {
507512
final String maindomainCleaned = entry.getKey();
@@ -510,14 +515,14 @@ public List<String> setMultiHostSupportV2(final PluginForHost multiHostPlugin, f
510515
if (plugins == null) {
511516
mhost.setStatus(MultihosterHostStatus.DEACTIVATED_JDOWNLOADER_UNSUPPORTED);
512517
unassignedMultiHostSupport.add(maindomainCleaned);
513-
finalresults2.add(mhost);
518+
finalresults_new.add(mhost);
514519
continue cleanListLoop;
515520
}
516521
/* Remove dupes based on the results we already have */
517522
final Iterator<LazyHostPlugin> iterator = plugins.iterator();
518523
do {
519524
final LazyHostPlugin plugin = iterator.next();
520-
if (finalresults.contains(plugin.getHost())) {
525+
if (finalresults_old.contains(plugin.getHost())) {
521526
plugins.remove(plugin);
522527
}
523528
} while (iterator.hasNext());
@@ -576,22 +581,22 @@ public List<String> setMultiHostSupportV2(final PluginForHost multiHostPlugin, f
576581
if (printNonWorkingHosts && !hostIsWorkingAccordingToMultihost) {
577582
logger.info("Non working host: " + mhost);
578583
}
579-
if (!DebugMode.TRUE_IN_IDE_ELSE_FALSE && !hostIsWorkingAccordingToMultihost) {
580-
// TODO: Remove this check
581-
logger.info("Skipping non working host in stable: " + mhost.getName());
582-
continue cleanListLoop;
583-
}
584584
final String pluginHost = finalplugin.getHost();
585585
if (multiHostPlugin != null && pluginHost.equals(multiHostPlugin.getHost())) {
586586
/*
587-
* Some mmultihosts put their own domain in the list of supported hosts. However, this is nowhere needed so let's not add it
587+
* Some multihosts put their own domain in the list of supported hosts. However, this is nowhere needed so let's not add it
588588
* to the final list.
589589
*/
590590
continue cleanListLoop;
591-
} else if (finalresults.contains(pluginHost)) {
591+
} else if (finalresults_old.contains(pluginHost)) {
592592
continue cleanListLoop;
593593
}
594-
finalresults.add(pluginHost);
594+
if (!DebugMode.TRUE_IN_IDE_ELSE_FALSE && !hostIsWorkingAccordingToMultihost) {
595+
// TODO: Remove this check
596+
logger.info("Skipping non working host in stable: " + mhost.getName());
597+
} else {
598+
finalresults_old.add(pluginHost);
599+
}
595600
final String[] siteSupportedNames = finalplugin.getSitesSupported();
596601
if (siteSupportedNames != null && siteSupportedNames.length > 0) {
597602
/* Add all domains we know to list of supported domains. */
@@ -603,7 +608,7 @@ public List<String> setMultiHostSupportV2(final PluginForHost multiHostPlugin, f
603608
/* Set plugin domain as first domain */
604609
mhost.getDomains().remove(pluginHost);
605610
mhost.getDomains().add(0, pluginHost);
606-
finalresults2.add(mhost);
611+
finalresults_new.add(mhost);
607612
}
608613
/**
609614
* Remove all "double" entries from remaining list of unmatched entries to avoid wrong log output. </br>
@@ -647,7 +652,7 @@ public List<String> setMultiHostSupportV2(final PluginForHost multiHostPlugin, f
647652
}
648653
}
649654
}
650-
if (finalresults.isEmpty()) {
655+
if (finalresults_old.isEmpty()) {
651656
if (logger != null) {
652657
logger.info("Failed to find ANY usable results");
653658
}
@@ -657,24 +662,24 @@ public List<String> setMultiHostSupportV2(final PluginForHost multiHostPlugin, f
657662
/* Log final results if wanted. */
658663
final boolean logValidResults = false;
659664
if (logger != null && logValidResults) {
660-
logger.info("Found real hosts: " + finalresults.size());
661-
for (final String host : finalresults) {
665+
logger.info("Found real hosts: " + finalresults_old.size());
666+
for (final String host : finalresults_old) {
662667
logger.finest("Found host: " + host);
663668
}
664669
}
665670
/* sorting will now work properly since they are all pre-corrected to lowercase. */
666-
Collections.sort(finalresults, new NaturalOrderComparator());
667-
this.setProperty(PROPERTY_MULTIHOST_SUPPORT, new CopyOnWriteArrayList<String>(finalresults));
671+
Collections.sort(finalresults_old, new NaturalOrderComparator());
672+
this.setProperty(PROPERTY_MULTIHOST_SUPPORT, new CopyOnWriteArrayList<String>(finalresults_old));
668673
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
669-
Collections.sort(finalresults2, new Comparator<MultiHostHost>() {
674+
Collections.sort(finalresults_new, new Comparator<MultiHostHost>() {
670675
@Override
671676
public int compare(MultiHostHost o1, MultiHostHost o2) {
672677
return o1.getDomain().compareToIgnoreCase(o2.getDomain());
673678
}
674679
});
675-
multihostSupportV2 = new CopyOnWriteArrayList<MultiHostHost>(finalresults2);
680+
multihostSupportV2 = new CopyOnWriteArrayList<MultiHostHost>(finalresults_new);
676681
}
677-
return finalresults;
682+
return finalresults_old;
678683
}
679684

680685
protected List<MultiHostHost> multihostSupportV2 = null;

0 commit comments

Comments
 (0)