Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
withsalt committed Apr 25, 2024
2 parents 9e85785 + 46fa560 commit fab3254
Show file tree
Hide file tree
Showing 112 changed files with 1,226 additions and 734 deletions.
20 changes: 20 additions & 0 deletions src/Bilibili.AspNetCore.Apis/Bilibili.AspNetCore.Apis.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<Version>4.0.2</Version>
<Description>Bilibili API封装。</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="SkiaSharp.QrCode" Version="0.7.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Bilibili.AspNetCore.Apis/Constants/CacheKeyConstant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bilibili.AspNetCore.Apis.Constants
{
class CacheKeyConstant
{
public const string COOKIE_KEY = "COOKIE_KEY";

public const string LOGIN_STATUS_CACHE_KEY = "PAGE_STATUS_CACHE_KEY";
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using BilibiliAutoLiver.Services;
using BilibiliAutoLiver.Services.Interface;
using Bilibili.AspNetCore.Apis.Interface;
using Bilibili.AspNetCore.Apis.Services;
using Microsoft.Extensions.DependencyInjection;

namespace BilibiliAutoLiver.DependencyInjection
namespace Bilibili.AspNetCore.Apis.DependencyInjection
{
public static class RegisteBilibiliServices
public static class RegisteBilibiliApis
{
public static IServiceCollection AddBilibiliServices(this IServiceCollection services)
public static IServiceCollection AddBilibiliApis(this IServiceCollection services)
{
//Cookie模块
services.AddSingleton<IBilibiliCookieService, BilibiliCookieService>();
//Http请求相关
services.AddTransient<IHttpClientService, HttpClientService>();
//账号
services.AddTransient<IBilibiliAccountService, BilibiliAccountService>();
services.AddTransient<IBilibiliAccountApiService, BilibiliAccountApiService>();
//直播的API
services.AddTransient<IBilibiliLiveApiService, BilibiliLiveApiService>();
//推流相关
services.AddTransient<IPushStreamServiceV1, PushStreamServiceV1>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Net.Http;

namespace BilibiliAutoLiver.Exceptions
namespace Bilibili.AspNetCore.Apis.Exceptions
{
public class ApiRequestException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BilibiliAutoLiver.Exceptions
namespace Bilibili.AspNetCore.Apis.Exceptions
{
public class CookieException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BilibiliAutoLiver.Exceptions
namespace Bilibili.AspNetCore.Apis.Exceptions
{
public class CookieExpiredException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using BilibiliAutoLiver.Models;
using BilibiliAutoLiver.Models.Base;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Bilibili.AspNetCore.Apis.Models;
using Bilibili.AspNetCore.Apis.Models.Base;

namespace BilibiliAutoLiver.Services.Interface
namespace Bilibili.AspNetCore.Apis.Interface
{
public interface IBilibiliAccountService
public interface IBilibiliAccountApiService
{
/// <summary>
/// 获取用户信息
Expand All @@ -24,6 +24,14 @@ public interface IBilibiliAccountService
/// <returns></returns>
Task<UserInfo> LoginByQrCode();

/// <summary>
/// 尝试获取二维码扫描登录状态
/// 如果能获取到,表示正在进行二维码扫码登录
/// </summary>
/// <param name="loginStatus"></param>
/// <returns></returns>
bool TryGetQrCodeLoginStatus(out QrCodeLoginStatus loginStatus);

/// <summary>
/// 生成登录二维码
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using BilibiliAutoLiver.Config;
using Bilibili.AspNetCore.Apis.Models;

namespace BilibiliAutoLiver.Services.Interface
namespace Bilibili.AspNetCore.Apis.Interface
{
public interface IBilibiliCookieService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using BilibiliAutoLiver.Models;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Bilibili.AspNetCore.Apis.Models;

namespace BilibiliAutoLiver.Services.Interface
namespace Bilibili.AspNetCore.Apis.Interface
{
public interface IBilibiliLiveApiService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BilibiliAutoLiver.Models.Base;
using BilibiliAutoLiver.Models.Enums;
using System.Net.Http;
using System.Net.Http;
using System.Threading.Tasks;
using Bilibili.AspNetCore.Apis.Models.Base;
using Bilibili.AspNetCore.Apis.Models.Enums;

namespace BilibiliAutoLiver.Services.Interface
namespace Bilibili.AspNetCore.Apis.Interface
{
public interface IHttpClientService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.ObjectModel;
using System.Net.Http.Headers;

namespace BilibiliAutoLiver.Models.Base
namespace Bilibili.AspNetCore.Apis.Models.Base
{
public class ResultModel<T> where T : class
{
Expand Down
8 changes: 8 additions & 0 deletions src/Bilibili.AspNetCore.Apis/Models/ConfirmRefreshModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Bilibili.AspNetCore.Apis.Models
{
public class ConfirmRefreshModel
{
public string csrf { get; set; }
public string refresh_token { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Bilibili.AspNetCore.Apis/Models/CookieInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bilibili.AspNetCore.Apis.Models
{
public class CookieInfo
{
public bool refresh { get; set; }

public long timestamp { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BilibiliAutoLiver.Config
namespace Bilibili.AspNetCore.Apis.Models
{
public class CookiesConfig
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BilibiliAutoLiver.Config
namespace Bilibili.AspNetCore.Apis.Models
{
public class CookiesJson
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BilibiliAutoLiver.Models.Enums
namespace Bilibili.AspNetCore.Apis.Models.Enums
{
public enum BodyFormat
{
Expand Down
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 BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class HeartBeat
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class LiveAreaItem
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class LiveRoomInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class ProtocolsItem
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class LoginStatusCacheInfo
public class QrCodeLoginStatus
{
public bool IsLogged { get; set; }

Expand Down
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 BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class QrCodeScanResult
{
Expand Down
25 changes: 25 additions & 0 deletions src/Bilibili.AspNetCore.Apis/Models/QrCodeUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.IO;
using SkiaSharp;
using SkiaSharp.QrCode.Image;

namespace Bilibili.AspNetCore.Apis.Models
{
public class QrCodeUrl
{
public string qrcode_key { get; set; }

public string url { get; set; }

public byte[] GetBytes()
{
if (string.IsNullOrWhiteSpace(this.url)) throw new ArgumentNullException("url");
var qrCode = new SkiaSharp.QrCode.Image.QrCode(this.url, new Vector2Slim(512, 512), SKEncodedImageFormat.Png);
using (MemoryStream ms = new MemoryStream())
{
qrCode.GenerateImage(ms, true, SkiaSharp.QrCode.ECCLevel.M);
return ms.ToArray();
}
}
}
}
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 BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class RefreshCookieModel
{
Expand Down
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 BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class RefreshCookieResult
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class RoomPlayInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class Rtmp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
public class StartLiveInfo
{
Expand Down
9 changes: 9 additions & 0 deletions src/Bilibili.AspNetCore.Apis/Models/StopLiveInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bilibili.AspNetCore.Apis.Models
{
public class StopLiveInfo
{
public int change { get; set; }

public string status { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text;

namespace BilibiliAutoLiver.Models
namespace Bilibili.AspNetCore.Apis.Models
{
/// <summary>
/// 账户信息
Expand Down
Loading

0 comments on commit fab3254

Please sign in to comment.