added vknet as submodule

This commit is contained in:
timerix 2022-11-15 18:51:31 +06:00
parent 2028bf5967
commit f3b620756d
11 changed files with 106 additions and 31 deletions

6
.gitmodules vendored
View File

@ -1,3 +1,9 @@
[submodule "DTLib"] [submodule "DTLib"]
path = DTLib path = DTLib
url = https://github.com/Timerix22/DTLib.git url = https://github.com/Timerix22/DTLib.git
[submodule "vknet"]
path = vknet
url = https://github.com/Timerix22/vknet
[submodule "VkNet.AudioBypass"]
path = VkNet.AudioBypass
url = https://github.com/Timerix22/VkNet.AudioBypass

View File

@ -2,5 +2,8 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/DTLib" vcs="Git" />
<mapping directory="$PROJECT_DIR$/VkNet.AudioBypass" vcs="Git" />
<mapping directory="$PROJECT_DIR$/vknet" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -1,13 +1,11 @@
// See https://aka.ms/new-console-template for more information using DTLib.Dtsod;
using VkAudioDownloader; using VkAudioDownloader;
var client = new VkClient(VkClientConfig.FromDtsod(new DtsodV23(File.ReadAllText("config.dtsod"))));
var client = new VkClient(new VkClientConfig()
{
AppId = 51473647,
Login = "aaa",
Password = "aaa"
});
client.Connect(); client.Connect();
Console.WriteLine(client.Api.Token); Console.WriteLine(client.Api.Token);
var audios = client.FindAudio("моя оборона");
foreach (var a in audios)
{
Console.WriteLine(a.Title);
}

View File

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@ -0,0 +1,3 @@
app_id: 0ul;
login: " ";
password: " ";

View File

@ -8,6 +8,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib", "DTLib\DTLib\DTLib.
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib.Dtsod", "DTLib\DTLib.Dtsod\DTLib.Dtsod.csproj", "{F6FA6507-8A20-43F8-9D88-4CB2F049780D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib.Dtsod", "DTLib\DTLib.Dtsod\DTLib.Dtsod.csproj", "{F6FA6507-8A20-43F8-9D88-4CB2F049780D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VkNet", "vknet\VkNet\VkNet.csproj", "{123A7020-4C9B-4F7D-A27A-3002A7B21D4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VkNet.Generators", "vknet\VkNet.Generators\VkNet.Generators.csproj", "{BD698045-3408-40C1-AEEF-865219710EE2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VkNet.AudioBypassService", "VkNet.AudioBypass\VkNet.AudioBypassService\VkNet.AudioBypassService.csproj", "{5650A6DD-602D-49FF-A0B0-DB59BD63EACE}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -30,5 +36,17 @@ Global
{F6FA6507-8A20-43F8-9D88-4CB2F049780D}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6FA6507-8A20-43F8-9D88-4CB2F049780D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6FA6507-8A20-43F8-9D88-4CB2F049780D}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6FA6507-8A20-43F8-9D88-4CB2F049780D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6FA6507-8A20-43F8-9D88-4CB2F049780D}.Release|Any CPU.Build.0 = Release|Any CPU {F6FA6507-8A20-43F8-9D88-4CB2F049780D}.Release|Any CPU.Build.0 = Release|Any CPU
{123A7020-4C9B-4F7D-A27A-3002A7B21D4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{123A7020-4C9B-4F7D-A27A-3002A7B21D4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{123A7020-4C9B-4F7D-A27A-3002A7B21D4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{123A7020-4C9B-4F7D-A27A-3002A7B21D4C}.Release|Any CPU.Build.0 = Release|Any CPU
{BD698045-3408-40C1-AEEF-865219710EE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD698045-3408-40C1-AEEF-865219710EE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD698045-3408-40C1-AEEF-865219710EE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD698045-3408-40C1-AEEF-865219710EE2}.Release|Any CPU.Build.0 = Release|Any CPU
{5650A6DD-602D-49FF-A0B0-DB59BD63EACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5650A6DD-602D-49FF-A0B0-DB59BD63EACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5650A6DD-602D-49FF-A0B0-DB59BD63EACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5650A6DD-602D-49FF-A0B0-DB59BD63EACE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -2,17 +2,18 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DTLib\DTLib.Dtsod\DTLib.Dtsod.csproj" />
<ProjectReference Include="..\DTLib\DTLib\DTLib.csproj" />
<ProjectReference Include="..\VkNet.AudioBypass\VkNet.AudioBypassService\VkNet.AudioBypassService.csproj" />
<!--ProjectReference Include="..\vknet\VkNet.Generators\VkNet.Generators.csproj" />
<ProjectReference Include="..\vknet\VkNet\VkNet.csproj" /!-->
<PackageReference Include="VkNet" Version="1.72.0" /> <PackageReference Include="VkNet" Version="1.72.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DTLib\DTLib.Dtsod\DTLib.Dtsod.csproj" />
<ProjectReference Include="..\DTLib\DTLib\DTLib.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -2,9 +2,15 @@
global using DTLib.Extensions; global using DTLib.Extensions;
using DTLib.Logging; using DTLib.Logging;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using VkNet; using VkNet;
using VkNet.Enums.Filters; using VkNet.Enums.Filters;
using VkNet.Model; using VkNet.Model;
using VkNet.Model.RequestParams;
using VkNet.Utils;
using VkNet.Model.Attachments;
using VkNet.AudioBypassService;
using VkNet.AudioBypassService.Extensions;
namespace VkAudioDownloader; namespace VkAudioDownloader;
@ -20,19 +26,48 @@ public class VkClient : IDisposable
Config = conf; Config = conf;
var services = new ServiceCollection(); var services = new ServiceCollection();
//services.AddSingleton<LoggerService>(); //services.AddSingleton<LoggerService>();
services.AddAudioBypass();
Api = new VkApi(services); Api = new VkApi(services);
} }
public void Connect() public void Connect()
{ {
Api.Authorize(new ApiAuthParams var authParams = new ApiAuthParams
{ {
ApplicationId = Config.AppId, ApplicationId = Config.AppId,
Login = Config.Login,
Password = Config.Password,
Settings = Settings.Audio Settings = Settings.Audio
};
if (Config.Token is not null)
{
Console.WriteLine("authorizing by token");
authParams.AccessToken = Config.Token;
}
else
{
Console.WriteLine("authorizing by login and password");
authParams.Login = Config.Login;
authParams.Password = Config.Password;
}
Api.Authorize(authParams);
}
public VkCollection<Audio> FindAudio(string query, int maxRezults=10) =>
Api.Audio.Search(new AudioSearchParams()
{
Query = query,
Count = maxRezults,
}); });
public Stream DownloadAudio(Audio audio)
{
HttpClient http = new HttpClient();
var stream = http.GetStreamAsync(audio.Url).GetAwaiter().GetResult();
return stream;
}
public void DownloadAudio(Audio audio, TimeSpan lengthLimit)
{
} }
private bool Disposed = false; private bool Disposed = false;

View File

@ -4,28 +4,36 @@ namespace VkAudioDownloader;
public class VkClientConfig public class VkClientConfig
{ {
/// account password
public string Password;
/// account login (email/phone number)
public string Login;
/// vk app id from https://vk.com/apps?act=manage /// vk app id from https://vk.com/apps?act=manage
public ulong AppId; public ulong AppId;
/// account password
public string? Password;
public static VkClientConfig FromDtsod(DtsodV23 dtsod) => /// account login (email/phone number)
new VkClientConfig public string? Login;
/// can be used instead of login and password
public string? Token;
public static VkClientConfig FromDtsod(DtsodV23 dtsod)
{
var config = new VkClientConfig
{ {
Password = dtsod["password"],
Login = dtsod["login"],
AppId = dtsod["app_id"] AppId = dtsod["app_id"]
}; };
if (dtsod.TryGetValue("login", out var login))
config.Login = login;
if (dtsod.TryGetValue("password", out var password))
config.Password = password;
if (dtsod.TryGetValue("token", out var token))
config.Token = token;
return config;
}
public DtsodV23 ToDtsod() => public DtsodV23 ToDtsod() =>
new DtsodV23 new DtsodV23
{ {
{ "password", Password }, { "app_id", AppId },
{ "login", Login }, { "password", Password ?? null },
{ "app_id", AppId } { "login", Login ?? null },
{ "token", Token ?? null }
}; };
} }

1
VkNet.AudioBypass Submodule

@ -0,0 +1 @@
Subproject commit 54bc3198977726bb4a401401001a15a12f326cc7

1
vknet Submodule

@ -0,0 +1 @@
Subproject commit 5989ed812a93dec5d44f60bc50d119a5a46047a1