Skip to content

Commit

Permalink
修复无法获取下载地址, 增加刷新下载地址功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhangzijing committed Oct 4, 2016
1 parent 2fcc2e4 commit 290c7e8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BilibiliVideoFetcher/Helper/UrlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class UrlHelper
{
public static string FixUrl(string url)
{
if(!url.StartsWith("http://")|| !url.StartsWith("https://"))
if(!(url.StartsWith("http://")|| url.StartsWith("https://")))
{
return "http://" + url;
}else
Expand Down
4 changes: 3 additions & 1 deletion BilibiliVideoFetcher/Process/FetchingCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ private static string GetAidFromSourceHtml(string html)
public static void ReFetchTask(VideoTask task)
{
CreateTaskWithAid(task.Aid,task.Page);
Data.FetchingTasks.GetInstance().Tasks.Remove(task);
Data.ApplicationSettings.GetInstance().Dispatcher.Invoke(()=> {
Data.FetchingTasks.GetInstance().Tasks.Remove(task);
});
}
public static void NewTask(string url)
{
Expand Down
12 changes: 6 additions & 6 deletions BilibiliVideoFetcher/Process/TaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public static void Build(string aid, int start, int end)
}
public static void Build(string aid, string page)
{
var json = Helper.NetworkHelper.GetTextFromUri(VIDEO_INFO_API + aid + "&page=" + page);
if (json.Length > 100)
var jsonVideoInfo = Helper.NetworkHelper.GetTextFromUri(VIDEO_INFO_API + aid + "&page=" + page);
if (jsonVideoInfo.Length > 100)
{
var videoInfo = JsonConvert.DeserializeObject<jsonVideoInfo>(json);
var videoInfo = JsonConvert.DeserializeObject<jsonVideoInfo>(jsonVideoInfo);
var newTask = new VideoTask();
newTask.VideoInfo = videoInfo;
newTask.Name = "(获取下载地址中)" + videoInfo.title + (videoInfo.partname == null || videoInfo.partname == string.Empty ? string.Empty : " " + videoInfo.partname);
Expand All @@ -76,7 +76,7 @@ public static void Build(string aid, string page)
Data.FetchingTasks.GetInstance().Tasks.Add(newTask);
});
var downJson = Helper.NetworkHelper.GetTextFromUri(
DOWNLOAD_API + newTask.Aid + "?quality=1&type=" +
DOWNLOAD_API + newTask.VideoInfo.cid + "?quality=1&type=" +
Data.ApplicationSettings.GetInstance().FetchingOption.Format);
if (downJson.Length < 100)
{
Expand All @@ -89,7 +89,7 @@ public static void Build(string aid, string page)
{
var quality = jvd.accept_quality.OrderByDescending(t => t).First();
downJson = Helper.NetworkHelper.GetTextFromUri(
DOWNLOAD_API + newTask.Aid + "?quality=" + quality);
DOWNLOAD_API + newTask.VideoInfo.cid + "?quality=" + quality);
jvd = JsonConvert.DeserializeObject<jsonVideoDownload>(downJson);
}
if (jvd.durl.Count == 0)
Expand All @@ -110,7 +110,7 @@ public static void Build(string aid, string page)
}
else
{
var errorMsg = JsonConvert.DeserializeObject<jsonVideoInfoFailedMessage>(json);
var errorMsg = JsonConvert.DeserializeObject<jsonVideoInfoFailedMessage>(jsonVideoInfo);
Data.NotificationData.GetInstance().Add(new NotifictionMessage(NotificationLevel.Error, "获取视频信息失败, 错误代号: " + errorMsg.code));
return;
}
Expand Down
1 change: 1 addition & 0 deletions BilibiliVideoFetcher/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem x:Name="menuItemViewDetail" Header="查看详情" Click="menuItemViewDetail_Click" />
<MenuItem x:Name="menuItemRefetchDownloadUrl" Header="刷新下载地址" Click="menuItemRefetchDownloadUrl_Click" />
<MenuItem x:Name="menuItemCopyDownloadUrl" Header="复制下载地址" Click="menuItemCopyDownloadUrl_Click" />
<MenuItem x:Name="menuItemViewInBilibili" Header="在Bilibili中查看" Click="menuItemViewInBilibili_Click" />

Expand Down
18 changes: 18 additions & 0 deletions BilibiliVideoFetcher/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,23 @@ private void menuItemCopyDanmuDownloadUrl_Click(object sender, RoutedEventArgs e
}

}

private void menuItemRefetchDownloadUrl_Click(object sender, RoutedEventArgs e)
{
Data.Log.GetLogger().Info("MainWindow->menuItemRefetchDownloadUrl_Click", "Executed menuItemRefetchDownloadUrl");
if (dataGrid.SelectedItems.Count == 0)
{
Data.NotificationData.GetInstance().Add(
new Classes.NotifictionMessage(NotificationLevel.Warning, "尚未选择所要获取下载地址的项"));
return;
}
var task = GetSelectedTask(dataGrid);
Data.NotificationData.GetInstance().Add(
new Classes.NotifictionMessage(NotificationLevel.Warning, "已开始刷新下载地址."));
new Task(()=>
{
Process.FetchingCore.ReFetchTask(task);
}).Start();
}
}
}

0 comments on commit 290c7e8

Please sign in to comment.