2020-11-12 21:19:45 +00:00
|
|
|
package me.kavin.piped;
|
|
|
|
|
2021-07-16 22:40:46 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import org.hibernate.Session;
|
|
|
|
import org.hibernate.Transaction;
|
|
|
|
import org.hibernate.query.Query;
|
2020-11-12 21:19:45 +00:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.localization.Localization;
|
|
|
|
|
2021-03-29 13:59:10 +00:00
|
|
|
import io.activej.inject.Injector;
|
2021-07-16 22:40:46 +00:00
|
|
|
import me.kavin.piped.utils.DatabaseSessionFactory;
|
2020-11-12 21:19:45 +00:00
|
|
|
import me.kavin.piped.utils.DownloaderImpl;
|
2021-07-16 22:40:46 +00:00
|
|
|
import me.kavin.piped.utils.Multithreading;
|
|
|
|
import me.kavin.piped.utils.ResponseHelper;
|
2021-08-20 20:22:39 +00:00
|
|
|
import me.kavin.piped.utils.obj.db.PubSub;
|
2020-11-12 21:19:45 +00:00
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
2021-02-24 09:52:29 +00:00
|
|
|
NewPipe.init(new DownloaderImpl(), new Localization("en", "US"));
|
2020-11-12 21:19:45 +00:00
|
|
|
|
2021-03-29 13:59:10 +00:00
|
|
|
Injector.useSpecializer();
|
2021-02-24 09:52:29 +00:00
|
|
|
|
2021-07-16 22:40:46 +00:00
|
|
|
new Timer().scheduleAtFixedRate(new TimerTask() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Session s = DatabaseSessionFactory.createSession();
|
|
|
|
|
2021-08-20 20:22:39 +00:00
|
|
|
List<PubSub> pubSubList = s.createNativeQuery(
|
2021-11-18 23:32:19 +00:00
|
|
|
"select distinct pubsub.* from pubsub inner join users_subscribed on pubsub.id = users_subscribed.channel where pubsub.subbed_at < :time",
|
|
|
|
PubSub.class).setParameter("time", System.currentTimeMillis() - TimeUnit.DAYS.toMillis(4))
|
|
|
|
.getResultList();
|
2021-07-16 22:40:46 +00:00
|
|
|
|
2021-08-20 20:22:39 +00:00
|
|
|
Collections.shuffle(pubSubList);
|
2021-07-16 22:40:46 +00:00
|
|
|
|
2021-08-20 20:22:39 +00:00
|
|
|
for (PubSub pubsub : pubSubList)
|
|
|
|
if (pubsub != null)
|
2021-07-20 21:27:28 +00:00
|
|
|
Multithreading.runAsyncLimitedPubSub(() -> {
|
|
|
|
Session sess = DatabaseSessionFactory.createSession();
|
|
|
|
try {
|
2021-08-20 20:22:39 +00:00
|
|
|
ResponseHelper.subscribePubSub(pubsub.getId(), sess);
|
2021-07-21 12:37:43 +00:00
|
|
|
} catch (Exception e) {
|
2021-07-20 21:27:28 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
sess.close();
|
|
|
|
});
|
2021-07-16 22:40:46 +00:00
|
|
|
|
|
|
|
s.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0, TimeUnit.MINUTES.toMillis(90));
|
|
|
|
|
|
|
|
new Timer().scheduleAtFixedRate(new TimerTask() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Session s = DatabaseSessionFactory.createSession();
|
|
|
|
|
|
|
|
Transaction tr = s.getTransaction();
|
|
|
|
|
|
|
|
tr.begin();
|
|
|
|
|
|
|
|
Query<?> query = s.createQuery("delete from Video where uploaded < :time").setParameter("time",
|
|
|
|
System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10));
|
|
|
|
|
|
|
|
System.out.println(String.format("Cleanup: Removed %o old videos", query.executeUpdate()));
|
|
|
|
|
|
|
|
tr.commit();
|
|
|
|
|
|
|
|
s.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0, TimeUnit.MINUTES.toMillis(60));
|
|
|
|
|
2021-03-29 13:59:10 +00:00
|
|
|
new ServerLauncher().launch(args);
|
2021-02-05 18:28:02 +00:00
|
|
|
|
2021-02-24 10:26:26 +00:00
|
|
|
}
|
2020-11-12 21:19:45 +00:00
|
|
|
}
|