Skip to content

Commit

Permalink
2.0.2.1c
Browse files Browse the repository at this point in the history
修复大部分播放和下载不断重连的问题
加密保存cookie和修改为枚举方式判断登陆状态
增加第三方库相关说明
  • Loading branch information
CHKZL committed Mar 20, 2020
1 parent b42a7ee commit c41b10d
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 66 deletions.
2 changes: 2 additions & 0 deletions Auxiliary/Auxiliary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Reference Include="System.Drawing.Design" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -95,6 +96,7 @@
<ItemGroup>
<Compile Include="bilibili.cs" />
<Compile Include="Downloader.cs" />
<Compile Include="Encryption.cs" />
<Compile Include="InfoLogger.cs" />
<Compile Include="MMPU.cs" />
<Compile Include="Program.cs" />
Expand Down
29 changes: 20 additions & 9 deletions Auxiliary/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Auxiliary
{
public class Downloader
{

public DownIofoData DownIofo = new DownIofoData();
public class DownIofoData
{
Expand All @@ -33,10 +33,12 @@ public class DownIofoData
public string 标题 { set; get; }
public bool 播放状态 { set; get; }
public bool 是否是播放任务 { set; get; }
public string 重连文件路径 { set; get; }
}
public string Start(string 开始后显示的备注)
{
int a = 0;

DownIofo.WC = new WebClient();
DownIofo.WC.Headers.Add("Accept: */*");
DownIofo.WC.Headers.Add("User-Agent: " + Ver.UA);
Expand Down Expand Up @@ -96,15 +98,21 @@ public string Start(string 开始后显示的备注)
Thread.Sleep(1000);
if (bilibili.根据房间号获取房间信息.是否正在直播(DownIofo.房间_频道号))
{

a++;
if (判断文件是否存在.判断(DownIofo.下载地址, DownIofo.平台))
{
DownIofo.下载地址 = bilibili.根据房间号获取房间信息.下载地址(DownIofo.房间_频道号);
//DownIofo.下载地址 = bilibili.根据房间号获取房间信息.下载地址(DownIofo.房间_频道号);
break;
}
else
{
if(a>5)
DownIofo.下载地址 = bilibili.根据房间号获取房间信息.下载地址(DownIofo.房间_频道号);
if (判断文件是否存在.判断(DownIofo.下载地址, DownIofo.平台))
{
break;
}
if (a>5)
{
DownIofo.下载状态 = false;
DownIofo.备注 = "该房间未推送直播流";
Expand All @@ -124,7 +132,8 @@ public string Start(string 开始后显示的备注)
}
}
DownIofo.开始时间 = Convert.ToInt32((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
DownIofo.WC.DownloadFileAsync(new Uri(DownIofo.下载地址), DownIofo.文件保存路径);
//DownIofo.WC.DownloadFileAsync(new Uri(DownIofo.下载地址), DownIofo.文件保存路径);
DownIofo.WC.DownloadFileTaskAsync(new Uri(DownIofo.下载地址), DownIofo.文件保存路径);
DownIofo.备注 = 开始后显示的备注;
DownIofo.下载状态 = true;
return DownIofo.文件保存路径;
Expand Down Expand Up @@ -174,11 +183,11 @@ public static Downloader 新建下载对象(string 平台, string 唯一码, str
};
if(!是否保存)
{
int 优雅 = new Random().Next(1000, 9999);
下载对象.DownIofo.文件保存路径 = AppDomain.CurrentDomain.BaseDirectory + "tmp\\LiveCache\\" + 下载对象.DownIofo.标题 + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + 优雅 + ".flv";
int 随机值 = new Random().Next(1000, 9999);
下载对象.DownIofo.文件保存路径 = AppDomain.CurrentDomain.BaseDirectory + "tmp\\LiveCache\\" + 下载对象.DownIofo.标题 + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + 随机值 + ".flv";
if (File.Exists(下载对象.DownIofo.文件保存路径))
{
下载对象.DownIofo.文件保存路径 = AppDomain.CurrentDomain.BaseDirectory + "tmp\\LiveCache\\" + 下载对象.DownIofo.标题 + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + (优雅)+1 + ".flv";
下载对象.DownIofo.文件保存路径 = AppDomain.CurrentDomain.BaseDirectory + "tmp\\LiveCache\\" + 下载对象.DownIofo.标题 + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + (随机值)+1 + ".flv";
}

}
Expand Down Expand Up @@ -225,13 +234,13 @@ private void 下载完成事件(object sender, AsyncCompletedEventArgs e)
}
else
{
if (bilibili.根据房间号获取房间信息.是否正在直播(DownIofo.房间_频道号)&& DownIofo.是否保存)
if (bilibili.根据房间号获取房间信息.是否正在直播(DownIofo.房间_频道号) && DownIofo.是否保存)
{
switch (DownIofo.平台)
{
case "bilibili":
{
Downloader 下载对象 = Downloader.新建下载对象(DownIofo.平台, DownIofo.房间_频道号, bilibili.根据房间号获取房间信息.获取标题(DownIofo.房间_频道号), Guid.NewGuid().ToString(), bilibili.根据房间号获取房间信息.下载地址(DownIofo.房间_频道号), "重连", false);
Downloader 下载对象 = Downloader.新建下载对象(DownIofo.平台, DownIofo.房间_频道号, bilibili.根据房间号获取房间信息.获取标题(DownIofo.房间_频道号), Guid.NewGuid().ToString(), bilibili.根据房间号获取房间信息.下载地址(DownIofo.房间_频道号), "重连", DownIofo.是否保存);
if (!下载对象.DownIofo.下载状态)
{
下载对象.DownIofo.备注 = "该房间当前状态不能获取到直播流";
Expand All @@ -245,6 +254,8 @@ private void 下载完成事件(object sender, AsyncCompletedEventArgs e)
Thread.Sleep(1000);
if (下载对象.DownIofo.已下载大小bit > 1000)
{
// DownIofo.重连文件路径 = 下载对象.DownIofo.文件保存路径;
//DownIofo = 下载对象.DownIofo;
DownIofo.下载状态 = true;
return;
}
Expand Down
137 changes: 137 additions & 0 deletions Auxiliary/Encryption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Auxiliary
{
public static class Encryption
{
#region AES 加密解密

/// <summary>
/// AES加密
/// </summary>
/// <param name="source">待加密字段</param>
/// <param name="keyVal">密钥值</param>
/// <param name="ivVal">加密辅助向量</param>
/// <returns></returns>
public static string AesStr(this string source, string keyVal, string ivVal)
{
var encoding = Encoding.UTF8;
byte[] btKey = keyVal.FormatByte(encoding);
byte[] btIv = ivVal.FormatByte(encoding);
byte[] byteArray = encoding.GetBytes(source);
string encrypt;
Rijndael aes = Rijndael.Create();
using (MemoryStream mStream = new MemoryStream())
{
using (CryptoStream cStream = new CryptoStream(mStream, aes.CreateEncryptor(btKey, btIv), CryptoStreamMode.Write))
{
cStream.Write(byteArray, 0, byteArray.Length);
cStream.FlushFinalBlock();
encrypt = Convert.ToBase64String(mStream.ToArray());
}
}
aes.Clear();
return encrypt;
}

/// <summary>
/// AES解密
/// </summary>
/// <param name="source">待加密字段</param>
/// <param name="keyVal">密钥值</param>
/// <param name="ivVal">加密辅助向量</param>
/// <returns></returns>
public static string UnAesStr(this string source, string keyVal, string ivVal)
{
var encoding = Encoding.UTF8;
byte[] btKey = keyVal.FormatByte(encoding);
byte[] btIv = ivVal.FormatByte(encoding);
byte[] byteArray = Convert.FromBase64String(source);
string decrypt;
Rijndael aes = Rijndael.Create();
using (MemoryStream mStream = new MemoryStream())
{
using (CryptoStream cStream = new CryptoStream(mStream, aes.CreateDecryptor(btKey, btIv), CryptoStreamMode.Write))
{
cStream.Write(byteArray, 0, byteArray.Length);
cStream.FlushFinalBlock();
decrypt = encoding.GetString(mStream.ToArray());
}
}
aes.Clear();
return decrypt;
}
#endregion
#region BASE64 加密解密

/// <summary>
/// BASE64 加密
/// </summary>
/// <param name="source">待加密字段</param>
/// <returns></returns>
public static string Base64(this string source)
{
var btArray = Encoding.UTF8.GetBytes(source);
return Convert.ToBase64String(btArray, 0, btArray.Length);
}

/// <summary>
/// BASE64 解密
/// </summary>
/// <param name="source">待解密字段</param>
/// <returns></returns>
public static string UnBase64(this string source)
{
var btArray = Convert.FromBase64String(source);
return Encoding.UTF8.GetString(btArray);
}

#endregion

#region 内部方法

/// <summary>
/// 转成数组
/// </summary>
private static byte[] Str2Bytes(this string source)
{
source = source.Replace(" ", "");
byte[] buffer = new byte[source.Length / 2];
for (int i = 0; i < source.Length; i += 2) buffer[i / 2] = Convert.ToByte(source.Substring(i, 2), 16);
return buffer;
}

/// <summary>
/// 转换成字符串
/// </summary>
private static string Bytes2Str(this IEnumerable<byte> source, string formatStr = "{0:X2}")
{
StringBuilder pwd = new StringBuilder();
foreach (byte btStr in source) { pwd.AppendFormat(formatStr, btStr); }
return pwd.ToString();
}

private static byte[] FormatByte(this string strVal, Encoding encoding)
{
return encoding.GetBytes(strVal.Base64().Substring(0, 16).ToUpper());
}

/// <summary>
/// HashAlgorithm 加密统一方法
/// </summary>
private static string HashAlgorithmBase(HashAlgorithm hashAlgorithmObj, string source, Encoding encoding)
{
byte[] btStr = encoding.GetBytes(source);
byte[] hashStr = hashAlgorithmObj.ComputeHash(btStr);
return hashStr.Bytes2Str();
}

#endregion
}
}
85 changes: 48 additions & 37 deletions Auxiliary/MMPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using Newtonsoft.Json.Linq;
using System.Windows.Forms;

namespace Auxiliary
{
Expand All @@ -25,7 +26,7 @@ public class MMPU
public static string 直播缓存目录 ="";
public static int 直播更新时间 = 40;
public static string 下载储存目录 = "";
public static string 版本号 = "2.0.2.1b";
public static string 版本号 = "2.0.2.1c";
public static string[] 不检测的版本号 = {"2.0.2.0b", "2.0.2.0c" , "2.0.2.0d" , "2.0.2.0e" , "2.0.2.0f", "2.0.2.0g", "2.0.2.0" };
public static bool 第一次打开播放窗口 = true;
public static int 默认音量= 0;
Expand All @@ -49,6 +50,8 @@ public class MMPU
public static string UID = "";
public static string BiliUserFile= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BiliUser.ini");
public static int 播放缓冲时长 = 3;
public static string AESKey="rzqIzYmDQFqQmWfr";
public static string AESVal = "itkIBBs5JdCLKqpP";

public static string 房间状态MD5值 = string.Empty;
public static void 修改默认音量设置(int A)
Expand Down Expand Up @@ -120,6 +123,8 @@ public static string 写ini配置文件(string 节点, string 项目,string 值,
bilibili.BiliUser.Write(节点, 项目, , 路径);
return null;
}


/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -215,55 +220,61 @@ public static void 更新网络房间缓存()
int A = 1;
new Thread(new ThreadStart(delegate
{
var wc = new WebClient();
wc.Headers.Add("Accept: */*");
wc.Headers.Add("Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4");
byte[] roomHtml = wc.DownloadData("https://gitee.com/SYXM/vdb/raw/master/json/list.json");
var result = JObject.Parse(Encoding.UTF8.GetString(roomHtml));

foreach (var item in result["vtbs"])
try
{
foreach (var x in item["accounts"])
var wc = new WebClient();
wc.Headers.Add("Accept: */*");
wc.Headers.Add("Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4");
byte[] roomHtml = wc.DownloadData("https://gitee.com/SYXM/vdb/raw/master/json/list.json");
var result = JObject.Parse(Encoding.UTF8.GetString(roomHtml));

foreach (var item in result["vtbs"])
{
if (x["platform"].ToString() == "bilibili")
foreach (var x in item["accounts"])
{

string name = "";
if (item["name"].ToString().Contains("ch"))
if (x["platform"].ToString() == "bilibili")
{
try
{
name = item["name"]["ch"].ToString();
}
catch (Exception)
{

}
}
else if (item["name"].ToString().Contains("cn"))
{
try
string name = "";
if (item["name"].ToString().Contains("ch"))
{
name = item["name"]["cn"].ToString();
try
{
name = item["name"]["ch"].ToString();
}
catch (Exception)
{

}
}
catch (Exception)
else if (item["name"].ToString().Contains("cn"))
{

try
{
name = item["name"]["cn"].ToString();
}
catch (Exception)
{

}
}
列表缓存.Add(new 列表加载缓存
{
编号 = A,
名称 = name,
官方名称 = item["name"][item["name"]["default"].ToString()].ToString(),
平台 = "bilibili",
UID = x["id"].ToString(),
类型 = x["type"].ToString()
});
A++;
}
列表缓存.Add(new 列表加载缓存
{
编号 = A,
名称 = name,
官方名称 = item["name"][item["name"]["default"].ToString()].ToString(),
平台 = "bilibili",
UID = x["id"].ToString(),
类型 = x["type"].ToString()
});
A++;
}
}
}
catch (Exception)
{
}
//this.Dispatcher.Invoke(new Action(delegate
//{
// 选中内容展示.Content = "";
Expand Down
Loading

0 comments on commit c41b10d

Please sign in to comment.