tobby48 4 years ago
parent
commit
43e3ac1835
16 changed files with 535 additions and 294 deletions
  1. 32
    0
      pom.xml
  2. 3
    7
      src/main/java/kr/co/swh/lecture/opensource/project/discode/music/LayoutBot.java
  3. 6
    6
      src/main/java/kr/co/swh/lecture/opensource/project/discode/music/LayoutListener.java
  4. 0
    52
      src/main/java/kr/co/swh/lecture/opensource/project/discode/music/gui/ConsolePanel.java
  5. 0
    72
      src/main/java/kr/co/swh/lecture/opensource/project/discode/music/gui/GUI.java
  6. 0
    157
      src/main/java/kr/co/swh/lecture/opensource/project/discode/music/gui/TextAreaOutputStream.java
  7. 205
    0
      src/main/java/kr/co/swh/lecture/opensource/project/youtube/AddFeaturedVideo.java
  8. 33
    0
      src/main/java/kr/co/swh/lecture/opensource/project/youtube/Main.java
  9. 87
    0
      src/main/java/kr/co/swh/lecture/opensource/project/youtube/Server_talker.java
  10. 163
    0
      src/main/java/kr/co/swh/lecture/opensource/project/youtube/Youtube.java
  11. 6
    0
      src/main/java/kr/co/swh/lecture/opensource/project/youtube/client_secrets.json
  12. BIN
      src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/basic.cpython-37.pyc
  13. BIN
      src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/error.cpython-37.pyc
  14. BIN
      src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/help.cpython-37.pyc
  15. BIN
      src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/music.cpython-37.pyc
  16. 0
    0
      src/main/python/kr/co/swh/lecture/opensource/project/discord/music/뮤직봇.log

+ 32
- 0
pom.xml View File

@@ -37,6 +37,12 @@
37 37
 		<jetty.version>9.4.8.v20171121</jetty.version>
38 38
 		<jersey.version>1.19.4</jersey.version>
39 39
 		
40
+		
41
+		
42
+		<project.youtube.version>v3-rev56-1.15.0-rc</project.youtube.version>
43
+   	 	<project.http.version>1.15.0-rc</project.http.version>
44
+    	<project.oauth.version>1.15.0-rc</project.oauth.version>
45
+		
40 46
 	</properties>
41 47
 
42 48
 	<!-- lombok -->
@@ -365,6 +371,32 @@
365 371
 		
366 372
 		</dependency>
367 373
 		
374
+		
375
+		<!-- YouTube Data V3 support -->
376
+	    <dependency>
377
+	      <groupId>com.google.apis</groupId>
378
+	      <artifactId>google-api-services-youtube</artifactId>
379
+	      <version>${project.youtube.version}</version>
380
+	    </dependency>
381
+	
382
+	    <dependency>
383
+	      <groupId>com.google.http-client</groupId>
384
+	      <artifactId>google-http-client-jackson2</artifactId>
385
+	      <version>${project.http.version}</version>
386
+	    </dependency>
387
+	
388
+	    <dependency>
389
+	      <groupId>com.google.oauth-client</groupId>
390
+	      <artifactId>google-oauth-client-jetty</artifactId>
391
+	      <version>${project.oauth.version}</version>
392
+	    </dependency>
393
+	
394
+	    <dependency>
395
+	        <groupId>com.google.collections</groupId>
396
+	        <artifactId>google-collections</artifactId>
397
+	        <version>1.0</version>
398
+	    </dependency>
399
+		
368 400
 	</dependencies>
369 401
 	
370 402
 	<build>

src/main/java/kr/co/swh/lecture/opensource/project/discode/music/MusicBot.java → src/main/java/kr/co/swh/lecture/opensource/project/discode/music/LayoutBot.java View File

@@ -2,28 +2,24 @@ package kr.co.swh.lecture.opensource.project.discode.music;
2 2
 
3 3
 import javax.security.auth.login.LoginException;
4 4
 
5
-import kr.co.swh.lecture.opensource.project.discode.music.gui.GUI;
6 5
 import net.dv8tion.jda.api.JDA;
7 6
 import net.dv8tion.jda.api.JDABuilder;
8 7
 
9 8
 
10
-public class MusicBot {
9
+public class LayoutBot {
11 10
 	
12 11
 	public void play() throws LoginException, InterruptedException {
13 12
 		// Note: It is important to register your ReadyListener before building
14 13
         JDA jda = JDABuilder.createDefault("NjYzMjgzODYxMTUyNTk1OTkz.XhGROw.Ps3JJIKlEXoE1eah_5OKHwViThY")
15
-            .addEventListeners(new MusicListener())
14
+            .addEventListeners(new LayoutListener())
16 15
             .build();
17 16
 
18 17
         // optionally block until JDA is ready
19 18
         jda.awaitReady();
20
-		GUI gui = new GUI(this);
21
-//        this.setGUI(gui);
22
-        gui.init();	
23 19
 	}
24 20
 	public static void main(String[] args) throws LoginException, InterruptedException {
25 21
 		// TODO Auto-generated method stub
26
-		MusicBot bot = new MusicBot();
22
+		LayoutBot bot = new LayoutBot();
27 23
 		bot.play();
28 24
 	}
29 25
 	

src/main/java/kr/co/swh/lecture/opensource/project/discode/music/MusicListener.java → src/main/java/kr/co/swh/lecture/opensource/project/discode/music/LayoutListener.java View File

@@ -9,7 +9,7 @@ import net.dv8tion.jda.api.entities.User;
9 9
 import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
10 10
 import net.dv8tion.jda.api.hooks.ListenerAdapter;
11 11
 
12
-public class MusicListener extends ListenerAdapter{
12
+public class LayoutListener extends ListenerAdapter{
13 13
 	
14 14
 	@Override
15 15
 	public void onMessageReceived(MessageReceivedEvent event) {
@@ -23,7 +23,7 @@ public class MusicListener extends ListenerAdapter{
23 23
 		String message = msg.getContentRaw();
24 24
 		System.out.println(message.substring(0, 3));
25 25
 		
26
-		String m="";
26
+		String m=message;
27 27
 		if(message.substring(0, 3).equals("!! ")) {
28 28
 			m = message.substring(3);
29 29
 		}
@@ -85,26 +85,26 @@ public class MusicListener extends ListenerAdapter{
85 85
 		    2. Arg: url as string (can be null)
86 86
 		    3. Arg: icon url as string (can be null)
87 87
 		 */
88
-		eb.setAuthor("name", null, "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
88
+//		eb.setAuthor("name", null, "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
89 89
 
90 90
 		/*
91 91
 		    Set footer:
92 92
 		    1. Arg: text as string
93 93
 		    2. icon url as string (can be null)
94 94
 		 */
95
-		eb.setFooter("Text", "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
95
+//		eb.setFooter("Text", "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
96 96
 
97 97
 		/*
98 98
 		    Set image:
99 99
 		    Arg: image url as string
100 100
 		 */
101
-		eb.setImage("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
101
+//		eb.setImage("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
102 102
 
103 103
 		/*
104 104
 		    Set thumbnail image:
105 105
 		    Arg: image url as string
106 106
 		 */
107
-		eb.setThumbnail("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
107
+//		eb.setThumbnail("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
108 108
 		event.getTextChannel().sendMessage(eb.build()).queue();
109 109
 		
110 110
 	}

+ 0
- 52
src/main/java/kr/co/swh/lecture/opensource/project/discode/music/gui/ConsolePanel.java View File

@@ -1,52 +0,0 @@
1
-package kr.co.swh.lecture.opensource.project.discode.music.gui; 
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.opensource.project.discode.music.gui 
6
- * ConsolePanel.java
7
- *
8
- * 설명 :
9
- * </pre>
10
- * 
11
- * @since : 2021. 5. 30.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-import java.awt.Dimension;
16
-import java.awt.GridLayout;
17
-import java.io.PrintStream;
18
-
19
-import javax.swing.JPanel;
20
-import javax.swing.JScrollPane;
21
-import javax.swing.JTextArea;
22
-
23
-/**
24
- *
25
- * @author John Grosh <john.a.grosh@gmail.com>
26
- */
27
-public class ConsolePanel extends JPanel {
28
-    
29
-    /**
30
-	 * 
31
-	 */
32
-	private static final long serialVersionUID = 1L;
33
-
34
-	public ConsolePanel()
35
-    {
36
-        super();
37
-        JTextArea text = new JTextArea();
38
-        text.setLineWrap(true);
39
-        text.setWrapStyleWord(true);
40
-        text.setEditable(false);
41
-        PrintStream con=new PrintStream(new TextAreaOutputStream(text));
42
-        System.setOut(con);
43
-        System.setErr(con);
44
-        
45
-        JScrollPane pane = new JScrollPane();
46
-        pane.setViewportView(text);
47
-        
48
-        super.setLayout(new GridLayout(1,1));
49
-        super.add(pane);
50
-        super.setPreferredSize(new Dimension(400,300));
51
-    }
52
-}

+ 0
- 72
src/main/java/kr/co/swh/lecture/opensource/project/discode/music/gui/GUI.java View File

@@ -1,72 +0,0 @@
1
-package kr.co.swh.lecture.opensource.project.discode.music.gui; 
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.opensource.project.discode.music.gui 
6
- * GUI.java
7
- *
8
- * 설명 :
9
- * </pre>
10
- * 
11
- * @since : 2021. 5. 30.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-import java.awt.event.WindowEvent;
16
-import java.awt.event.WindowListener;
17
-
18
-import javax.swing.JFrame;
19
-import javax.swing.JTabbedPane;
20
-import javax.swing.WindowConstants;
21
-
22
-import kr.co.swh.lecture.opensource.project.discode.music.MusicBot;
23
-
24
-
25
-/**
26
- *
27
- * @author John Grosh <john.a.grosh@gmail.com>
28
- */
29
-public class GUI extends JFrame 
30
-{
31
-    private final ConsolePanel console;
32
-    private final MusicBot bot;
33
-    
34
-    public GUI(MusicBot bot) 
35
-    {
36
-        super();
37
-        this.bot = bot;
38
-        console = new ConsolePanel();
39
-    }
40
-    
41
-    public void init()
42
-    {
43
-        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
44
-        setTitle("JMusicBot");
45
-        JTabbedPane tabs = new JTabbedPane();
46
-        tabs.add("Console", console);
47
-        getContentPane().add(tabs);
48
-        pack();
49
-        setLocationRelativeTo(null);
50
-        setVisible(true);
51
-        addWindowListener(new WindowListener() 
52
-        {
53
-            @Override public void windowOpened(WindowEvent e) { /* unused */ }
54
-            @Override public void windowClosing(WindowEvent e) 
55
-            {
56
-                try
57
-                {
58
-                    bot.shutdown();
59
-                }
60
-                catch(Exception ex)
61
-                {
62
-                    System.exit(0);
63
-                }
64
-            }
65
-            @Override public void windowClosed(WindowEvent e) { /* unused */ }
66
-            @Override public void windowIconified(WindowEvent e) { /* unused */ }
67
-            @Override public void windowDeiconified(WindowEvent e) { /* unused */ }
68
-            @Override public void windowActivated(WindowEvent e) { /* unused */ }
69
-            @Override public void windowDeactivated(WindowEvent e) { /* unused */ }
70
-        });
71
-    }
72
-}

+ 0
- 157
src/main/java/kr/co/swh/lecture/opensource/project/discode/music/gui/TextAreaOutputStream.java View File

@@ -1,157 +0,0 @@
1
-package kr.co.swh.lecture.opensource.project.discode.music.gui; 
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.opensource.project.discode.music.gui 
6
- * TextAreaOutputStream.java
7
- *
8
- * 설명 :
9
- * </pre>
10
- * 
11
- * @since : 2021. 5. 30.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-import java.awt.EventQueue;
16
-import java.io.OutputStream;
17
-import java.io.UnsupportedEncodingException;
18
-import java.util.ArrayList;
19
-import java.util.LinkedList;
20
-import java.util.List;
21
-
22
-import javax.swing.JTextArea;
23
-/**
24
- *
25
- * @author Lawrence Dol
26
- */
27
-public class TextAreaOutputStream extends OutputStream {
28
-
29
-// *************************************************************************************************
30
-// INSTANCE MEMBERS
31
-// *************************************************************************************************
32
-
33
-private byte[]                          oneByte;                                                    // array for write(int val);
34
-private Appender                        appender;                                                   // most recent action
35
-
36
-public TextAreaOutputStream(JTextArea txtara) {
37
-    this(txtara,1000);
38
-    }
39
-
40
-public TextAreaOutputStream(JTextArea txtara, int maxlin) {
41
-    if(maxlin<1) { throw new IllegalArgumentException("TextAreaOutputStream maximum lines must be positive (value="+maxlin+")"); }
42
-    oneByte=new byte[1];
43
-    appender=new Appender(txtara,maxlin);
44
-    }
45
-
46
-/** Clear the current console text area. */
47
-public synchronized void clear() {
48
-    if(appender!=null) { appender.clear(); }
49
-    }
50
-
51
-@Override
52
-public synchronized void close() {
53
-    appender=null;
54
-    }
55
-
56
-@Override
57
-public synchronized void flush() {
58
-    /* empty */
59
-    }
60
-
61
-@Override
62
-public synchronized void write(int val) {
63
-    oneByte[0]=(byte)val;
64
-    write(oneByte,0,1);
65
-    }
66
-
67
-@Override
68
-public synchronized void write(byte[] ba) {
69
-    write(ba,0,ba.length);
70
-    }
71
-
72
-@Override
73
-public synchronized void write(byte[] ba,int str,int len) {
74
-    if(appender!=null) { appender.append(bytesToString(ba,str,len)); }
75
-    }
76
-
77
-//@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_DEFAULT_ENCODING")
78
-static private String bytesToString(byte[] ba, int str, int len) {
79
-    try { 
80
-        return new String(ba,str,len,"UTF-8"); 
81
-    } catch(UnsupportedEncodingException thr) { 
82
-        return new String(ba,str,len); 
83
-    } // all JVMs are required to support UTF-8
84
-    }
85
-
86
-// *************************************************************************************************
87
-// STATIC MEMBERS
88
-// *************************************************************************************************
89
-
90
-    static class Appender
91
-    implements Runnable
92
-    {
93
-    static private final String         EOL1="\n";
94
-    static private final String         EOL2=System.getProperty("line.separator",EOL1);
95
-    
96
-    private final JTextArea             textArea;
97
-    private final int                   maxLines;                                                   // maximum lines allowed in text area
98
-    private final LinkedList<Integer>   lengths;                                                    // length of lines within text area
99
-    private final List<String>          values;                                                     // values waiting to be appended
100
-
101
-    private int                         curLength;                                                  // length of current line
102
-    private boolean                     clear;
103
-    private boolean                     queue;
104
-
105
-    Appender(JTextArea txtara, int maxlin) {
106
-        textArea =txtara;
107
-        maxLines =maxlin;
108
-        lengths  =new LinkedList<>();
109
-        values   =new ArrayList<>();
110
-
111
-        curLength=0;
112
-        clear    =false;
113
-        queue    =true;
114
-        }
115
-
116
-    private synchronized void append(String val) {
117
-        values.add(val);
118
-        if(queue) { 
119
-            queue=false; 
120
-            EventQueue.invokeLater(this); 
121
-        }
122
-        }
123
-
124
-    private synchronized void clear() {
125
-        clear=true;
126
-        curLength=0;
127
-        lengths.clear();
128
-        values.clear();
129
-        if(queue) { 
130
-            queue=false; 
131
-            EventQueue.invokeLater(this); 
132
-        }
133
-        }
134
-
135
-    // MUST BE THE ONLY METHOD THAT TOUCHES textArea!
136
-    @Override
137
-    public synchronized void run() {
138
-        if(clear) { textArea.setText(""); }
139
-        values.stream().map((val) -> {
140
-            curLength+=val.length();
141
-            return val;
142
-        }).map((val) -> {
143
-            if(val.endsWith(EOL1) || val.endsWith(EOL2)) {
144
-                if(lengths.size()>=maxLines) { textArea.replaceRange("",0,lengths.removeFirst()); }
145
-                lengths.addLast(curLength);
146
-                curLength=0;
147
-            }
148
-            return val;
149
-        }).forEach((val) -> {
150
-            textArea.append(val);
151
-        });
152
-        values.clear();
153
-        clear =false;
154
-        queue =true;
155
-        }
156
-    }
157
-} /* END PUBLIC CLASS */

+ 205
- 0
src/main/java/kr/co/swh/lecture/opensource/project/youtube/AddFeaturedVideo.java View File

@@ -0,0 +1,205 @@
1
+package kr.co.swh.lecture.opensource.project.youtube; 
2
+
3
+import org.apache.log4j.Logger;
4
+
5
+/**
6
+ * <pre>
7
+ * kr.co.swh.lecture.opensource.project.youtube 
8
+ * AddFeaturedVideo.java
9
+ *
10
+ * 설명 :
11
+ * </pre>
12
+ * 
13
+ * @since : 2021. 6. 6.
14
+ * @author : tobby48
15
+ * @version : v1.0
16
+ */
17
+import com.google.api.client.auth.oauth2.Credential;
18
+import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
19
+import com.google.api.client.extensions.java6.auth.oauth2.FileCredentialStore;
20
+import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
21
+import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
22
+import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
23
+import com.google.api.client.googleapis.json.GoogleJsonResponseException;
24
+import com.google.api.client.http.HttpTransport;
25
+import com.google.api.client.http.javanet.NetHttpTransport;
26
+import com.google.api.client.json.JsonFactory;
27
+import com.google.api.client.json.jackson2.JacksonFactory;
28
+import com.google.api.services.youtube.YouTube;
29
+import com.google.api.services.youtube.model.*;
30
+import com.google.common.collect.Lists;
31
+
32
+import java.io.File;
33
+import java.io.IOException;
34
+import java.math.BigInteger;
35
+import java.util.List;
36
+
37
+/**
38
+ * This program adds a featured video to a channel via the Invideo Programming API.
39
+ *
40
+ * @author Ikai Lan <ikai@google.com>
41
+ */
42
+public class AddFeaturedVideo {
43
+
44
+    /**
45
+     * Global instance of the HTTP transport.
46
+     */
47
+    private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
48
+
49
+    /**
50
+     * Global instance of the JSON factory.
51
+     */
52
+    private static final JsonFactory JSON_FACTORY = new JacksonFactory();
53
+
54
+    /**
55
+     * Global instance of Youtube object to make all API requests.
56
+     */
57
+    private static YouTube youtube;
58
+
59
+
60
+    /**
61
+     * Authorizes the installed application to access user's protected data.
62
+     *
63
+     * @param scopes list of scopes needed to run youtube upload.
64
+     */
65
+    private static Credential authorize(List<String> scopes) throws IOException {
66
+
67
+        // Load client secrets.
68
+        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
69
+                JSON_FACTORY, AddFeaturedVideo.class.getResourceAsStream("/client_secrets.json"));
70
+
71
+        // Checks that the defaults have been replaced (Default = "Enter X here").
72
+        if (clientSecrets.getDetails().getClientId().startsWith("Enter")
73
+                || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
74
+            System.out.println(
75
+                    "Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential"
76
+                            + "into youtube-cmdline-addfeaturedvideo-sample/src/main/resources/client_secrets.json");
77
+            System.exit(1);
78
+        }
79
+
80
+        // Set up file credential store.
81
+        FileCredentialStore credentialStore = new FileCredentialStore(
82
+                new File(System.getProperty("user.home"), ".credentials/youtube-api-addfeaturedvideo.json"),
83
+                JSON_FACTORY);
84
+
85
+        // Set up authorization code flow.
86
+        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
87
+                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialStore(credentialStore)
88
+                .build();
89
+
90
+        // Build the local server and bind it to port 8080
91
+        LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
92
+
93
+        // Authorize.
94
+        return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
95
+    }
96
+
97
+    /**
98
+     * This is a very simple code sample that looks up a user's channel, then features the most recently
99
+     * uploaded video in the bottom left hand corner of every single video in the channel.
100
+     *
101
+     * @param args command line args (not used).
102
+     */
103
+    public static void main(String[] args) {
104
+
105
+        // An OAuth 2 access scope that allows for full read/write access.
106
+        List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
107
+
108
+        try {
109
+            // Authorization.
110
+            Credential credential = authorize(scopes);
111
+
112
+            // YouTube object used to make all API requests.
113
+            youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(
114
+                    "youtube-cmdline-addfeaturedvideo-sample").build();
115
+
116
+            // Fetch the user's channel. We also fetch the uploads playlist so we can use this later
117
+            // to find the most recently uploaded video
118
+            ChannelListResponse channelListResponse = youtube.channels().list("id,contentDetails")
119
+                    .setMine(true)
120
+                    .setFields("items(contentDetails/relatedPlaylists/uploads,id)")
121
+                    .execute();
122
+
123
+            // This assumes the user has a channel already. If the user does not have a channel, this should
124
+            // throw a GoogleJsonResponseException explaining the issue
125
+            Channel myChannel = channelListResponse.getItems().get(0);
126
+            String channelId = myChannel.getId();
127
+            String uploadsPlaylistId = myChannel.getContentDetails().getRelatedPlaylists().getUploads();
128
+
129
+            // Fetch the most recently uploaded video
130
+            PlaylistItemListResponse playlistItemListResponse = youtube.playlistItems().list("snippet")
131
+                    .setPlaylistId(uploadsPlaylistId)
132
+                    .setFields("items/snippet")
133
+                    .execute();
134
+
135
+            String featuredVideoId;
136
+            if (playlistItemListResponse.getItems().isEmpty()) {
137
+                // There are no videos on the channel. Therefore, we cannot feature a video. Exit.
138
+                System.out.println("Channel contains no videos. Featuring a default video instead from the Google Developers channel.");
139
+                featuredVideoId = "w4eiUiauo2w";
140
+            } else {
141
+                // The latest video should be the first video in the playlist response
142
+                PlaylistItem featuredVideo = playlistItemListResponse.getItems().get(0);
143
+                featuredVideoId = featuredVideo.getSnippet()
144
+                        .getResourceId()
145
+                        .getVideoId();
146
+
147
+                System.out.println("Featuring video: " + featuredVideo.getSnippet().getTitle());
148
+            }
149
+
150
+            // Feature this video on the channel via the Invideo programming API
151
+            // This describes the position of the video. Valid positions are bottomLeft, bottomRight, topLeft and
152
+            // topRight
153
+            InvideoPosition invideoPosition = new InvideoPosition();
154
+            invideoPosition.setCornerPosition("bottomLeft");
155
+            invideoPosition.setType("corner");
156
+
157
+            // The allowed offsets are offsetFromEnd and offsetFromStart, with offsetMs being an offset in milliseconds
158
+            InvideoTiming invideoTiming = new InvideoTiming();
159
+            invideoTiming.setOffsetMs(BigInteger.valueOf(15000l));
160
+            invideoTiming.setType("offsetFromEnd");
161
+
162
+            // Represents the type of promotion. In this case, a video with a video ID
163
+            PromotedItemId promotedItemId = new PromotedItemId();
164
+            promotedItemId.setType("video");
165
+            promotedItemId.setVideoId(featuredVideoId);
166
+
167
+            // Construct the Invidideo promotion
168
+            InvideoPromotion invideoPromotion = new InvideoPromotion();
169
+            invideoPromotion.setPosition(invideoPosition);
170
+            invideoPromotion.setTiming(invideoTiming);
171
+            invideoPromotion.setItems(Lists.newArrayList(promotedItemId));
172
+
173
+            // Now let's add the invideo promotion to the channel
174
+            Channel channel = new Channel();
175
+            channel.setId(channelId);
176
+            channel.setInvideoPromotion(invideoPromotion);
177
+
178
+            // Make the API call
179
+            Channel updateChannelResponse = youtube.channels()
180
+                    .update("invideoPromotion", channel)
181
+                    .execute();
182
+
183
+            // Print out returned results.
184
+            System.out.println("\n================== Updated Channel Information ==================\n");
185
+            System.out.println("\t- Channel ID: " + updateChannelResponse.getId());
186
+
187
+            InvideoPromotion promotion = updateChannelResponse.getInvideoPromotion();
188
+            System.out.println("\t- Invideo promotion video ID: " + promotion.getItems()
189
+                    .get(0)
190
+                    .getVideoId());
191
+            System.out.println("\t- Promotion position: " + promotion.getPosition().getCornerPosition());
192
+            System.out.println("\t- Promotion timing: " + promotion.getTiming().getOffsetMs()
193
+                    + " Offset: " + promotion.getTiming().getType());
194
+        } catch (GoogleJsonResponseException e) {
195
+            System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : "
196
+                    + e.getDetails().getMessage());
197
+            e.printStackTrace();
198
+
199
+        } catch (IOException e) {
200
+            System.err.println("IOException: " + e.getMessage());
201
+            e.printStackTrace();
202
+        }
203
+    }
204
+
205
+}

+ 33
- 0
src/main/java/kr/co/swh/lecture/opensource/project/youtube/Main.java View File

@@ -0,0 +1,33 @@
1
+package kr.co.swh.lecture.opensource.project.youtube; 
2
+
3
+/**
4
+ * <pre>
5
+ * kr.co.swh.lecture.opensource.project.youtube 
6
+ * Main.java
7
+ *
8
+ * 설명 :
9
+ * </pre>
10
+ * 
11
+ * @since : 2021. 6. 6.
12
+ * @author : tobby48
13
+ * @version : v1.0
14
+ */
15
+
16
+import javax.security.auth.login.LoginException;
17
+
18
+import net.dv8tion.jda.api.JDA;
19
+import net.dv8tion.jda.api.JDABuilder;
20
+
21
+
22
+public class Main {
23
+	public static void main(String[] args) throws LoginException, InterruptedException {
24
+		JDA jda = JDABuilder.createDefault("NjYzMjgzODYxMTUyNTk1OTkz.XhGROw.Ps3JJIKlEXoE1eah_5OKHwViThY")
25
+	            .addEventListeners(new Server_talker())
26
+	            .build();
27
+
28
+	        // optionally block until JDA is ready
29
+	        jda.awaitReady();
30
+	}
31
+
32
+	
33
+}

+ 87
- 0
src/main/java/kr/co/swh/lecture/opensource/project/youtube/Server_talker.java View File

@@ -0,0 +1,87 @@
1
+package kr.co.swh.lecture.opensource.project.youtube; 
2
+
3
+import java.util.ArrayList;
4
+
5
+import net.dv8tion.jda.api.entities.Message;
6
+import net.dv8tion.jda.api.entities.MessageChannel;
7
+import net.dv8tion.jda.api.entities.TextChannel;
8
+import net.dv8tion.jda.api.entities.User;
9
+import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
10
+import net.dv8tion.jda.api.hooks.ListenerAdapter;
11
+
12
+public class Server_talker extends ListenerAdapter{
13
+	
14
+	
15
+	@Override
16
+    public void onMessageReceived(MessageReceivedEvent event) {
17
+		User user = event.getAuthor();
18
+		TextChannel tc = event.getTextChannel();
19
+		Message msg = event.getMessage();
20
+		String a = null;
21
+		
22
+		if(user.isBot()) return;
23
+		if(msg.getContentRaw().equalsIgnoreCase("hello"))
24
+		tc.sendMessage("hello, "+ user.getAsMention()).queue();
25
+//		System.out.println(msg.getContentRaw().substring(0,3));
26
+		//;
27
+		if (msg.getContentRaw().equals("이봐 징징이 거기 동전좀 주워주겠나?"))
28
+        {
29
+            MessageChannel channel = event.getChannel();
30
+            long time = System.currentTimeMillis();
31
+            channel.sendMessage("d민믜ㅏㅇ아라아") /* => RestAction<Message> */
32
+                   .queue(response /* => Message */ -> {
33
+                       response.editMessageFormat("싫어요 사장님 사장님이 주우세요: %d ms", System.currentTimeMillis() - time).queue();
34
+                   });
35
+        }
36
+		if (msg.getContentRaw().equals("자네 해고 되고 싶나?"))
37
+        {
38
+            MessageChannel channel = event.getChannel();
39
+            long time = System.currentTimeMillis();
40
+            channel.sendMessage("홀롤롤로") /* => RestAction<Message> */
41
+                   .queue(response /* => Message */ -> {
42
+                       response.editMessageFormat("알겠어요 주울께요: %d ms", System.currentTimeMillis() - time).queue();
43
+                   });
44
+        }
45
+		if (msg.getContentRaw().equals("이때를 노렸어!"))
46
+        {
47
+            MessageChannel channel = event.getChannel();
48
+            long time = System.currentTimeMillis();
49
+            channel.sendMessage("암") /* => RestAction<Message> */
50
+                   .queue(response /* => Message */ -> {
51
+                       response.editMessageFormat("사장님 지금 뭐하시는거에요?: %d ms", System.currentTimeMillis() - time).queue();
52
+                   });
53
+        }
54
+		if (msg.getContentRaw().equals("어이 리사"))
55
+        {
56
+            MessageChannel channel = event.getChannel();
57
+            long time = System.currentTimeMillis();
58
+            channel.sendMessage("홀롤롤로") /* => RestAction<Message> */
59
+                   .queue(response /* => Message */ -> {
60
+                       response.editMessageFormat("그래 "+ user.getAsMention(), System.currentTimeMillis() - time).queue();
61
+                   });
62
+        }
63
+		if (msg.getContentRaw().substring(0,3).equals("%p ")){
64
+			
65
+			String m = msg.getContentRaw().substring(3);
66
+			Youtube y = new Youtube();
67
+			ArrayList<String> arr = y.audio(m);
68
+			
69
+			
70
+			
71
+            MessageChannel channel = event.getChannel();
72
+            long time = System.currentTimeMillis();
73
+            
74
+            for(String s : arr) {
75
+            	channel.sendMessage("홀롤롤로") /* => RestAction<Message> */
76
+            	.queue(response /* => Message */ -> {
77
+
78
+            		response.editMessage(s).queue();
79
+
80
+            	});
81
+            }
82
+            
83
+            
84
+		}
85
+    
86
+	}
87
+}

+ 163
- 0
src/main/java/kr/co/swh/lecture/opensource/project/youtube/Youtube.java View File

@@ -0,0 +1,163 @@
1
+package kr.co.swh.lecture.opensource.project.youtube; 
2
+
3
+/**
4
+ * <pre>
5
+ * kr.co.swh.lecture.opensource.project.youtube 
6
+ * Youtube.java
7
+ *
8
+ * 설명 :
9
+ * </pre>
10
+ * 
11
+ * @since : 2021. 6. 6.
12
+ * @author : tobby48
13
+ * @version : v1.0
14
+ */
15
+import java.io.BufferedReader;
16
+import java.io.IOException;
17
+import java.io.InputStreamReader;
18
+import java.net.HttpURLConnection;
19
+import java.net.URL;
20
+import java.net.URLEncoder;
21
+import java.util.ArrayList;
22
+import java.util.HashMap;
23
+import java.util.List;
24
+import java.util.Map;
25
+import java.util.Scanner;
26
+
27
+import com.google.gson.Gson;
28
+
29
+
30
+
31
+
32
+public class Youtube {
33
+	public String search(String search) throws IOException {
34
+		
35
+		String apiurl = "https://www.googleapis.com/youtube/v3/search";
36
+		apiurl += "?key=AIzaSyAI9M3FgT9emj5omLmbvm8rRDVLQvMMgE8";
37
+		apiurl += "&part=snippet&type=video&maxResults=20&videoEmbeddable=true";
38
+		apiurl += "&q="+URLEncoder.encode(search,"UTF-8");
39
+		
40
+		URL url = new URL(apiurl);
41
+		HttpURLConnection con = (HttpURLConnection) url.openConnection();
42
+		con.setRequestMethod("GET");
43
+		
44
+		BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
45
+		String inputLine;
46
+		StringBuffer response = new StringBuffer();
47
+		while((inputLine = br.readLine()) != null) {
48
+			response.append(inputLine);
49
+		}
50
+		br.close();
51
+		
52
+		return response.toString();
53
+	}
54
+	
55
+	public ArrayList<String> audio(String audio) {
56
+		
57
+		Gson gsonObj = new Gson();
58
+		Map<String, String> inputMap = new HashMap<String, String>();
59
+		inputMap.put("name", "makesomething");
60
+		inputMap.put("blog", "https://web-inf.tistory.com");
61
+		
62
+		Youtube y = new Youtube();
63
+		ArrayList<String> alist = new ArrayList<String>();
64
+		try {
65
+			String s = y.search(""+ audio +"");
66
+			Map map = gsonObj.fromJson(s, Map.class);	
67
+
68
+
69
+			//			List list = gsonObj.fromJson(map.get("items"), List.class);	
70
+			List list = (List)map.get("items");
71
+
72
+			//			Map map1 = gsonObj.fromJson(list.get(0).toString(), Map.class);
73
+			for(int a = 0; a < list.size(); a++) {
74
+
75
+				Map id = (Map)list.get(a);
76
+				Map videoId = (Map)id.get("id");
77
+				//System.out.println(videoId.get("videoId"));
78
+
79
+				Map snippet = (Map)list.get(a);
80
+				Map title = (Map)id.get("snippet");
81
+				//System.out.println(title.get("title"));
82
+				String popo;
83
+				HashMap<String,String> disc = new HashMap<String,String>();
84
+				//disc.put("number",String.valueOf(a+1));
85
+				//disc.put("title",(String) title.get("title")); //값 추가
86
+				disc.put("address","https://www.youtube.com/watch?v="+((String) videoId.get("videoId")));
87
+				System.out.println(disc);
88
+				popo = "https://www.youtube.com/watch?v="+((String) videoId.get("videoId"));
89
+				
90
+				alist.add(popo);	
91
+					if(a > 10)   
92
+					{
93
+						break;
94
+					}
95
+					else if(alist.toString().length() > 2000) 
96
+					{
97
+						alist.remove(a);
98
+						break;
99
+					}
100
+				}
101
+
102
+			//			System.out.println(map.get("items"));
103
+
104
+			//			System.out.println(s);
105
+
106
+
107
+		} catch (IOException e) {
108
+			// TODO Auto-generated catch block
109
+			e.printStackTrace();
110
+		}
111
+		return alist;
112
+	}
113
+	public static void main(String[] args) {
114
+		String name;
115
+		Gson gsonObj = new Gson();
116
+		Map<String, String> inputMap = new HashMap<String, String>();
117
+		inputMap.put("name", "makesomething");
118
+		inputMap.put("blog", "https://web-inf.tistory.com");
119
+		Scanner sc = new Scanner(System.in);
120
+		name = sc.next();
121
+		Youtube y = new Youtube();
122
+		
123
+		try {
124
+			String s = y.search(""+ name +"");
125
+			Map map = gsonObj.fromJson(s, Map.class);	
126
+
127
+
128
+			//			List list = gsonObj.fromJson(map.get("items"), List.class);	
129
+			List list = (List)map.get("items");
130
+
131
+			//			Map map1 = gsonObj.fromJson(list.get(0).toString(), Map.class);
132
+			for(int a = 0; a<15; a++) {
133
+
134
+				Map id = (Map)list.get(a);
135
+				Map videoId = (Map)id.get("id");
136
+				//System.out.println(videoId.get("videoId"));
137
+
138
+				Map snippet = (Map)list.get(a);
139
+				Map title = (Map)id.get("snippet");
140
+				//System.out.println(title.get("title"));
141
+
142
+				HashMap<String,String> disc = new HashMap<String,String>();
143
+				disc.put("number",String.valueOf(a+1));
144
+				disc.put("title",(String) title.get("title")); //값 추가
145
+				disc.put("address","https://www.youtube.com/watch?v="+((String) videoId.get("videoId")));
146
+				System.out.println(disc);
147
+
148
+
149
+			}
150
+
151
+			//			System.out.println(map.get("items"));
152
+
153
+			//			System.out.println(s);
154
+
155
+
156
+		} catch (IOException e) {
157
+			// TODO Auto-generated catch block
158
+			e.printStackTrace();
159
+		}
160
+		
161
+		
162
+	}
163
+}

+ 6
- 0
src/main/java/kr/co/swh/lecture/opensource/project/youtube/client_secrets.json View File

@@ -0,0 +1,6 @@
1
+{
2
+  "installed": {
3
+    "client_id": "Enter Client ID",
4
+    "client_secret": "Enter Client Secret"
5
+  }
6
+}

BIN
src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/basic.cpython-37.pyc View File


BIN
src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/error.cpython-37.pyc View File


BIN
src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/help.cpython-37.pyc View File


BIN
src/main/python/kr/co/swh/lecture/opensource/project/discord/music/cogs/__pycache__/music.cpython-37.pyc View File


+ 0
- 0
src/main/python/kr/co/swh/lecture/opensource/project/discord/music/뮤직봇.log View File