aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/vtuber/ScheduleHandler.java
blob: d9212370a0136d83e4ed7f28349c7ba9afdfb8a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package vtuber;

import com.pina.Holodex;
import com.pina.HolodexException;
import com.pina.datatypes.Channel;
import com.pina.datatypes.SimpleVideo;
import com.pina.query.ChannelQueryBuilder;
import com.pina.query.VideoQueryBuilder;

import java.util.ArrayList;
import java.util.List;

public class ScheduleHandler {
    Holodex holodex;

    public ScheduleHandler(String apikey) {
        System.out.println("ScheduleHandler initialized");
        holodex = new Holodex(apikey);

    }

    public List<SimpleVideo> getSchedule(String org, int limit) {
        System.out.println("Getting schedule for " + org);
        List<SimpleVideo> upcomingAndLiveVideos = new ArrayList<>();
        try {
            List<SimpleVideo> upcomingVideos = holodex.getLiveAndUpcomingVideos(new VideoQueryBuilder().setOrg(org).setLimit(limit).setStatus("upcoming"));
            List<SimpleVideo> liveVideos = holodex.getLiveAndUpcomingVideos(new VideoQueryBuilder().setStatus("live").setOrg(org).setLimit(limit));
            upcomingAndLiveVideos.addAll(liveVideos);
            upcomingAndLiveVideos.addAll(upcomingVideos);
        } catch (HolodexException e) {
            System.out.println("Error getting schedule for " + org);
            System.out.println(e.getMessage());
        }
        return upcomingAndLiveVideos;
    }

    public List<SimpleVideo> getSchedule(String org) {
        System.out.println("Getting schedule for " + org);
        List<SimpleVideo> upcomingAndLiveVideos = new ArrayList<>();
        try {
            List<SimpleVideo> upcomingVideos = holodex.getLiveAndUpcomingVideos(new VideoQueryBuilder().setOrg(org).setStatus("upcoming"));
            List<SimpleVideo> liveVideos = holodex.getLiveAndUpcomingVideos(new VideoQueryBuilder().setStatus("live").setOrg(org));
            upcomingAndLiveVideos.addAll(liveVideos);
            upcomingAndLiveVideos.addAll(upcomingVideos);
        } catch (HolodexException e) {
            System.out.println("Error getting schedule for " + org);
            System.out.println(e.getMessage());
        }
        return upcomingAndLiveVideos;
    }

    public List<SimpleVideo> getScheduleChannelId(String channelId) {
        System.out.println("Getting schedule for " + channelId);
        List<SimpleVideo> upcomingAndLiveVideos = new ArrayList<>();
        try {
            List<SimpleVideo> upcomingVideos = holodex.getLiveAndUpcomingVideos(new VideoQueryBuilder().setChannelId(channelId).setStatus("upcoming"));
            List<SimpleVideo> liveVideos = holodex.getLiveAndUpcomingVideos(new VideoQueryBuilder().setStatus("live").setChannelId(channelId));
            upcomingAndLiveVideos.addAll(liveVideos);
            upcomingAndLiveVideos.addAll(upcomingVideos);
        } catch (HolodexException e) {
            System.out.println("Error getting schedule for " + channelId);
            System.out.println(e.getMessage());
        }
        return upcomingAndLiveVideos;

    }

    public boolean organizationExists(String org) {
        List<Channel> channels;
        try {
            channels = holodex.getChannels(new ChannelQueryBuilder().setOrg(org));
        } catch (HolodexException e) {
            System.out.println("Couldn't find organization with name " + org);
            return false;
        }
        return channels.size() > 0;
    }

    public boolean channelExists(String channelId) {
        Channel channel;
        try{
            channel = holodex.getChannel(channelId);
            if (channel.name == null) {
                throw new HolodexException("Searching channel successful but no results found");
            }
        } catch (HolodexException e) {
            System.out.println("Couldn't find channel with id " + channelId);
            return false;
        }
        return true;
    }

}

send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage