22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/docs/package-search-index.js:
--------------------------------------------------------------------------------
1 | packageSearchIndex = [{"l":"com.khjxiaogu.MiraiSongPlugin.cardprovider"},{"l":"com.khjxiaogu.MiraiSongPlugin.musicsource"},{"l":"com.khjxiaogu.MiraiSongPlugin.test"},{"l":"所有程序包","url":"allpackages-index.html"}]
--------------------------------------------------------------------------------
/docs/package-search-index.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khjxiaogu/MiraiSongPlugin/79711fcc1ae79fe51aa1d209c40e879f82f67366/docs/package-search-index.zip
--------------------------------------------------------------------------------
/docs/resources/glass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khjxiaogu/MiraiSongPlugin/79711fcc1ae79fe51aa1d209c40e879f82f67366/docs/resources/glass.png
--------------------------------------------------------------------------------
/docs/resources/x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khjxiaogu/MiraiSongPlugin/79711fcc1ae79fe51aa1d209c40e879f82f67366/docs/resources/x.png
--------------------------------------------------------------------------------
/docs/type-search-index.js:
--------------------------------------------------------------------------------
1 | typeSearchIndex = [{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"AmrVoiceProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin.musicsource","l":"BaiduMusicSource"},{"p":"com.khjxiaogu.MiraiSongPlugin.musicsource","l":"KugouMusicSource"},{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"LightAppCardProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"LightAppXCardProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin.test","l":"Main"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"MiraiSongPlugin"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"MusicCardProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"MusicInfo"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"MusicSource"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"NetEaseCrypto"},{"p":"com.khjxiaogu.MiraiSongPlugin.musicsource","l":"NetEaseMusicSource"},{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"PlainMusicInfoProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"PluginData"},{"p":"com.khjxiaogu.MiraiSongPlugin.musicsource","l":"QQMusicHQSource"},{"p":"com.khjxiaogu.MiraiSongPlugin.musicsource","l":"QQMusicSource"},{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"ShareCardProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"SilkVoiceProvider"},{"p":"com.khjxiaogu.MiraiSongPlugin","l":"Utils"},{"p":"com.khjxiaogu.MiraiSongPlugin.cardprovider","l":"XMLCardProvider"},{"l":"所有类","url":"allclasses-index.html"}]
--------------------------------------------------------------------------------
/docs/type-search-index.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khjxiaogu/MiraiSongPlugin/79711fcc1ae79fe51aa1d209c40e879f82f67366/docs/type-search-index.zip
--------------------------------------------------------------------------------
/ffmpeg/.gitignore:
--------------------------------------------------------------------------------
1 | /ffmpeg.exe
2 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | com.khjxiaogu
6 | MiraiSongPlugin
7 | 1.2.2
8 | MiraiSongPlugin
9 | 使用“#音乐 关键词”、“#QQ 关键词”、“#网易 关键词”等方式进行点歌的插件。
10 |
11 | ${project.name}-2.7-${project.version}
12 | src/main/java
13 |
14 |
15 | src/main/resources
16 | true
17 |
18 |
19 |
20 |
21 | org.codehaus.mojo
22 | templating-maven-plugin
23 | 1.0.0
24 |
25 |
26 | filter-src
27 |
28 | filter-sources
29 |
30 |
31 |
32 | @
33 |
34 |
35 |
36 |
37 |
38 |
39 | org.apache.maven.plugins
40 | maven-shade-plugin
41 | 3.2.1
42 |
43 |
44 | false
45 | true
46 |
47 |
48 | com.google.code.gson:gson
49 |
50 |
51 |
52 |
53 | com.google.gson
54 | ${project.groupId}.${project.artifactId}.gson
55 |
56 |
57 |
58 |
59 |
60 | package
61 |
62 | shade
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | UTF-8
71 | 点歌插件
72 | khjxiaogu
73 | 1.8
74 | 1.8
75 |
76 |
77 |
78 | alimaven
79 | aliyun maven
80 | http://maven.aliyun.com/nexus/content/groups/public/
81 |
82 |
83 | globalmvn
84 | https://mvnrepository.com/artifact/
85 |
86 |
87 |
88 |
89 | net.mamoe
90 | mirai-console
91 | 2.12.2
92 | provided
93 |
94 |
95 | net.mamoe
96 | mirai-core-all
97 | 2.12.2
98 | provided
99 |
100 |
101 | com.google.code.gson
102 | gson
103 | 2.8.6
104 |
105 |
106 |
--------------------------------------------------------------------------------
/silk_v3_encoder.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khjxiaogu/MiraiSongPlugin/79711fcc1ae79fe51aa1d209c40e879f82f67366/silk_v3_encoder.exe
--------------------------------------------------------------------------------
/src/.gitignore:
--------------------------------------------------------------------------------
1 | /test/
2 |
--------------------------------------------------------------------------------
/src/main/java-templates/com/khjxiaogu/MiraiSongPlugin/PluginData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin;
19 |
20 | // TODO: Auto-generated Javadoc
21 | /**
22 | * 自动替换的插件信息工具类
23 | *
24 | * @author khjxiaogu
25 | * file: PluginData.java
26 | * time: 2020年9月12日
27 | */
28 | public class PluginData {
29 | /**
30 | * The Id.
31 | * 插件id.
32 | */
33 | public static String id = "@project.groupId@.mirai.@project.artifactId@";
34 |
35 | /**
36 | * The name.
37 | * 插件名称.
38 | */
39 | public static String name = "@mirai.plugin.name@";
40 |
41 | /**
42 | * The ver.
43 | * 插件版本.
44 | */
45 | public static String ver = "@project.version@";
46 |
47 | /**
48 | * The auth.
49 | * 插件作者.
50 | */
51 | public static String auth = "@mirai.plugin.author@";
52 |
53 | /**
54 | * The info.
55 | * 插件信息.
56 | */
57 | public static String info = "@project.description@";
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/JsonBuilder.java:
--------------------------------------------------------------------------------
1 | package com.khjxiaogu.MiraiSongPlugin;
2 |
3 | import com.google.gson.JsonArray;
4 | import com.google.gson.JsonElement;
5 | import com.google.gson.JsonObject;
6 |
7 | public class JsonBuilder {
8 |
9 | public JsonBuilder() {
10 | }
11 | public static JsonArrayBuilder array(){
12 | return new JsonArrayBuilder<>(null);
13 | }
14 | public static JsonObjectBuilder object(){
15 | return new JsonObjectBuilder<>(null);
16 | }
17 | public static class JsonArrayBuilder {
18 | JsonArray jo=new JsonArray();
19 | T parent;
20 | private JsonArrayBuilder(T par) {
21 | parent=par;
22 | }
23 | public T end() {
24 | if(parent==null)
25 | return (T) jo;
26 | return parent;
27 | }
28 | public JsonArrayBuilder add(String v){
29 | jo.add(v);
30 | return this;
31 | }
32 | public JsonArrayBuilder add(Number v){
33 | jo.add(v);
34 | return this;
35 | }
36 | public JsonArrayBuilder add(boolean v){
37 | jo.add(v);
38 | return this;
39 | }
40 | public JsonArrayBuilder add(Character v){
41 | jo.add(v);
42 | return this;
43 | }
44 | public JsonArrayBuilder add(JsonElement v){
45 | jo.add(v);
46 | return this;
47 | }
48 | public JsonObjectBuilder> object(){
49 | JsonObjectBuilder> job= new JsonObjectBuilder<>(this);
50 | this.add(job.get());
51 | return job;
52 | }
53 | public JsonArrayBuilder> array(){
54 | JsonArrayBuilder> job= new JsonArrayBuilder<>(this);
55 | this.add(job.get());
56 | return job;
57 | }
58 | public JsonArray get() {
59 | return jo;
60 | };
61 | public String toString() {
62 | return jo.toString();
63 | }
64 | }
65 | public static class JsonObjectBuilder {
66 | JsonObject jo=new JsonObject();
67 | T parent;
68 | private JsonObjectBuilder(T par) {
69 | parent=par;
70 | }
71 |
72 | public T end() {
73 | if(parent==null)
74 | return (T) jo;
75 | return parent;
76 | }
77 | public JsonObjectBuilder add(String k,String v){
78 | jo.addProperty(k,v);
79 | return this;
80 | }
81 | public JsonObjectBuilder add(String k,Number v){
82 | jo.addProperty(k,v);
83 | return this;
84 | }
85 | public JsonObjectBuilder add(String k,boolean v){
86 | jo.addProperty(k,v);
87 | return this;
88 | }
89 | public JsonObjectBuilder add(String k,Character v){
90 | jo.addProperty(k, v);
91 | return this;
92 | }
93 | public JsonObjectBuilder add(String k,JsonElement v){
94 | jo.add(k, v);
95 | return this;
96 | }
97 | public JsonObjectBuilder> object(String k){
98 | JsonObjectBuilder> job= new JsonObjectBuilder>(this);
99 | this.add(k, job.get());
100 | return job;
101 | }
102 | public JsonArrayBuilder> array(String k){
103 | JsonArrayBuilder> job= new JsonArrayBuilder<>(this);
104 | this.add(k,job.get());
105 | return job;
106 | }
107 | public JsonObject get() {
108 | return jo;
109 | };
110 | public String toString() {
111 | return jo.toString();
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/MusicCardProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin;
19 |
20 | import net.mamoe.mirai.contact.Contact;
21 | import net.mamoe.mirai.message.data.Message;
22 |
23 | /**
24 | * 生成音乐卡片的接口
25 | *
26 | * @author khjxiaogu
27 | * file: MusicCardProvider.java
28 | * time: 2020年8月26日
29 | */
30 | @FunctionalInterface
31 | public interface MusicCardProvider {
32 |
33 | /**
34 | * 处理音乐信息并生成卡片.
35 | *
36 | * @param mi 音乐信息
37 | * @param ct 请求该信息的联系人,可能为群或者好友,用于上传图片等用,不要直接给他们发信息,应该通过返回值
38 | * @return 返回要回传的音乐卡片信息
39 | * @throws Exception 发生任意异常
40 | */
41 | public Message process(MusicInfo mi, Contact ct) throws Exception;
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/MusicInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin;
19 |
20 | import java.util.Map;
21 |
22 | // TODO: Auto-generated Javadoc
23 | /**
24 | * Class MusicInfo.
25 | *
26 | * @author khjxiaogu
27 | * file: MusicInfo.java
28 | * @date 2022年8月22日
29 | */
30 | public class MusicInfo {
31 |
32 | /** The title. 音乐名称 */
33 | public final String title;
34 |
35 | /** The desc. 音乐描述 */
36 | public final String desc;
37 |
38 | /** The purl. 图片地址,必须能够外界直接访问 */
39 | public final String purl;
40 |
41 | /** The murl. 音频地址,必须能够外界直接访问 */
42 | public final String murl;
43 |
44 | /** The jurl. 跳转地址,必须能够外界直接访问 */
45 | public final String jurl;
46 |
47 | /** The source. 音乐源名称 */
48 | public final String source;
49 |
50 | /** The icon. 音乐源图标地址 */
51 | public final String icon;
52 |
53 | /** The appid. 音乐软件appid,用于发送卡片 */
54 | public final long appid;
55 |
56 | /** The properties. 请求上述链接的而外http HEAD,可能为null */
57 | public Map properties;
58 |
59 | /**
60 | * Instantiates a new MusicInfo.
61 | *
62 | * @param title the title
63 | * @param desc the desc
64 | * @param purl the purl
65 | * @param murl the murl
66 | * @param jurl the jurl
67 | * @param source the source
68 | * @param icon the icon
69 | * @param appid the appid
70 | */
71 | public MusicInfo(String title, String desc, String purl, String murl, String jurl, String source, String icon,
72 | long appid) {
73 | this.title = title;
74 | this.desc = desc;
75 | this.purl = purl;
76 | this.murl = murl;
77 | this.jurl = jurl;
78 | this.source = source;
79 | this.icon = icon;
80 | this.appid = appid;
81 | }
82 |
83 | /**
84 | * Instantiates a new MusicInfo.
85 | *
86 | * @param title the title
87 | * @param desc the desc
88 | * @param purl the purl
89 | * @param murl the murl
90 | * @param jurl the jurl
91 | * @param source the source
92 | */
93 | public MusicInfo(String title, String desc, String purl, String murl, String jurl, String source) {
94 | this.appid = 0;
95 | this.icon = "";
96 | this.source = source;
97 | this.title = title;
98 | this.desc = desc;
99 | this.purl = purl;
100 | this.murl = murl;
101 | this.jurl = jurl;
102 | }
103 |
104 | /**
105 | * Instantiates a new MusicInfo.
106 | *
107 | * @param title the title
108 | * @param desc the desc
109 | * @param purl the purl
110 | * @param murl the murl
111 | * @param jurl the jurl
112 | * @param source the source
113 | * @param icon the icon
114 | */
115 | public MusicInfo(String title, String desc, String purl, String murl, String jurl, String source, String icon) {
116 | this.title = title;
117 | this.desc = desc;
118 | this.purl = purl;
119 | this.murl = murl;
120 | this.jurl = jurl;
121 | this.source = source;
122 | this.icon = icon;
123 | this.appid = 0;
124 | }
125 |
126 | @Override
127 | public String toString() {
128 | return "歌曲信息\n歌名:" + title + "\n作者:" + desc + "\n封面:" + purl + "\n音频:" + murl + "\n链接:" + jurl
129 | + "\n来自:" + source + "\n小图标:" + icon + "\nAPPID:" + appid;
130 | }
131 | }
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/MusicSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin;
19 |
20 | // TODO: Auto-generated Javadoc
21 |
22 | /**
23 | * 音乐来源接口.
24 | *
25 | * @author khjxiaogu
26 | * file: MusicSource.java
27 | * time: 2020年8月26日
28 | */
29 | public interface MusicSource {
30 |
31 | /**
32 | * 搜索对应关键词并返回音乐信息.
33 | * 返回音乐信息不能为null。
34 | *
35 | * @param keyword 关键词
36 | * @return return 返回音乐信息数据类
37 | * @throws Exception 如果发生异常或者找不到音乐,都抛出异常。
38 | */
39 | public MusicInfo get(String keyword) throws Exception;
40 | /**
41 | * 搜索对应音乐ID并返回音乐信息.
42 | * 返回音乐信息不能为null。
43 | *
44 | * @param keyword 音乐
45 | * @return return 返回音乐信息数据类
46 | * @throws Exception 如果发生异常或者找不到音乐,都抛出异常。
47 | */
48 | public MusicInfo getId(String id) throws Exception;
49 |
50 | /**
51 | * 返回是否对全部搜索可见
52 | *
53 | * @return 如果是全部搜索可以搜索本来源,返回true.
54 | */
55 | public default boolean isVisible() {
56 | return true;
57 | };
58 | }
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/SongIdMatcher.java:
--------------------------------------------------------------------------------
1 | package com.khjxiaogu.MiraiSongPlugin;
2 |
3 | import java.util.Objects;
4 | import java.util.regex.Matcher;
5 | import java.util.regex.Pattern;
6 |
7 | import net.mamoe.mirai.contact.Contact;
8 | import net.mamoe.mirai.message.data.Message;
9 |
10 | public class SongIdMatcher {
11 | Pattern mc;
12 | MusicSource src;
13 | MusicCardProvider card;
14 | public SongIdMatcher(String regex,MusicSource src,MusicCardProvider cd) {
15 | mc=Pattern.compile(regex);
16 | this.src=Objects.requireNonNull(src);
17 | this.card=Objects.requireNonNull(cd);
18 | }
19 | public Message test(String s,Contact ct) throws Exception {
20 | Matcher m=mc.matcher(s);
21 | if(m.find()) {
22 | return card.process(src.getId(m.group(1)),ct);
23 | }
24 | return null;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/AmrVoiceProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.io.OutputStream;
25 | import java.net.URL;
26 | import java.net.URLConnection;
27 | import java.util.Map;
28 |
29 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
30 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
31 | import com.khjxiaogu.MiraiSongPlugin.Utils;
32 |
33 | import net.mamoe.mirai.contact.Contact;
34 | import net.mamoe.mirai.message.data.Message;
35 | import net.mamoe.mirai.message.data.PlainText;
36 | import net.mamoe.mirai.utils.ExternalResource;
37 | import net.mamoe.mirai.utils.OverFileSizeMaxException;
38 |
39 | public class AmrVoiceProvider implements MusicCardProvider {
40 | public static String ffmpeg = "ffmpeg";
41 | public static boolean autoSize = false;
42 | public static boolean wideBrand = false;
43 | private final static String[] brs = new String[] { "23.05k", "19.85k", "18.25k", "15.85k", "14.25k", "12.65k",
44 | "8.85k", "6.6k" };
45 | public static String customCommand;
46 |
47 | public AmrVoiceProvider() {
48 | }
49 |
50 | @Override
51 | public Message process(MusicInfo mi, Contact ct) {
52 | URLConnection huc2 = null;
53 | try {
54 | huc2 = new URL(mi.murl).openConnection();
55 | if (mi.properties != null)
56 | for (Map.Entry me : mi.properties.entrySet())
57 | huc2.addRequestProperty(me.getKey(), me.getValue());
58 | huc2.connect();
59 | } catch (IOException e) {
60 | return new PlainText("获取音频失败");
61 | }
62 | File f = new File("temp/", "wv" + System.currentTimeMillis() + ".m4a");
63 | // File f2 = new File("./temp/", "wv" + System.currentTimeMillis() + ".silk");
64 | // File ft = new File("./temp/", "wv" + System.currentTimeMillis() + ".pcm");
65 | File f2 = new File("temp/", "wv" + System.currentTimeMillis() + ".amr");
66 | try {
67 | f.getParentFile().mkdirs();
68 | OutputStream os = new FileOutputStream(f);
69 | os.write(Utils.readAll(huc2.getInputStream()));
70 | os.flush();
71 | os.close();
72 | while(!new File(f.getAbsolutePath()).exists());
73 | if (customCommand != null) {
74 | Utils.exeCmd(customCommand.replace("%input%", f.getAbsolutePath()).replace("%output%",
75 | f2.getAbsolutePath()));
76 | try (FileInputStream fis = new FileInputStream(f2);ExternalResource ex=ExternalResource.create(fis)) {
77 | return Utils.uploadVoice(ex,ct);
78 | }
79 | } else if (wideBrand) {
80 | if (autoSize)
81 | Utils.exeCmd(ffmpeg, "-i", f.getAbsolutePath(), "-ab", "23.85k", "-ar", "16000",
82 | "-ac", "1", "-acodec", "amr_wb", "-fs", "1000000", "-y", f2.getAbsolutePath());
83 | else
84 | Utils.exeCmd(ffmpeg, "-i", f.getAbsolutePath(), "-ab", "23.85k", "-ar", "16000",
85 | "-ac", "1", "-acodec", "amr_wb", "-y", f2.getAbsolutePath());
86 | int i = 0;
87 | do {
88 | try {
89 | try (FileInputStream fis = new FileInputStream(f2);ExternalResource ex=ExternalResource.create(fis)) {
90 | return Utils.uploadVoice(ex,ct);
91 | }
92 | } catch (OverFileSizeMaxException ofse) {
93 | Utils.exeCmd(ffmpeg, "-i", f.getAbsolutePath(), "-ab", brs[i], "-ar", "16000",
94 | "-ac", "1", "-acodec", "amr_wb", "-y", f2.getAbsolutePath());
95 | i++;
96 | }
97 | } while (autoSize);
98 | } else {
99 | Utils.exeCmd(ffmpeg, "-i", f.getAbsolutePath(), "-ab", "12.2k", "-ar", "8000", "-ac",
100 | "1", "-fs", "1000000", "-y", f2.getAbsolutePath());
101 |
102 | try (FileInputStream fis = new FileInputStream(f2);ExternalResource ex=ExternalResource.create(fis)) {
103 | return Utils.uploadVoice(ex,ct);
104 | }
105 | }
106 |
107 | } catch (Exception e1) {
108 | // TODO Auto-generated catch block
109 | e1.printStackTrace();
110 | } finally {
111 | f.delete();
112 | // ft.delete();
113 | f2.delete();
114 | }
115 | return new PlainText("当前状态不支持音频");
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/LightAppCardProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import com.google.gson.JsonObject;
21 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
22 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
23 |
24 | import net.mamoe.mirai.contact.Contact;
25 | import net.mamoe.mirai.message.data.LightApp;
26 | import net.mamoe.mirai.message.data.MessageChain;
27 |
28 | public class LightAppCardProvider implements MusicCardProvider {
29 |
30 | public LightAppCardProvider() {
31 | }
32 |
33 | @Override
34 | public MessageChain process(MusicInfo mi, Contact ct) {
35 | JsonObject appmsg = new JsonObject();
36 | appmsg.addProperty("app", "com.tencent.structmsg");
37 | appmsg.addProperty("view", "music");
38 | appmsg.addProperty("ver", "0.0.0.1");
39 | appmsg.addProperty("desc", "音乐");
40 | appmsg.addProperty("prompt", mi.title);
41 | // "autosize":true,
42 | // "ctime":1601797108,
43 | // "forward":true,
44 | // "type":"normal"
45 | JsonObject config = new JsonObject();
46 | config.addProperty("autosize", true);
47 | config.addProperty("forward", true);
48 | config.addProperty("token", "");
49 | config.addProperty("type", "normal");
50 | JsonObject extra = new JsonObject();
51 | extra.addProperty("app_type", 1);
52 | extra.addProperty("appid", mi.appid);
53 | extra.addProperty("uin", ct.getId());
54 | appmsg.add("extra", extra);
55 | JsonObject meta = new JsonObject();
56 | appmsg.add("meta", meta);
57 | JsonObject music = new JsonObject();
58 | meta.add("music", music);
59 | music.addProperty("action", "");
60 | music.addProperty("android_pkg_name", "");
61 | music.addProperty("app_type", 1);
62 | music.addProperty("appid", mi.appid);
63 | music.addProperty("preview", mi.purl);
64 | music.addProperty("desc", mi.desc);
65 | music.addProperty("jumpUrl", mi.jurl);
66 | music.addProperty("musicUrl", mi.murl);
67 | music.addProperty("sourceMsgId", "0");
68 | music.addProperty("source_icon", mi.icon);
69 | music.addProperty("source_url", "");
70 | music.addProperty("tag", mi.source);
71 | music.addProperty("title", mi.title);
72 | return new LightApp(appmsg.toString()).plus("[分享]").plus(mi.title).plus("\n").plus(mi.desc).plus("\n")
73 | .plus(mi.jurl).plus("\n[来自]").plus(mi.source);
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/LightAppXCardProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import com.google.gson.JsonObject;
21 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
22 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
23 | import com.khjxiaogu.MiraiSongPlugin.Utils;
24 |
25 | import net.mamoe.mirai.contact.Contact;
26 | import net.mamoe.mirai.message.data.LightApp;
27 | import net.mamoe.mirai.message.data.Message;
28 |
29 | public class LightAppXCardProvider implements MusicCardProvider {
30 |
31 | public LightAppXCardProvider() {
32 | }
33 |
34 | @Override
35 | public Message process(MusicInfo mi, Contact ct) throws Exception {
36 | JsonObject appmsg = new JsonObject();
37 | appmsg.addProperty("app", "com.tencent.miniapp_01");
38 | JsonObject cfg = new JsonObject();
39 | cfg.addProperty("autosize", 0);
40 | cfg.addProperty("ctime", Utils.getTime() / 1000);
41 | cfg.addProperty("token", "a95f83e736db2f94d88f9974c09717ad");
42 | cfg.addProperty("type", "normal");
43 | cfg.addProperty("forward", 1);
44 | appmsg.add("config", cfg);
45 | appmsg.addProperty("view", "music");
46 | appmsg.addProperty("ver", "1.0.0.19");
47 | appmsg.addProperty("desc", "音乐");
48 | appmsg.addProperty("view", "view_8C8E89B49BE609866298ADDFF2DBABA4");
49 | appmsg.addProperty("prompt", mi.title);
50 | JsonObject meta = new JsonObject();
51 | appmsg.add("meta", meta);
52 | JsonObject music = new JsonObject();
53 | meta.add("music", music);
54 | music.addProperty("action", "");
55 | music.addProperty("android_pkg_name", "");
56 | music.addProperty("app_type", 1);
57 | music.addProperty("appid", mi.appid);
58 | music.addProperty("preview", mi.purl);
59 | music.addProperty("desc", mi.desc);
60 | music.addProperty("jumpUrl", mi.jurl);
61 | music.addProperty("musicUrl", mi.murl);
62 | music.addProperty("sourceMsgId", "0");
63 | music.addProperty("source_icon", mi.icon);
64 | music.addProperty("source_url", "");
65 | music.addProperty("tag", mi.source);
66 | music.addProperty("title", mi.title);
67 | JsonObject detail = new JsonObject();
68 | meta.add("detail_1", detail);
69 | detail.addProperty("appid", mi.appid);
70 | detail.addProperty("desc", mi.desc);
71 | detail.addProperty("icon", mi.icon);
72 | detail.addProperty("preview", mi.purl);
73 | detail.addProperty("qqdocurl", mi.jurl);
74 | detail.addProperty("scene", 1036);
75 | detail.addProperty("shareTemplateId", "8C8E89B49BE609866298ADDFF2DBABA4");
76 | detail.add("shareTemplateData", new JsonObject());
77 | detail.addProperty("title", mi.title);
78 | return new LightApp(appmsg.toString()).plus(mi.jurl);
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/MiraiMusicCard.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
24 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
25 |
26 | import net.mamoe.mirai.contact.Contact;
27 | import net.mamoe.mirai.message.data.Message;
28 | import net.mamoe.mirai.message.data.MusicKind;
29 | import net.mamoe.mirai.message.data.MusicShare;
30 |
31 | public class MiraiMusicCard implements MusicCardProvider {
32 | static Map appidMappings=new HashMap<>();
33 | static MusicCardProvider def=new XMLCardProvider();
34 | static {
35 | for(MusicKind mk:MusicKind.values())
36 | appidMappings.put(mk.getAppId(),mk);
37 | }
38 | @Override
39 | public Message process(MusicInfo mi, Contact ct) throws Exception {
40 | MusicKind omk=appidMappings.get(mi.appid);
41 | if(omk!=null)
42 | return new MusicShare(omk,mi.title,mi.desc,mi.jurl,mi.purl,mi.murl);
43 | return def.process(mi, ct);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/PlainMusicInfoProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import java.io.IOException;
21 | import java.net.MalformedURLException;
22 |
23 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
24 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
25 | import com.khjxiaogu.MiraiSongPlugin.Utils;
26 |
27 | import net.mamoe.mirai.contact.Contact;
28 | import net.mamoe.mirai.message.data.Image;
29 | import net.mamoe.mirai.message.data.Message;
30 | import net.mamoe.mirai.message.data.PlainText;
31 | import net.mamoe.mirai.utils.ExternalResource;
32 | import net.mamoe.mirai.utils.OverFileSizeMaxException;
33 |
34 | public class PlainMusicInfoProvider implements MusicCardProvider {
35 |
36 | public PlainMusicInfoProvider() {
37 | }
38 |
39 | @Override
40 | public Message process(MusicInfo mi, Contact ct) throws OverFileSizeMaxException, MalformedURLException {
41 | Image im = null;
42 | try(ExternalResource ex=ExternalResource.create(Utils.getFromHttp(mi.purl))){
43 | im = ct.uploadImage(ex);
44 | } catch (IOException e) {
45 | }
46 | StringBuilder tsb = new StringBuilder().append("歌名:").append(mi.title).append("\n作者:").append(mi.desc)
47 | .append("\n封面:").append(mi.purl).append("\n外链:").append(mi.murl).append("\n链接:").append(mi.jurl)
48 | .append("\n来自:").append(mi.source);
49 | if (im != null)
50 | return im.plus(tsb.toString());
51 | return new PlainText(tsb.toString());
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/ShareCardProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
21 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
22 |
23 | import net.mamoe.mirai.contact.Contact;
24 | import net.mamoe.mirai.message.data.Message;
25 | import net.mamoe.mirai.message.data.RichMessage;
26 |
27 | public class ShareCardProvider implements MusicCardProvider {
28 |
29 | public ShareCardProvider() {
30 | }
31 |
32 | @Override
33 | public Message process(MusicInfo mi, Contact ct) {
34 | return RichMessage.share(mi.jurl.replaceAll("\\&", "&"), mi.title, mi.desc,
35 | mi.purl.replaceAll("\\&", "&"));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/SilkVoiceProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.io.OutputStream;
25 | import java.net.HttpURLConnection;
26 | import java.net.URL;
27 | import java.util.Map;
28 |
29 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
30 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
31 | import com.khjxiaogu.MiraiSongPlugin.Utils;
32 |
33 | import net.mamoe.mirai.contact.Contact;
34 | import net.mamoe.mirai.message.data.Message;
35 | import net.mamoe.mirai.message.data.PlainText;
36 | import net.mamoe.mirai.utils.ExternalResource;
37 |
38 | public class SilkVoiceProvider implements MusicCardProvider {
39 | public static String silk = "silk_v3_encoder";
40 | public static String ffmpeg ="ffmpeg";
41 |
42 | public SilkVoiceProvider() {
43 | }
44 |
45 | @Override
46 | public Message process(MusicInfo mi, Contact ct) {
47 | HttpURLConnection huc2 = null;
48 | try {
49 | huc2 = (HttpURLConnection) new URL(mi.murl).openConnection();
50 | if (mi.properties != null)
51 | for (Map.Entry me : mi.properties.entrySet())
52 | huc2.addRequestProperty(me.getKey(), me.getValue());
53 | huc2.setRequestMethod("GET");
54 | huc2.connect();
55 | } catch (IOException e) {
56 | return new PlainText("获取音频失败");
57 | }
58 | File f = new File("temp/", "wv" + System.currentTimeMillis() + ".m4a");
59 | File f2 = new File("temp/", "wv" + System.currentTimeMillis() + ".silk");
60 | File ft = new File("temp/", "wv" + System.currentTimeMillis() + ".pcm");
61 | // File f2=new File("./temp/","wv"+System.currentTimeMillis()+".amr");
62 | try {
63 | f.getParentFile().mkdirs();
64 | OutputStream os = new FileOutputStream(f);
65 | os.write(Utils.readAll(huc2.getInputStream()));
66 |
67 | os.close();
68 | // exeCmd(new File("ffmpeg.exe").getAbsolutePath() + " -i \"" +
69 | // f.getAbsolutePath()
70 | // + "\" -ab 12.2k -ar 8000 -ac 1 -y " + f2.getAbsolutePath());
71 | Utils.exeCmd(ffmpeg, "-i", f.getAbsolutePath(), "-f", "s16le", "-ar", "24000", "-ac", "1",
72 | "-acodec", "pcm_s16le", "-y", ft.getAbsolutePath());
73 | Utils.exeCmd(silk, ft.getAbsolutePath(), f2.getAbsolutePath(), "-Fs_API", "24000",
74 | "-tencent");
75 | try (FileInputStream fis = new FileInputStream(f2);ExternalResource ex=ExternalResource.create(fis)) {
76 | return Utils.uploadVoice(ex,ct);
77 | }
78 | } catch (IOException e1) {
79 | // TODO Auto-generated catch block
80 | e1.printStackTrace();
81 | } finally {
82 | f.delete();
83 | ft.delete();
84 | f2.delete();
85 | }
86 | return new PlainText("当前状态不支持音频");
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/cardprovider/XMLCardProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.cardprovider;
19 |
20 | import com.khjxiaogu.MiraiSongPlugin.MusicCardProvider;
21 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
22 |
23 | import net.mamoe.mirai.contact.Contact;
24 | import net.mamoe.mirai.message.data.Message;
25 | import net.mamoe.mirai.message.data.MessageChain;
26 | import net.mamoe.mirai.message.data.SimpleServiceMessage;
27 |
28 | public class XMLCardProvider implements MusicCardProvider {
29 |
30 | public XMLCardProvider() {
31 | }
32 |
33 | @Override
34 | public MessageChain process(MusicInfo mi, Contact ct) {
35 | StringBuilder xmb = new StringBuilder("\r\n\r\n")
38 | .append("\r\n").append("").append(escapeXmlContent(mi.title))
40 | .append("\r\n").append(escapeXmlContent(mi.desc))
41 | .append("\r\n\r\n\r\n");
45 | Message msg = new SimpleServiceMessage(2, xmb.toString());
46 | return msg.plus(mi.jurl);
47 | }
48 |
49 | public String escapeXmlContent(String org) {
50 | return org.replaceAll("<", "<").replaceAll(">", ">");
51 | }
52 |
53 | public String escapeXmlTag(String org) {
54 | return org.replaceAll("\\&", "&").replaceAll("\"", """).replaceAll("'", "'")
55 | .replaceAll("<", "<").replaceAll(">", ">");
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/BaiduMusicSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import java.net.HttpURLConnection;
21 | import java.net.URL;
22 |
23 | import com.google.gson.JsonObject;
24 | import com.google.gson.JsonParser;
25 | import com.khjxiaogu.MiraiSongPlugin.HttpRequestBuilder;
26 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
27 | import com.khjxiaogu.MiraiSongPlugin.MusicSource;
28 | import com.khjxiaogu.MiraiSongPlugin.Utils;
29 |
30 | public class BaiduMusicSource implements MusicSource {
31 |
32 | public BaiduMusicSource() {
33 | }
34 |
35 | @Override
36 | public MusicInfo get(String keyword) throws Exception {
37 | JsonObject jo;
38 | int requested = 0;
39 | HttpRequestBuilder req=HttpRequestBuilder.create("http","music.baidu.com")
40 | .url("/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.search.catalogSug&query=")
41 | .url(Utils.urlEncode(keyword))
42 | .referer("http://music.91q.com/")
43 | .defUA();
44 | do {
45 |
46 | jo = req.get().readJson();
47 | } while (jo.get("error_code").getAsInt() != 22000 && requested++ < 3);// 百度有时候会请求失败,不断请求直到成功。
48 | String sid = jo.getAsJsonObject().getAsJsonObject().get("song").getAsJsonArray().get(0).getAsJsonObject()
49 | .get("songid").getAsString();
50 | return getId(sid);
51 | }
52 |
53 | @Override
54 | public MusicInfo getId(String sid) throws Exception {
55 | HttpURLConnection huc = (HttpURLConnection) new URL(
56 | "http://tingapi.ting.baidu.com/v1/restserver/ting?format=json&calback=&from=webapp_music&method=baidu.ting.song.play&songid="
57 | + sid).openConnection();
58 | huc.setRequestProperty("Host", "tingapi.ting.baidu.com");
59 | huc.setRequestProperty("Referrer", "http://music.taihe.com/");
60 | huc.setRequestProperty("User-Agent",
61 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36");
62 | huc.setRequestMethod("GET");
63 | huc.connect();
64 | JsonObject allinfo = JsonParser.parseString(new String(Utils.readAll(huc.getInputStream()), "UTF-8"))
65 | .getAsJsonObject();
66 | JsonObject sif = allinfo.getAsJsonObject().get("songinfo").getAsJsonObject();
67 | huc.disconnect();
68 | return new MusicInfo(sif.get("title").getAsString(), sif.get("author").getAsString(),
69 | sif.get("pic_big").getAsString(),
70 | allinfo.get("bitrate").getAsJsonObject().get("file_link").getAsString(),
71 | sif.get("share_url") != null ? sif.get("share_url").getAsString() : "", "千千静听");
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/BiliBiliMusicSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import java.util.HashMap;
21 |
22 | import com.google.gson.JsonArray;
23 | import com.google.gson.JsonObject;
24 | import com.khjxiaogu.MiraiSongPlugin.HttpRequestBuilder;
25 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
26 | import com.khjxiaogu.MiraiSongPlugin.MusicSource;
27 | import com.khjxiaogu.MiraiSongPlugin.Utils;
28 |
29 | public class BiliBiliMusicSource implements MusicSource {
30 |
31 | @Override
32 | public MusicInfo get(String keyword) throws Exception {
33 | JsonArray ja=HttpRequestBuilder.create("api.bilibili.com")
34 | .url("/audio/music-service-c/s?keyword=")
35 | .url(Utils.urlEncode(keyword))
36 | .get()
37 | .readJson().get("data").getAsJsonObject().get("result").getAsJsonArray();
38 | String murl;
39 | JsonObject jo = ja.get(0).getAsJsonObject();
40 | JsonArray pl = jo.get("play_url_list").getAsJsonArray();
41 | int i = 0;
42 | while (pl.size() <= 0) {
43 | jo = ja.get(++i).getAsJsonObject();
44 | pl = jo.get("play_url_list").getAsJsonArray();
45 | }
46 | murl = pl.get(pl.size() > 1 ? 1 : 0).getAsJsonObject().get("url").getAsString();
47 | MusicInfo mi = new MusicInfo(jo.get("title").getAsString(),
48 | "UP:" + jo.get("up_name").getAsString() + "创作:" + jo.get("author").getAsString(),
49 | jo.get("cover").getAsString(), murl, "https://www.bilibili.com/audio/au" + jo.get("id").getAsString(),
50 | "哔哩哔哩","https://open.gtimg.cn/open/app_icon/00/95/17/76/100951776_100_m.png?t=1624441854",100951776);
51 | mi.properties = new HashMap<>();
52 | mi.properties.put("user-agent",
53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36");
54 | mi.properties.put("referer", "https://www.bilibili.com/");
55 | return mi;
56 | }
57 |
58 | @Override
59 | public MusicInfo getId(String id) throws Exception {
60 | throw new UnsupportedOperationException("暂不支持");
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/KugouMusicSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import com.google.gson.JsonObject;
21 | import com.google.gson.JsonParser;
22 | import com.khjxiaogu.MiraiSongPlugin.HttpRequestBuilder;
23 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
24 | import com.khjxiaogu.MiraiSongPlugin.MusicSource;
25 | import com.khjxiaogu.MiraiSongPlugin.Utils;
26 |
27 | public class KugouMusicSource implements MusicSource {
28 | final static String COOKIE = "kg_mid=30f1713c23ab7bb496ab035b07dae834; ACK_SERVER_10015=%7B%22list%22%3A%5B%5B%22bjlogin-user.kugou.com%22%5D%5D%7D; ACK_SERVER_10016=%7B%22list%22%3A%5B%5B%22bjreg-user.kugou.com%22%5D%5D%7D; ACK_SERVER_10017=%7B%22list%22%3A%5B%5B%22bjverifycode.service.kugou.com%22%5D%5D%7D; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1598198881; kg_dfid=1HZmYL0ngIYp0uu93N2m4s5P; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1598199021";
29 |
30 | public KugouMusicSource() {
31 | }
32 |
33 | @Override
34 | public MusicInfo get(String keyword) throws Exception {
35 | keyword=Utils.urlEncode(keyword);
36 | JsonObject je = JsonParser
37 | .parseString(HttpRequestBuilder.create("http","msearchcdn.kugou.com")
38 | .url("/api/v3/search/song?showtype=14&highlight=em&pagesize=1&tag_aggr=1&tagtype=%E5%85%A8%E9%83%A8&plat=0&sver=5&correct=1&api_ver=1&version=9108&page=1&area_code=1&tag=1&with_res_tag=1&keyword=")
39 | .url(keyword)
40 | .get().readString().replaceAll("", ""))
41 | .getAsJsonObject();
42 | String song = je.get("data").getAsJsonObject().get("info").getAsJsonArray().get(0).getAsJsonObject().get("hash")
43 | .getAsString();
44 | String album_id = je.get("data").getAsJsonObject().get("info").getAsJsonArray().get(0).getAsJsonObject()
45 | .get("album_id").getAsString();
46 | JsonObject info = HttpRequestBuilder.create("wwwapi.kugou.com")
47 | .url("/yy/index.php?r=play/getdata&hash=")
48 | .url(song)
49 | .url("&album_id=")
50 | .url(album_id)
51 | .url("&_=")
52 | .url(String.valueOf(Utils.getTime()))
53 | .cookie(COOKIE)
54 | .get().readJson().get("data").getAsJsonObject();
55 | return new MusicInfo(info.get("audio_name").getAsString(), info.get("author_name").getAsString(),
56 | info.get("img").getAsString(), info.get("play_url").getAsString(),
57 | "https://www.kugou.com/song/#hash=" + song + "&album_id=" + info.get("album_id").getAsString(), "酷狗","",205141);
58 | }
59 |
60 | @Override
61 | public MusicInfo getId(String id) throws Exception {
62 | throw new UnsupportedOperationException("暂不支持");
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/LocalFileSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import java.io.FileReader;
21 |
22 | import com.google.gson.JsonArray;
23 | import com.google.gson.JsonElement;
24 | import com.google.gson.JsonObject;
25 | import com.google.gson.JsonParser;
26 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
27 | import com.khjxiaogu.MiraiSongPlugin.MusicSource;
28 | import com.khjxiaogu.MiraiSongPlugin.Utils;
29 |
30 | public class LocalFileSource implements MusicSource {
31 | public static boolean autoLocal = false;
32 |
33 | @Override
34 | public boolean isVisible() {
35 | return autoLocal;
36 | }
37 |
38 | public LocalFileSource() {
39 | }
40 |
41 | String forceGetJsonString(JsonObject jo, String member) {
42 | return forceGetJsonString(jo, member, "");
43 | }
44 |
45 | String forceGetJsonString(JsonObject jo, String member, String def) {
46 | if (jo.has(member))
47 | return jo.get(member).getAsString();
48 | return def;
49 | }
50 |
51 | @Override
52 | public MusicInfo get(String keyword) throws Exception {
53 | try(FileReader fr=new FileReader("SongPluginLocal.json")){
54 | JsonArray localfs = JsonParser.parseReader(fr).getAsJsonArray();
55 |
56 | JsonObject result = null;
57 | double min = Integer.MAX_VALUE;
58 | for (JsonElement je : localfs) {
59 | JsonObject cur = je.getAsJsonObject();
60 | String ckw = forceGetJsonString(cur, "title");
61 | double curm = Utils.compare(keyword, ckw);
62 | if (curm < min) {
63 | min = curm;
64 | result = cur;
65 | }
66 | }
67 |
68 | return new MusicInfo(forceGetJsonString(result, "title"), forceGetJsonString(result, "desc"),
69 | forceGetJsonString(result, "previewUrl"), forceGetJsonString(result, "musicUrl"),
70 | forceGetJsonString(result, "jumpUrl"), forceGetJsonString(result, "source", "本地"));
71 | }
72 | }
73 |
74 | @Override
75 | public MusicInfo getId(String id) throws Exception {
76 | throw new UnsupportedOperationException("暂不支持");
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/NetEaseAdvancedRadio.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
21 | import com.khjxiaogu.MiraiSongPlugin.Utils;
22 |
23 | public class NetEaseAdvancedRadio extends NetEaseRadioSource {
24 |
25 | @Override
26 | public MusicInfo get(String keyword) throws Exception {
27 | String rkw = keyword;
28 | int pos = rkw.indexOf('|');
29 | if (pos != -1) {
30 | String radio = rkw.substring(0, pos);
31 | String song = rkw.substring(pos + 1);
32 | if (song.length() > 0 && radio.length() > 0)
33 | return super.get(Utils.urlEncode(radio), song);
34 | }
35 | return super.get(keyword);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/NetEaseHQMusicSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import com.google.gson.JsonArray;
21 | import com.google.gson.JsonObject;
22 | import com.khjxiaogu.MiraiSongPlugin.HttpRequestBuilder;
23 | import com.khjxiaogu.MiraiSongPlugin.JsonBuilder;
24 | import com.khjxiaogu.MiraiSongPlugin.NetEaseCrypto;
25 |
26 | public class NetEaseHQMusicSource extends NetEaseMusicSource {
27 |
28 | public NetEaseHQMusicSource() {
29 | }
30 |
31 | @Override
32 | public String queryRealUrl(String id) throws Exception {
33 |
34 | JsonObject main = HttpRequestBuilder.create("music.163.com")
35 | .url("/weapi/song/enhance/player/url?csrf_token=")
36 | .contenttype("application/x-www-form-urlencoded")
37 | .referer("https://music.163.com")
38 | .cookie(NetEaseCrypto.cookie)
39 | .ua(NetEaseCrypto.getUserAgent())
40 | .post()
41 | .send(NetEaseCrypto.weapiEncryptParam(JsonBuilder.object().add("ids","[" + id + "]").add("br",999000).toString()))
42 | .readJson();
43 | if (main.get("code").getAsInt() == 200) {
44 | JsonArray data = main.get("data").getAsJsonArray();
45 | JsonObject song = data.get(0).getAsJsonObject();
46 | if (song.get("code").getAsInt() == 200) {
47 | return song.get("url").getAsString().trim();
48 | }
49 | }
50 | return null;
51 | }
52 |
53 | @Override
54 | public boolean isVisible() {
55 | return false;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/NetEaseMusicSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import com.google.gson.JsonArray;
21 | import com.google.gson.JsonObject;
22 | import com.khjxiaogu.MiraiSongPlugin.HttpRequestBuilder;
23 | import com.khjxiaogu.MiraiSongPlugin.JsonBuilder;
24 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
25 | import com.khjxiaogu.MiraiSongPlugin.MusicSource;
26 | import com.khjxiaogu.MiraiSongPlugin.NetEaseCrypto;
27 | import com.khjxiaogu.MiraiSongPlugin.Utils;
28 |
29 | public class NetEaseMusicSource implements MusicSource {
30 |
31 | public NetEaseMusicSource() {
32 | }
33 |
34 | public String queryRealUrl(String id) throws Exception {
35 | return "http://music.163.com/song/media/outer/url?id=" + id + ".mp3";
36 | }
37 |
38 |
39 | @Override
40 | public MusicInfo get(String keyword) throws Exception {
41 | String murl;
42 | JsonObject jom=HttpRequestBuilder.create("music.163.com")
43 | .url("/weapi/cloudsearch/get/web?csrf_token=")
44 | .referer("http://music.163.com/")
45 | .cookie("appver=1.5.0.75771;"+NetEaseCrypto.cookie)
46 | .contenttype("application/x-www-form-urlencoded")
47 | .post()
48 | .send(NetEaseCrypto.weapiEncryptParam(JsonBuilder.object().add("s", keyword).add("type", 1).add("offset", 0).add("limit", 3).toString()))
49 | .readJson();
50 | JsonArray ja=jom
51 | .get("result").getAsJsonObject().get("songs").getAsJsonArray();
52 | JsonObject jo = ja.get(0).getAsJsonObject();
53 | murl = queryRealUrl(jo.get("id").getAsString());
54 | int i = 0;
55 | while (!Utils.isExistent(murl)) {
56 | jo = ja.get(++i).getAsJsonObject();
57 | murl = queryRealUrl(jo.get("id").getAsString());
58 | }
59 | return new MusicInfo(jo.get("name").getAsString(),
60 | jo.get("ar").getAsJsonArray().get(0).getAsJsonObject().get("name").getAsString(),
61 | jo.get("al").getAsJsonObject().get("picUrl").getAsString(), murl,
62 | "https://y.music.163.com/m/song?id=" + jo.get("id").getAsString(), "网易云音乐", "", 100495085);
63 | }
64 |
65 | @Override
66 | public MusicInfo getId(String id) throws Exception {
67 | String murl;
68 | JsonObject jo =HttpRequestBuilder.create("music.163.com")
69 | .url("/weapi/song/detail?csrf_token=")
70 | .referer("http://music.163.com/")
71 | .cookie("appver=1.5.0.75771;"+NetEaseCrypto.cookie)
72 | .contenttype("application/x-www-form-urlencoded")
73 | .post()
74 | .send(NetEaseCrypto.weapiEncryptParam(JsonBuilder.object().array("ids").add(id).end().toString()))
75 | .readJson()
76 | .get("songs").getAsJsonArray()
77 | .get(0).getAsJsonObject();
78 | murl = queryRealUrl(id);
79 | return new MusicInfo(jo.get("name").getAsString(),
80 | jo.get("artists").getAsJsonArray().get(0).getAsJsonObject().get("name").getAsString(),
81 | jo.get("album").getAsJsonObject().get("picUrl").getAsString(), murl,
82 | "https://y.music.163.com/m/song?id=" + jo.get("id").getAsString(), "网易云音乐", "", 100495085);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/musicsource/XimalayaSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.musicsource;
19 |
20 | import com.google.gson.JsonArray;
21 | import com.google.gson.JsonObject;
22 | import com.khjxiaogu.MiraiSongPlugin.HttpRequestBuilder;
23 | import com.khjxiaogu.MiraiSongPlugin.MusicInfo;
24 | import com.khjxiaogu.MiraiSongPlugin.MusicSource;
25 | import com.khjxiaogu.MiraiSongPlugin.Utils;
26 |
27 | public class XimalayaSource implements MusicSource {
28 |
29 | @Override
30 | public MusicInfo get(String keyword) throws Exception {
31 | JsonArray ja =HttpRequestBuilder.create("www.ximalaya.com")
32 | .url("/revision/search/main?page=1&spellchecker=true&paidFilter=true&condition=relation&rows=10&device=iPhone&core=track&kw=")
33 | .url(Utils.urlEncode(keyword))
34 |
35 | .get()
36 | .readJson()
37 | .get("data").getAsJsonObject()
38 | .get("track").getAsJsonObject()
39 | .get("docs").getAsJsonArray();
40 | JsonObject song;
41 | int i=-1;
42 | do {
43 | song=ja.get(++i).getAsJsonObject();
44 | }while(song.get("isPaid").getAsBoolean());
45 | String path=HttpRequestBuilder.create("www.ximalaya.com")
46 | .url("/tracks/")
47 | .url(song.get("id").getAsString())
48 | .url(".json")
49 | .get()
50 | .readJson().get("play_path").getAsString();
51 |
52 | return new MusicInfo(song.get("title").getAsString(),song.get("nickname").getAsString(),"https:"+song.get("coverPath").getAsString(),path,"https://www.ximalaya.com"+song.get("trackUrl").getAsString(),"喜马拉雅");
53 | }
54 |
55 | @Override
56 | public MusicInfo getId(String id) throws Exception {
57 | JsonObject out=HttpRequestBuilder.create("www.ximalaya.com")
58 | .url("/tracks/")
59 | .url(id)
60 | .url(".json")
61 | .get()
62 | .readJson();
63 | return new MusicInfo(out.get("title").getAsString(),
64 | String.valueOf(out.get("nickname")),
65 | out.get("cover_url").getAsString(),
66 | out.get("play_path").getAsString(),
67 | "https://www.ximalaya.com/sound/"+id,
68 | "喜马拉雅");
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/FriendMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | public class FriendMatcher implements PermissionMatcher {
24 | PermissionResult result;
25 | @Override
26 | public PermissionResult match(MatchInfo info) {
27 | if(info.bot.getFriend(info.callerid)!=null)
28 | return result;
29 | return PermissionResult.UNSPECIFIED;
30 | }
31 | public FriendMatcher(PermissionResult result) {
32 | this.result = result;
33 | }
34 | public FriendMatcher(boolean result) {
35 | this(PermissionResult.valueOf(result));
36 | }
37 |
38 | @Override
39 | public List getValue() {
40 | return Arrays.asList(result.getSymbol()+"friend");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/GroupMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.ArrayList;
21 | import java.util.LinkedHashMap;
22 | import java.util.List;
23 | import java.util.Map;
24 | import java.util.Map.Entry;
25 | import java.util.concurrent.ConcurrentHashMap;
26 |
27 | import com.khjxiaogu.MiraiSongPlugin.permission.CommandMatcher.PermissionFactory;
28 |
29 | public class GroupMatcher implements PermissionMatcher {
30 | PermissionResult wildcard=PermissionResult.UNSPECIFIED;
31 | LinkedHashMap restricted=new LinkedHashMap<>(5);
32 | Map memberpermissions=new ConcurrentHashMap<>(10);
33 |
34 | @Override
35 | public PermissionResult match(MatchInfo info) {
36 | PermissionResult pr=wildcard;
37 | for(PermissionMatcher sp:restricted.values()) {
38 | pr=pr.and(sp.match(info));
39 | }
40 | pr=pr.and(memberpermissions.getOrDefault(info.callerid,PermissionResult.UNSPECIFIED));
41 | return pr;
42 | }
43 | public List getValue(){
44 | List pl=new ArrayList<>();
45 | if(wildcard!=PermissionResult.UNSPECIFIED)
46 | pl.add(wildcard.getSymbol()+"*");
47 | for(PermissionMatcher sp:restricted.values())
48 | pl.addAll(sp.getValue());
49 | for(Entry i:memberpermissions.entrySet()) {
50 | pl.add(i.getValue().getSymbol()+i.getKey().toString());
51 | }
52 | return pl;
53 | }
54 | boolean load(String param) {
55 | if(param.length()==0)return false;
56 | char isr=param.charAt(0);
57 | if(Character.isDigit(isr)) {
58 | memberpermissions.put(Long.parseLong(param),PermissionResult.DISALLOW);
59 | return true;
60 | }
61 | boolean result=false;
62 | String s;
63 | switch(isr) {
64 | case '#':return false;
65 | case '+':result=true;s=param.substring(1);break;
66 | case '-':s=param.substring(1);break;
67 | default:s=param;break;
68 | }
69 | if(Character.isDigit(s.charAt(0))) {
70 | memberpermissions.put(Long.parseLong(s),PermissionResult.valueOf(result));
71 | return true;
72 | }else if(s.charAt(0)=='*') {
73 | wildcard=PermissionResult.valueOf(result);
74 | return true;
75 | }else {
76 | PermissionFactory pf=Matchers.get(s);
77 | if(pf!=null) {
78 | restricted.put(s,pf.create(result));
79 | return true;
80 | }
81 | }
82 | return false;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/MatchInfo.java:
--------------------------------------------------------------------------------
1 | package com.khjxiaogu.MiraiSongPlugin.permission;
2 |
3 | import net.mamoe.mirai.Bot;
4 | import net.mamoe.mirai.contact.Member;
5 | import net.mamoe.mirai.contact.User;
6 |
7 | public class MatchInfo {
8 | Bot bot;
9 | long callerid;
10 | long groupid;
11 | String cmd;
12 | boolean isTemp;
13 | boolean mustMatchCommand;
14 | public MatchInfo() {
15 | }
16 | public MatchInfo(String cmd,long memberid,long groupid,Bot bot) {
17 | super();
18 | this.bot = bot;
19 | this.callerid = memberid;
20 | this.groupid = groupid;
21 | this.cmd = cmd;
22 | }
23 | public MatchInfo(String cmd,Member m) {
24 | this(cmd,m.getId(),m.getGroup().getId(),m.getBot());
25 | }
26 |
27 | public MatchInfo(String cmd,User u,boolean temp) {
28 | this(cmd,u.getId(),0,u.getBot());
29 | this.isTemp=temp;
30 | }
31 | public MatchInfo mustMatchCommand() {
32 | mustMatchCommand=true;
33 | return this;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/Matchers.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | import com.khjxiaogu.MiraiSongPlugin.permission.CommandMatcher.PermissionFactory;
24 |
25 | public class Matchers {
26 | static Map subfactories=new HashMap<>();
27 | static {
28 | subfactories.put("admins",is->new MemberPermissionMatcher(WildcardPermission.admins,is));
29 | subfactories.put("friend",is->new FriendMatcher(is));
30 | subfactories.put("admin",is->new MemberPermissionMatcher(WildcardPermission.admin,is));
31 | subfactories.put("owner",is->new MemberPermissionMatcher(WildcardPermission.owner,is));
32 | subfactories.put("member",is->new MemberPermissionMatcher(WildcardPermission.member,is));
33 | subfactories.put("stranger",is->new StrangerMatcher(is));
34 | }
35 | public static PermissionMatcher create(String s,boolean result) {
36 | PermissionFactory pf=subfactories.get(s);
37 | if(pf!=null)
38 | return pf.create(result);
39 | return null;
40 | }
41 | public static PermissionFactory get(String s) {
42 | return subfactories.get(s);
43 | }
44 | public static PermissionFactory getWC(String s) {
45 | return subfactories.get(s);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/MemberPermissionMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | import net.mamoe.mirai.contact.Group;
24 | import net.mamoe.mirai.contact.Member;
25 |
26 | public class MemberPermissionMatcher implements PermissionMatcher {
27 | PermissionResult result;
28 | WildcardPermission perm;
29 | @Override
30 | public PermissionResult match(MatchInfo info) {
31 | if(info.groupid==0)return PermissionResult.UNSPECIFIED;
32 | Group g=info.bot.getGroup(info.groupid);
33 | if(g!=null) {
34 | try {
35 | Member m=g.get(info.callerid);
36 | if(m!=null)
37 | return (perm.isMatch(m.getPermission())?result:PermissionResult.UNSPECIFIED);
38 | }catch(Exception ignored) {}
39 | }
40 | return PermissionResult.UNSPECIFIED;
41 | }
42 |
43 |
44 | public MemberPermissionMatcher(WildcardPermission perm,PermissionResult result) {
45 | this.perm=perm;
46 | this.result = result;
47 | }
48 | public MemberPermissionMatcher(WildcardPermission perm,boolean result) {
49 | this(perm,PermissionResult.valueOf(result));
50 | }
51 |
52 | @Override
53 | public List getValue() {
54 | return Arrays.asList(result.getSymbol()+perm.name());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/NullOperationMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | public final class NullOperationMatcher implements PermissionMatcher {
24 | public static final NullOperationMatcher INSTANCE=new NullOperationMatcher();
25 |
26 | @Override
27 | public PermissionResult match(MatchInfo info) {
28 | return PermissionResult.UNSPECIFIED;
29 | }
30 | @Override
31 | public List getValue() {
32 | return Arrays.asList("#");
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/PermissionMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.List;
21 |
22 | public interface PermissionMatcher {
23 | PermissionResult match(MatchInfo info);
24 |
25 | List getValue();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/PermissionResult.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | public enum PermissionResult {
21 | ALLOW(true,"+"),UNSPECIFIED(true,null),DISALLOW(false,"-");
22 | private final boolean allow;
23 | private final String symbol;
24 | private PermissionResult(boolean allow,String symbol) {
25 | this.allow = allow;
26 | this.symbol=symbol;
27 | }
28 | public String getSymbol() {
29 | return symbol;
30 | }
31 | public static PermissionResult valueOf(boolean b) {
32 | if(b)return ALLOW;
33 | return DISALLOW;
34 | }
35 | public boolean isAllowed() {
36 | return allow;
37 | }
38 | public boolean isForceAllowed() {
39 | return this==ALLOW;
40 | }
41 | public PermissionResult and(PermissionResult oth) {
42 | if(oth==UNSPECIFIED)
43 | return this;
44 | return oth;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/QQMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | public class QQMatcher implements PermissionMatcher {
24 | PermissionResult result;
25 | long qq;
26 | @Override
27 | public PermissionResult match(MatchInfo info) {
28 | if(info.callerid==qq)
29 | return result;
30 | return PermissionResult.UNSPECIFIED;
31 | }
32 | public QQMatcher(long qq,PermissionResult result) {
33 | this.result = result;
34 | this.qq=qq;
35 | }
36 | public QQMatcher(long qq,boolean result) {
37 | this(qq,PermissionResult.valueOf(result));
38 | }
39 | @Override
40 | public List getValue() {
41 | return Arrays.asList(result.getSymbol()+String.valueOf(qq));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/StrangerMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | public class StrangerMatcher implements PermissionMatcher {
24 | PermissionResult result;
25 | @Override
26 | public PermissionResult match(MatchInfo info) {
27 | if(info.isTemp||info.bot.getFriend(info.callerid)==null) {
28 | return result;
29 | }
30 | return PermissionResult.UNSPECIFIED;
31 | }
32 |
33 |
34 | public StrangerMatcher(PermissionResult result) {
35 | this.result = result;
36 | }
37 | public StrangerMatcher(boolean result) {
38 | this(PermissionResult.valueOf(result));
39 | }
40 |
41 | @Override
42 | public List getValue() {
43 | return Arrays.asList(result.getSymbol()+"stranger");
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/khjxiaogu/MiraiSongPlugin/permission/WildcardPermission.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mirai Song Plugin
3 | * Copyright (C) 2021 khjxiaogu
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.khjxiaogu.MiraiSongPlugin.permission;
19 |
20 | import java.util.function.Predicate;
21 |
22 | import net.mamoe.mirai.contact.MemberPermission;
23 |
24 | public enum WildcardPermission {
25 | admin(m->m==MemberPermission.ADMINISTRATOR),
26 | admins(m->m!=MemberPermission.MEMBER),
27 | owner(m->m==MemberPermission.OWNER),
28 | member(m->m==MemberPermission.MEMBER),
29 | members(m->true);
30 | private final Predicate matcher;
31 |
32 | private WildcardPermission(Predicate matcher) {
33 | this.matcher = matcher;
34 | }
35 | public boolean isMatch(MemberPermission mp) {
36 | return matcher.test(mp);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin:
--------------------------------------------------------------------------------
1 | ${project.groupId}.${project.artifactId}.${project.artifactId}
--------------------------------------------------------------------------------
/src/main/resources/config.yml:
--------------------------------------------------------------------------------
1 | ffmpeg_path: "ffmpeg"
2 | silkenc_path: "silk_v3_encoder"
3 | adddefault: true
4 | amrqualityshift: false
5 | amrwb: true
6 | use_custom_ffmpeg_command: false
7 | custom_ffmpeg_command: "ffmpeg -i %input% -ab 23.85k -ar 16000 -ac 1 -acodec amr_wb -y %output%"
8 | enable_local: false
9 | verbose: true
10 | hintsongnotfound: "无法找到歌曲。"
11 | hintcarderror: "分享歌曲失败。"
12 | hintnotemplate: "无法找到卡片。"
13 | hintsourcenotfound: "无法找到来源。"
14 | enableParser: 1
15 | admins:
16 | - 0
17 | neteasecookies: MUSIC_U=;
18 | extracommands:
19 | "#分享":
20 | source: all
21 | card: Share
22 |
23 |
--------------------------------------------------------------------------------