Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Oct 3, 2020
1 parent f01491d commit 2537e3d
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 89 deletions.
2 changes: 1 addition & 1 deletion BBDown/BBDown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.2.4</Version>
<Version>1.3.0</Version>
<Description>BBDown是一个免费且便捷高效的哔哩哔哩下载/解析软件.</Description>
</PropertyGroup>

Expand Down
59 changes: 59 additions & 0 deletions BBDown/BBDownBangumiInfoFetcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using static BBDown.BBDownEntity;
using static BBDown.BBDownUtil;

namespace BBDown
{
class BBDownBangumiInfoFetcher : IFetcher
{
public BBDownVInfo Fetch(string id)
{
id = id.Substring(3);
string index = "";
string api = $"https://api.bilibili.com/pgc/view/web/season?ep_id={id}";
string json = GetWebSource(api);
JObject infoJson = JObject.Parse(json);
string cover = infoJson["result"]["cover"].ToString();
string title = infoJson["result"]["title"].ToString();
string desc = infoJson["result"]["evaluate"].ToString();
string pubTime = infoJson["result"]["publish"]["pub_time"].ToString();
JArray pages = JArray.Parse(infoJson["result"]["episodes"].ToString());
List<Page> pagesInfo = new List<Page>();
int i = 1;
foreach (JObject page in pages)
{
string res = "";
try
{
res = page["dimension"]["width"].ToString() + "x" + page["dimension"]["height"].ToString();
}
catch (Exception) { }
string _title = page["long_title"].ToString();
if(string.IsNullOrEmpty(_title)) _title = page["title"].ToString();
Page p = new Page(i++,
page["aid"].ToString(),
page["cid"].ToString(),
page["id"].ToString(),
GetValidFileName(_title),
0, res);
if (p.epid == id) index = p.index.ToString();
pagesInfo.Add(p);
}

var info = new BBDownVInfo();
info.Title = GetValidFileName(title).Trim();
info.Desc = GetValidFileName(desc).Trim();
info.Pic = cover;
info.PubTime = pubTime;
info.PagesInfo = pagesInfo;
info.IsBangumi = true;
info.IsCheese = true;
info.Index = index;

return info;
}
}
}
6 changes: 3 additions & 3 deletions BBDown/BBDownCheeseInfoFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BBDownCheeseInfoFetcher : IFetcher
{
public BBDownVInfo Fetch(string id)
{
id = id.Substring(7);
string index = "";
string api = $"https://api.bilibili.com/pugv/view/web/season?ep_id={id}";
string json = GetWebSource(api);
Expand All @@ -35,11 +36,10 @@ public BBDownVInfo Fetch(string id)
pubTime = pubTime != "" ? (new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Convert.ToDouble(pubTime)).ToLocalTime().ToString()) : "";

var info = new BBDownVInfo();
info.Title = GetValidFileName(title);
info.Desc = GetValidFileName(desc);
info.Title = GetValidFileName(title).Trim();
info.Desc = GetValidFileName(desc).Trim();
info.Pic = cover;
info.PubTime = pubTime;
info.Subtitles = new List<Subtitle>(); //课程不考虑外挂字幕
info.PagesInfo = pagesInfo;
info.IsBangumi = true;
info.IsCheese = true;
Expand Down
2 changes: 1 addition & 1 deletion BBDown/BBDownMuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static int ffmpeg(string parms)

public static int MuxAV(string videoPath, string audioPath, string outPath, string desc = "", string title = "", string episodeId = "", string pic = "", List<Subtitle> subs = null, bool audioOnly = false, bool videoOnly = false)
{
if (!Directory.Exists(Path.GetDirectoryName(outPath)))
if (outPath.Contains("/") && ! Directory.Exists(Path.GetDirectoryName(outPath)))
Directory.CreateDirectory(Path.GetDirectoryName(outPath));
//----分析并生成-i参数
StringBuilder inputArg = new StringBuilder();
Expand Down
16 changes: 2 additions & 14 deletions BBDown/BBDownNormalInfoFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ public BBDownVInfo Fetch(string id)
pubTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Convert.ToDouble(pubTime)).ToLocalTime().ToString();
bool bangumi = false;

JArray subs = JArray.Parse(infoJson["data"]["subtitle"]["list"].ToString());
List<Subtitle> subtitleInfo = new List<Subtitle>();
foreach (JObject sub in subs)
{
Subtitle subtitle = new Subtitle();
subtitle.url = sub["subtitle_url"].ToString();
subtitle.lan = sub["lan"].ToString();
subtitle.path = $"{id}/{id}.{subtitle.lan}.srt";
subtitleInfo.Add(subtitle);
}

JArray pages = JArray.Parse(infoJson["data"]["pages"].ToString());
List<Page> pagesInfo = new List<Page>();
foreach (JObject page in pages)
Expand Down Expand Up @@ -63,11 +52,10 @@ public BBDownVInfo Fetch(string id)
catch { }

var info = new BBDownVInfo();
info.Title = GetValidFileName(title);
info.Desc = GetValidFileName(desc);
info.Title = GetValidFileName(title).Trim();
info.Desc = GetValidFileName(desc).Trim();
info.Pic = pic;
info.PubTime = pubTime;
info.Subtitles = subtitleInfo;
info.PagesInfo = pagesInfo;
info.IsBangumi = bangumi;

Expand Down
4 changes: 3 additions & 1 deletion BBDown/BBDownParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ namespace BBDown
{
class BBDownParser
{
public static string GetPlayJson(string aid, string cid, string epId, bool tvApi, bool bangumi, bool cheese, string qn = "0")
public static string GetPlayJson(string aidOri, string aid, string cid, string epId, bool tvApi, string qn = "0")
{
bool cheese = aidOri.StartsWith("cheese:");
bool bangumi = cheese || aidOri.StartsWith("ep:");
LogDebug("aid={0},cid={1},epId={2},tvApi={3},bangumi={4},cheese={5},qn={6}", aid, cid, epId, tvApi, bangumi, cheese, qn);
string prefix = tvApi ? (bangumi ? "api.snm0516.aisee.tv/pgc/player/api/playurltv" : "api.snm0516.aisee.tv/x/tv/ugc/playurl")
: (bangumi ? "api.bilibili.com/pgc/player/web/playurl" : "api.bilibili.com/x/player/playurl");
Expand Down
66 changes: 66 additions & 0 deletions BBDown/BBDownSubUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,78 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using static BBDown.BBDownEntity;
using static BBDown.BBDownUtil;
using static BBDown.BBDownLogger;
using System.Text.RegularExpressions;

namespace BBDown
{
class BBDownSubUtil
{
public static List<Subtitle> GetSubtitles(string aid, string cid)
{
List<Subtitle> subtitles = new List<Subtitle>();
try
{
string api = $"https://api.bilibili.com/x/web-interface/view?aid={aid}&cid={cid}";
string json = GetWebSource(api);
JObject infoJson = JObject.Parse(json);
JArray subs = JArray.Parse(infoJson["data"]["subtitle"]["list"].ToString());
foreach (JObject sub in subs)
{
Subtitle subtitle = new Subtitle();
subtitle.url = sub["subtitle_url"].ToString();
subtitle.lan = sub["lan"].ToString();
subtitle.path = $"{aid}/{aid}.{cid}.{subtitle.lan}.srt";
subtitles.Add(subtitle);
}
return subtitles;
}
catch (Exception)
{
try
{
//grpc调用接口 protobuf
string api = "https://app.biliapi.net/bilibili.community.service.dm.v1.DM/DmView";
int _aid = Convert.ToInt32(aid);
int _cid = Convert.ToInt32(cid);
int _type = 1;
byte[] data = new byte[18];
data[0] = 0x0; data[1] = 0x0; data[2] = 0x0; data[3] = 0x0; data[4] = 0xD; //先固定死了
int i = 5;
data[i++] = Convert.ToByte(1 << 3 | 0); // index=1
while ((_aid & -128) != 0)
{
data[i++] = Convert.ToByte((_aid & 127) | 128);
_aid = _aid >> 7;
}
data[i++] = Convert.ToByte(_aid);
data[i++] = Convert.ToByte(2 << 3 | 0); // index=2
while ((_cid & -128) != 0)
{
data[i++] = Convert.ToByte((_cid & 127) | 128);
_cid = _cid >> 7;
}
data[i++] = Convert.ToByte(_cid);
data[i++] = Convert.ToByte(3 << 3 | 0); // index=3
data[i++] = Convert.ToByte(_type);
string t = GetPostResponse(api, data);
Regex reg = new Regex("(zh-Han[st]).*?(http.*?\\.json)");
foreach(Match m in reg.Matches(t))
{
Subtitle subtitle = new Subtitle();
subtitle.url = m.Groups[2].Value;
subtitle.lan = m.Groups[1].Value;
subtitle.path = $"{aid}/{aid}.{cid}.{subtitle.lan}.srt";
subtitles.Add(subtitle);
}
return subtitles;
}
catch (Exception) { return subtitles; } //返回空列表
}
}

public static void SaveSubtitle(string url, string path)
{
File.WriteAllText(path, ConvertSubFromJson(GetWebSource(url)), new UTF8Encoding());
Expand Down
Loading

0 comments on commit 2537e3d

Please sign in to comment.