public static JObject 根据UID获取关注列表(string UID) { 关注列表类 关注列表 = new 关注列表类() { data = new List <关注列表类.账号信息>() }; int pg = 1; int ps; do { JObject JO = JObject.Parse(MMPU.使用WC获取网络内容("https://api.bilibili.com/x/relation/followings?vmid=" + UID + "&pn=" + pg + "&ps=50&order=desc&jsonp=jsonp")); ps = JO["data"]["list"].Count(); foreach (var item in JO["data"]["list"]) { 关注列表.data.Add(new 关注列表类.账号信息() { UID = item["mid"].ToString(), 介绍 = item["sign"].ToString(), 称 = item["uname"].ToString() }); } pg++; }while (ps > 0); return(JObject.FromObject(关注列表)); }
public static string 获取标题(string roomID) { roomID = 获取真实房间号(roomID); if (roomID == null) { InfoLog.InfoPrintf("房间号获取错误", InfoLog.InfoClass.载必要提示); return(null); } string roomHtml; try { roomHtml = MMPU.使用WC获取网络内容("https://api.live.bilibili.com/room/v1/Room/get_info?id=" + roomID); } catch (Exception e) { InfoLog.InfoPrintf(roomID + "获取房间信息失败:" + e.Message, InfoLog.InfoClass.载必要提示); return(null); } //解析结果 try { JObject result = JObject.Parse(roomHtml); string roomName = result["data"]["title"].ToString().Replace(" ", "").Replace("/", "").Replace("\\", "").Replace("\"", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("<", "").Replace(">", "").Replace("|", "").ToString(); InfoLog.InfoPrintf("根据RoomId获取到标题:" + roomName, InfoLog.InfoClass.Debug); return(roomName); } catch (Exception e) { InfoLog.InfoPrintf("视频标题解析失败:" + e.Message, InfoLog.InfoClass.Debug); return(""); } }
public static string 通过UID获取房间号(string uid) { string CacheStr = "byUIDgetROOMID"; if (DataCache.读缓存(CacheStr + uid, 0, out string CacheData)) { return(CacheData); } //发送HTTP请求 string roomHtml; try { roomHtml = MMPU.使用WC获取网络内容("https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=" + uid); } catch (Exception e) { InfoLog.InfoPrintf(uid + " 通过UID获取房间号:" + e.Message, InfoLog.InfoClass.Debug); return(null); } try { var result = JObject.Parse(roomHtml); string roomId = result["data"]["roomid"].ToString(); //InfoLog.InfoPrintf("根据UID获取到房间号:" + roomId, InfoLog.InfoClass.Debug); DataCache.写缓存(CacheStr + uid, roomId); return(roomId); } catch (Exception e) { InfoLog.InfoPrintf(uid + " 通过UID获取房间号:" + e.Message, InfoLog.InfoClass.Debug); return(null); } }
/// <summary> /// 获取BILIBILI直播流下载地址 /// </summary> /// <param name="roomid">房间号</param> /// <param name="R">是否为重试</param> /// <returns></returns> public static string 载地址(string roomid) { roomid = 获取真实房间号(roomid); if (roomid == null) { InfoLog.InfoPrintf("房间号获取错误", InfoLog.InfoClass.Debug); return(null); } string resultString; try { resultString = MMPU.使用WC获取网络内容("https://api.live.bilibili.com/room/v1/Room/playUrl?cid=" + roomid + "&otype=json&qn=10000&platform=web"); } catch (Exception e) { InfoLog.InfoPrintf("发送解析请求失败:" + e.Message, InfoLog.InfoClass.Debug); return(""); } //解析结果使用最高清晰度 try { MMPU.判断网络路径是否存在 判断文件是否存在 = new MMPU.判断网络路径是否存在(); string BBBC = ""; BBBC = (JObject.Parse(resultString)["data"]["durl"][0]["url"].ToString()); //BBBC = (JObject.Parse(resultString)["data"]["durl"][0]["url"].ToString() + "&platform=web").Replace("&pt=", "&pt=web") + "&pSession=" + Guid.NewGuid(); if (!判断文件是否存在.判断(BBBC, "bilibili", roomid)) { InfoLog.InfoPrintf("请求的开播房间当前推流数据为空,推测还未开播,等待数据流...:", InfoLog.InfoClass.Debug); try { if ((JObject.Parse(resultString)["message"].ToString() == "房间已加密")) { InfoLog.InfoPrintf("房间已加密", InfoLog.InfoClass.载必要提示); return(""); } } catch (Exception) { } BBBC = (JObject.Parse(resultString)["data"]["durl"][1]["url"].ToString()); } DataCache.BilibiliApiCount++; return(BBBC); } catch (Exception e) { InfoLog.InfoPrintf("视频流地址解析失败:" + e.Message, InfoLog.InfoClass.系统错误信息); return(""); } }
public static RoomInit.RoomInfo GetRoomInfo(string originalRoomId) { string roomHtml; try { roomHtml = MMPU.使用WC获取网络内容("https://api.live.bilibili.com/room/v1/Room/get_info?id=" + originalRoomId); } catch (Exception e) { InfoLog.InfoPrintf(originalRoomId + "获取房间信息失败:" + e.Message, InfoLog.InfoClass.Debug); return(null); } //解析返回结果 try { JObject result = JObject.Parse(roomHtml); string uid = result["data"]["uid"].ToString(); if (result["data"]["room_id"].ToString() != originalRoomId) { for (int i = 0; i < RoomList.Count(); i++) { if (RoomList[i].房间号 == originalRoomId) { RoomList[i].房间号 = result["data"]["room_id"].ToString(); break; } } } var roominfo = new RoomInit.RoomInfo { 房间号 = result["data"]["room_id"].ToString(), 标题 = result["data"]["title"].ToString().Replace(" ", "").Replace("/", "").Replace("\\", "").Replace("\"", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("<", "").Replace(">", "").Replace("|", ""), 直播状态 = result["data"]["live_status"].ToString() == "1" ? true : false, UID = result["data"]["uid"].ToString(), 直播开始时间 = result["data"]["live_time"].ToString(), 平台 = "bilibili" }; InfoLog.InfoPrintf("获取到房间信息:" + roominfo.UID + " " + (roominfo.直播状态 ? "已开播" : "未开播") + " " + (roominfo.直播状态 ? "开播时间:" + roominfo.直播开始时间 : ""), InfoLog.InfoClass.Debug); DataCache.BilibiliApiCount++; return(roominfo); } catch (Exception e) { InfoLog.InfoPrintf(originalRoomId + "房间信息解析失败:" + e.Message, InfoLog.InfoClass.Debug); return(null); } }
public static string 获取真实房间号(string roomID) { string CacheStr = "byROOMIDgetTRUEroomid"; if (DataCache.读缓存(CacheStr + roomID, 0, out string CacheData)) { return(CacheData); } try { if (int.Parse(roomID) > 10000) { DataCache.写缓存(CacheStr + roomID, roomID); return(roomID); } } catch (Exception) { } string roomHtml; try { roomHtml = MMPU.使用WC获取网络内容("https://api.live.bilibili.com/room/v1/Room/get_info?id=" + roomID); } catch (Exception e) { InfoLog.InfoPrintf(roomID + "获取房间信息失败:" + e.Message, InfoLog.InfoClass.Debug); return(null); } //从返回结果中提取真实房间号 try { JObject result = JObject.Parse(roomHtml); //string live_status = result["data"]["live_status"].ToString(); //if (live_status != "1") //{ // return "-1"; //} string roomid = result["data"]["room_id"].ToString(); DataCache.写缓存(CacheStr + roomID, roomid); return(roomid); } catch { return(roomID); } }