Skip to content

Commit

Permalink
将Desktop原先和Core交互的形式从http请求修改为直接函数访问
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jan 11, 2025
1 parent dfbd7ec commit a06b38c
Show file tree
Hide file tree
Showing 18 changed files with 619 additions and 301 deletions.
23 changes: 23 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,29 @@ public bool _ReconnectAnchorReStream
}
}


private static string LocalHTTPMode = "false";
/// <summary>
/// 本地模式时,是否使用HTTP进行请求
/// 默认值:false
/// </summary>
public bool _LocalHTTPMode
{
get
{
return bool.Parse(LocalHTTPMode);
}
set
{
if (value.ToString() != LocalHTTPMode)
{
LocalHTTPMode = value.ToString();
OnPropertyChanged();
ModifyConfig(value);
}
}
}

}
#endregion
}
Expand Down
35 changes: 35 additions & 0 deletions Core/RuntimeObject/Login.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Masuit.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.RuntimeObject
{
public static class Login
{
public static async Task<string> get_login_urlAsync()
{
string URL = string.Empty;
int waitTime = 0;
while (waitTime <= 3000)
{
if (System.IO.File.Exists(Core.Config.Core_RunConfig._QrUrl))
{
FileInfo fi = new FileInfo(Core.Config.Core_RunConfig._QrUrl);
using (FileStream fs = fi.OpenRead())
{
URL = fs.ReadAllText(Encoding.UTF8);
}
}
else
{
await Task.Delay(1000);
waitTime += 1000;
}
}
return URL;
}
}
}
239 changes: 239 additions & 0 deletions Core/RuntimeObject/RoomInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Core.Network.Methods;
using Masuit.Tools;
using Masuit.Tools.Hardware;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand All @@ -20,6 +22,243 @@ namespace Core.RuntimeObject
public class _Room
{
private static ConcurrentDictionary<long, RoomCardClass> roomInfos = new ConcurrentDictionary<long, RoomCardClass>();

/// <summary>
/// 总览,用于输出WEB或者Destop显示内容
/// </summary>
public class Overview
{
public static CardData GetCardOverview(int quantity = 0,int page = 0, _Room.SearchType type=_Room.SearchType.All,string screen_name = "")
{
try
{
CardData completeRoomInfoRes = new CardData();
var roomList = _Room.GetCardListClone(type, screen_name);
completeRoomInfoRes.total = roomList.Count;
if (quantity == 0)
{
foreach (var room in roomList)
{
CardData.CompleteInfo completeInfo = new CardData.CompleteInfo();
completeInfo.uid = room.Value.UID;
completeInfo.roomId = room.Value.RoomId;
completeInfo.userInfo = new()
{
isAutoRec = room.Value.IsAutoRec,
description = room.Value.Description,
isRecDanmu = room.Value.IsRecDanmu,
isRemind = room.Value.IsRemind,
name = room.Value.Name,
sex = room.Value.sex.Value,
sign = room.Value.sign.Value,
uid = room.Value.UID,
appointmentRecord = room.Value.AppointmentRecord,
};
completeInfo.roomInfo = new CardData.CompleteInfo.RoomInfo()
{
areaName = room.Value.area_v2_name.Value,
attention = room.Value.attention.Value,
coverFromUser = room.Value.cover_from_user.Value,
face = room.Value.face.Value,
keyFrame = room.Value.keyframe.Value,
liveStatus = room.Value.live_status.Value == 1 ? true : false,
liveTime = room.Value.live_time.Value,
roomId = room.Value.RoomId,
shortId = room.Value.short_id.Value,
tags = room.Value.tags.Value,
title = room.Value.Title.Value,
url = $"https://live.bilibili.com/{room.Value.RoomId}",
specialType = room.Value.special_type.Value,
};

completeInfo.taskStatus = new CardData.CompleteInfo.TaskStatus()
{
downloadSize = room.Value.DownInfo.DownloadSize,
endTime = room.Value.DownInfo.EndTime,
isDownload = room.Value.DownInfo.IsDownload,
startTime = room.Value.DownInfo.StartTime,
title = room.Value.Title.Value,
status = room.Value.DownInfo.Status,
downloadRate = room.Value.DownInfo.RealTimeDownloadSpe
};
completeRoomInfoRes.completeInfoList.Add(completeInfo);
}
}
else
{
for (int i = page * quantity - quantity; i < roomList.Count && i < page * quantity; i++)
{
CardData.CompleteInfo completeInfo = new CardData.CompleteInfo();
completeInfo.uid = roomList.ElementAt(i).Value.UID;
completeInfo.roomId = roomList.ElementAt(i).Value.RoomId;
completeInfo.userInfo = new()
{
isAutoRec = roomList.ElementAt(i).Value.IsAutoRec,
description = roomList.ElementAt(i).Value.Description,
isRecDanmu = roomList.ElementAt(i).Value.IsRecDanmu,
isRemind = roomList.ElementAt(i).Value.IsRemind,
name = roomList.ElementAt(i).Value.Name,
sex = roomList.ElementAt(i).Value.sex.Value,
sign = roomList.ElementAt(i).Value.sign.Value,
uid = roomList.ElementAt(i).Value.UID,
appointmentRecord = roomList.ElementAt(i).Value.AppointmentRecord
};
completeInfo.roomInfo = new CardData.CompleteInfo.RoomInfo()
{
areaName = roomList.ElementAt(i).Value.area_v2_name.Value,
attention = roomList.ElementAt(i).Value.attention.Value,
coverFromUser = roomList.ElementAt(i).Value.cover_from_user.Value,
face = roomList.ElementAt(i).Value.face.Value,
keyFrame = roomList.ElementAt(i).Value.keyframe.Value,
liveStatus = roomList.ElementAt(i).Value.live_status.Value == 1 ? true : false,
liveTime = roomList.ElementAt(i).Value.live_time.Value,
roomId = roomList.ElementAt(i).Value.RoomId,
shortId = roomList.ElementAt(i).Value.short_id.Value,
tags = roomList.ElementAt(i).Value.tags.Value,
title = roomList.ElementAt(i).Value.Title.Value,
url = $"https://live.bilibili.com/{roomList.ElementAt(i).Value.RoomId}"
};
completeInfo.taskStatus = new CardData.CompleteInfo.TaskStatus()
{
downloadSize = roomList.ElementAt(i).Value.DownInfo.DownloadSize,
endTime = roomList.ElementAt(i).Value.DownInfo.EndTime,
isDownload = roomList.ElementAt(i).Value.DownInfo.IsDownload,
startTime = roomList.ElementAt(i).Value.DownInfo.StartTime,
title = roomList.ElementAt(i).Value.Title.Value,
status = roomList.ElementAt(i).Value.DownInfo.Status,
downloadRate = roomList.ElementAt(i).Value.DownInfo.RealTimeDownloadSpe,
isDanma = false
};

if (roomList.ElementAt(i).Value.DownInfo.LiveChatListener != null && roomList.ElementAt(i).Value.DownInfo.LiveChatListener.Register.Contains("DetectRoom_LiveStart"))
{
completeInfo.taskStatus.isDanma = true;
}

completeRoomInfoRes.completeInfoList.Add(completeInfo);
}
}
roomList.Clear();
roomList = null;
return completeRoomInfoRes;
}
catch (Exception)
{
return null;
}
}

public class CardData
{
public int total { get; set; } = 0;
public List<CompleteInfo> completeInfoList { get; set; } = new();
public class CompleteInfo
{
public long uid { get; set; }
public long roomId { get; set; }
public UserInfo userInfo { get; set; } = new();
public RoomInfo roomInfo { get; set; } = new();
public TaskStatus taskStatus { get; set; } = new();
public class UserInfo
{
public string name { get; set; }
public string description { get; set; }
public long uid { get; set; }
public bool isAutoRec { get; set; }
public bool isRemind { get; set; }
public bool isRecDanmu { get; set; }
public string sex { get; set; }
public string sign { get; set; }
public bool appointmentRecord { get; set; }
}
public class RoomInfo
{
public long roomId { get; set; }
public string title { get; set; }
public int attention { get; set; }
public long liveTime { get; set; }
public bool liveStatus { get; set; }
public int shortId { get; set; }
public string areaName { get; set; }
public string face { get; set; }
public string tags { get; set; }
public string coverFromUser { get; set; }
public string keyFrame { get; set; }
public string url { get; set; }
public int specialType { get; set; }

}
public class TaskStatus
{
public bool isDownload { get; set; }
public long downloadSize { get; set; }
public double downloadRate { get; set; }
public DownloadStatus status { get; set; }
public DateTime startTime { get; set; }
public DateTime endTime { get; set; }
public string title { get; set; }
public bool isDanma { get; set; }
}
}
}

public static (int MonitoringCount, int LiveCount, int RecCount) GetRoomStatisticsOverview()
{
var roomList = _Room.GetCardListClone(_Room.SearchType.All);
(int MonitoringCount, int LiveCount, int RecCount) count = new();
count.MonitoringCount = roomList.Count;
count.LiveCount = roomList.Where(x => x.Value.live_status.Value == 1).Count();
count.RecCount = roomList.Where(x => x.Value.DownInfo.Status == RoomCardClass.DownloadStatus.Downloading || x.Value.DownInfo.Status == RoomCardClass.DownloadStatus.Standby).Count();
return count;
}
}

/// <summary>
/// 批量删除房间
/// </summary>
/// <param name="uids">使用半角逗号分割的UID符串</param>
/// <returns></returns>
public static List<(long key, bool State, string Message)> BatchDeleteRooms(string uids)
{
List<(long key, bool State, string Message)> list = new();
string[] uid = uids.Split(',');
foreach (var item in uid)
{
if (long.TryParse(item, out long u))
{
(long key, bool State, string Message) Info = Core.RuntimeObject._Room.DelRoom(u, 0, true);
list.Add(Info);
}

}
return list;
}

/// <summary>
/// 批量增加房间
/// </summary>
/// <param name="uids">使用半角逗号分割的UID字符串</param>
/// <param name="auto_rec"></param>
/// <param name="remind"></param>
/// <param name="rec_danmu"></param>
/// <returns></returns>
public static List<(long key, int State, string Message)> BatchAddRooms(string uids,bool auto_rec=false, bool remind=false,bool rec_danmu=false)
{
List<(long key, int State, string Message)> list = new();
string[] uid = uids.Split(',');

foreach (var item in uid)
{
if (long.TryParse(item, out long u))
{
(long key, int State, string Message) Info = Core.RuntimeObject._Room.AddRoom(auto_rec, remind, rec_danmu, u, 0, true);
list.Add(Info);
}
}
return list;
}


/// <summary>
/// 通过UID获取房间卡
/// </summary>
Expand Down
47 changes: 47 additions & 0 deletions Core/Tools/SystemResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,60 @@
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static Core.Tools.SystemResource.GetHDDInfo;
using static Core.Tools.SystemResource.GetMemInfo;

namespace Core.Tools
{
public class SystemResource
{
public static class Overview
{
public static SystemResourceClass GetOverview()
{
SystemResourceClass systemResourceClass = new();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
systemResourceClass = new()
{
HDDInfo = GetHDDInfo.GetLinux(),
Memory = GetMemInfo.GetLiunx(),
Platform = "Linux"
};
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
systemResourceClass = new()
{
Memory = GetMemInfo.GetWindows(),
Platform = "Windows"
};
string DriveLetter = Path.GetFullPath(Core.Config.Core_RunConfig._RecFileDirectory)[..1];
systemResourceClass.HDDInfo = GetHDDInfo.GetWindows(DriveLetter);
}
return systemResourceClass;
}
public class SystemResourceClass
{
/// <summary>
/// 平台
/// </summary>
public string Platform { set; get; }
/// <summary>
/// 内存
/// </summary>
public MemInfo Memory { set; get; }
/// <summary>
/// 硬盘信息
/// </summary>
public List<HDDInfo> HDDInfo { set; get; }
}
}


public class GetHDDInfo
{
public static List<HDDInfo> GetWindows(string DriveLetter)
Expand Down
Loading

0 comments on commit a06b38c

Please sign in to comment.