Skip to content

Commit

Permalink
update music and clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
Controllerdestiny committed Dec 24, 2024
1 parent 82ef579 commit c251699
Show file tree
Hide file tree
Showing 27 changed files with 49 additions and 148 deletions.
8 changes: 1 addition & 7 deletions Music/Attributes/SongExt.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.Attributes;
namespace Music.Attributes;

[AttributeUsage(AttributeTargets.Field)]
public class SongExt(string ext) : Attribute
Expand Down
8 changes: 1 addition & 7 deletions Music/Attributes/SongFormat.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.Attributes;
namespace Music.Attributes;

[AttributeUsage(AttributeTargets.Field)]
public class SongFormat(string format) : Attribute
Expand Down
18 changes: 9 additions & 9 deletions Music/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void Initialize()

private async ValueTask ChangeMusicSource(CommandArgs args)
{
if(args.Parameters.Count > 0)
if (args.Parameters.Count > 0)
{
if (args.Parameters[0] == "QQ" || args.Parameters[0] == "网易")
{
Expand Down Expand Up @@ -74,7 +74,7 @@ private async ValueTask DownloadPlay(CommandArgs args)
}
}
else
{
{
await args.EventArgs.Reply("请输入一个正确的歌单ID!");
}
}
Expand All @@ -91,9 +91,9 @@ private async ValueTask QrcodeLogin(CommandArgs args)
{
var (qrsig, buffer) = await Login.GetLoginQrcode();
await args.EventArgs.Reply(MessageBuilder.Group(args.EventArgs.Chain.GroupUin!.Value).Image(buffer).Text("请尽快扫描此二维码60秒后失效"));
await Login.CheckLoginQrcode(qrsig, 120, async (state, token) =>
{
if(state == QQ.Enums.QrcodeLoginType.DONE)
await Login.CheckLoginQrcode(qrsig, 120, async (state, token) =>
{
if (state == QQ.Enums.QrcodeLoginType.DONE)
{
Config.Instance.SetToken(token);
Config.Instance.SaveTo();
Expand All @@ -114,11 +114,11 @@ await Login.CheckLoginQrcode(qrsig, 120, async (state, token) =>
}
});
}
catch(Exception ex)
catch (Exception ex)
{
await args.EventArgs.Reply(ex.Message);
}

}

#region 点歌
Expand Down Expand Up @@ -206,8 +206,8 @@ private async ValueTask ChageMusic(CommandArgs args)
try
{
var music = await MusicTool.GetMusicQQ(musicName, id);
var json = MusicSigner.Sign(new("qq", music.PageUrl, music.PlayUrl, music.Album.Picture, music.Name, string.Join(",", music.Singer.Select(i=>i.Name))));
var json = MusicSigner.Sign(new("qq", music.PageUrl, music.PlayUrl, music.Album.Picture, music.Name, string.Join(",", music.Singer.Select(i => i.Name))));

if (json != null)
await args.EventArgs.Reply(MessageBuilder.Group(args.EventArgs.Chain.GroupUin!.Value).LightApp(json));
}
Expand Down
8 changes: 1 addition & 7 deletions Music/QQ/Enums/QrcodeLoginType.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Enums;
namespace Music.QQ.Enums;

public enum QrcodeLoginType
{
Expand Down
3 changes: 1 addition & 2 deletions Music/QQ/Internal/MusicToken/TokenInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace Music.QQ.Internal.MusicToken;

Expand Down
10 changes: 3 additions & 7 deletions Music/QQ/Internal/Qimei.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Text;
using System.Linq;
using System.Security.Cryptography;
using System.Net.Http;
using Music.QQ.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Music.QQ.Internal;
using System.Security.Cryptography;
using System.Text;

public class QimeiService
{
Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/QuerSong/QuerySongData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Music.QQ.Internal.Search.Song;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.QuerSong;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Req.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal;

Expand Down
1 change: 0 additions & 1 deletion Music/QQ/Internal/Response.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Music.QQ.Internal;

Expand Down
6 changes: 0 additions & 6 deletions Music/QQ/Internal/Search/Body.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/ReqData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/Hotness.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/KSong.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/MV.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/Pay.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/SingerItem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/SongData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/SongFile.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Song/Volume.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search.Song;

Expand Down
5 changes: 0 additions & 5 deletions Music/QQ/Internal/Search/Songs.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Music.QQ.Internal.Search.Song;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Music.QQ.Internal.Search;

Expand Down
2 changes: 1 addition & 1 deletion Music/QQ/Internal/User/HomePageData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma warning disable CS8618 // Naming Styles
namespace Music.QQ.Internal.User;

using System;
using Newtonsoft.Json;
using System;
public partial class HomePageData
{
[JsonProperty("Info")]
Expand Down
22 changes: 11 additions & 11 deletions Music/QQ/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class Login
UseCookies = true
};

private static readonly HttpClient client = new (httpClientHandler)
private static readonly HttpClient client = new(httpClientHandler)
{
DefaultRequestHeaders = { { "Referer", "https://xui.ptlogin2.qq.com/" } }
};
Expand All @@ -49,7 +49,7 @@ public partial class Login
{ "daid", "383" },
{ "pt_3rd_aid", "100497308" }
};

var uri = new Uri(Utils.QueryUri(QrLoginApi, paramsDict));
var res = await client.GetAsync(uri);
var bytes = await res.Content.ReadAsByteArrayAsync();
Expand All @@ -59,7 +59,7 @@ public partial class Login


public static async Task<TokenInfo> GetQQMusicToken(string code, int gtk)
{
{
// 创建匿名类表示JSON对象
var request = new
{
Expand All @@ -76,7 +76,7 @@ public static async Task<TokenInfo> GetQQMusicToken(string code, int gtk)
method = "QQLogin",
param = new
{
code
code
}
}
};
Expand Down Expand Up @@ -151,7 +151,7 @@ public static async Task CheckLoginQrcode(string qrsig, int timeOut, Action<Qrco
{
await timerTask.ConfigureAwait(false);
}
catch (OperationCanceledException) when(cts.IsCancellationRequested)
catch (OperationCanceledException) when (cts.IsCancellationRequested)
{
action(QrcodeLoginType.CANCEL, null);
}
Expand Down Expand Up @@ -196,15 +196,15 @@ private static async Task<QrcodeLoginType> CheckLoginQrcode(string qrsig, Action
};
var url = Utils.QueryUri(CheckQrLoginApi, parameters);
var res = await client.GetAsync(url);
if(!res.IsSuccessStatusCode) throw new HttpRequestException("CheckLoginQrcode failed!");
if (!res.IsSuccessStatusCode) throw new HttpRequestException("CheckLoginQrcode failed!");
var results = await res.Content.ReadAsStringAsync();
var match = RegexHelper.RegexState().Match(results);
if(!match.Success) throw new Exception("CheckLoginQrcode failed!");
if (!match.Success) throw new Exception("CheckLoginQrcode failed!");
var val = match.Groups[1].Value;
var data = val.Split(",").Select(s => s.Trim('\'')).ToArray();
var cookieuri = new Uri(QQMusicApi);
var state = data[0] switch
{
var state = data[0] switch
{
"0" => QrcodeLoginType.DONE,
"65" => QrcodeLoginType.TIMEOUT,
"66" => QrcodeLoginType.SCAN,
Expand All @@ -213,12 +213,12 @@ private static async Task<QrcodeLoginType> CheckLoginQrcode(string qrsig, Action
_ => QrcodeLoginType.OTHER
};
if (state == QrcodeLoginType.DONE)
{
{
var sigx = RegexHelper.RegexSigx().Match(data[2]).Groups[1].Value;
var uin = RegexHelper.RegexUin().Match(data[2]).Groups[1].Value;
var pskey = await CheckSig(uin, sigx);
var code = await Authorize(pskey);
var token = await GetQQMusicToken(code, Utils.Hash33(pskey));
var token = await GetQQMusicToken(code, Utils.Hash33(pskey));
token.Cookie = cookie.GetCookies(cookieuri).ToDictionary(c => c.Name, c => c.Value);
token.P_Skey = pskey;
action(state, token);
Expand Down
Loading

0 comments on commit c251699

Please sign in to comment.