Skip to content

Commit

Permalink
Merge pull request #463 from ywmoyue/dev
Browse files Browse the repository at this point in the history
4.6.25
  • Loading branch information
ywmoyue authored Jan 1, 2024
2 parents 5bc68d4 + f108efe commit a708fa9
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 95 deletions.
3 changes: 2 additions & 1 deletion src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<Compile Include="Models\Common\Live\RoomChangeMsgModel.cs" />
<Compile Include="Models\Common\User\SubmitCollectionItemModel.cs" />
<Compile Include="Models\Common\WbiKey.cs" />
<Compile Include="Models\Exceptions\NotFoundException.cs" />
<Compile Include="Models\Exceptions\CustomizedErrorWithDataException.cs" />
<Compile Include="Models\Exceptions\PlayerException.cs" />
<Compile Include="Models\Requests\Api\BaseApi.cs" />
Expand Down Expand Up @@ -1287,4 +1288,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
11 changes: 11 additions & 0 deletions src/BiliLite.UWP/Models/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace BiliLite.Models.Exceptions
{
public class NotFoundException : Exception
{
public NotFoundException(string msg) : base(msg)
{
}
}
}
13 changes: 1 addition & 12 deletions src/BiliLite.UWP/Models/Requests/Api/SeasonApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,13 @@ public ApiModel Detail(string season_id, bool proxy = false)
var api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{baseUrl}/pgc/view/app/season",
baseUrl = $"{baseUrl}/pgc/view/v2/app/season",
parameter = ApiHelper.MustParameter(AppKey, true) + $"&season_id={season_id}"
};
api.parameter += ApiHelper.GetSign(api.parameter, AppKey);
return api;
}

public ApiModel DetailWeb(string season_id)
{
var api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://bangumi.bilibili.com/view/web_api/season",
parameter = $"season_id={season_id}"
};

return api;
}
/// <summary>
/// 短评
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/BiliLite.UWP/Pages/SeasonDetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<convert:DatetimeConvert x:Key="datetime" ></convert:DatetimeConvert>
<convert:ColorSelecteConvert x:Key="colorSelct" ></convert:ColorSelecteConvert>
<SolidColorBrush x:Key="GridViewItemBackgroundSelected" Color="{ThemeResource HighLightColor}" />
<SolidColorBrush x:Key="GridViewItemForegroundSelected" Color="{ThemeResource HighLightColor}" />
<SolidColorBrush x:Key="GridViewItemForegroundSelected" Color="{ThemeResource HighLightTextColor}" />
<SolidColorBrush x:Key="RatingControlSelectedForeground" Color="Orange" />
</Page.Resources>
<Grid>
Expand Down Expand Up @@ -192,7 +192,7 @@
</StackPanel>
</Grid>
<Button Margin="0 16 0 0" Visibility="{x:Bind Path=m_viewModel.Detail.ShowPayment,Mode=OneWay}" BorderBrush="#FFFB9E60" Background="Transparent" HorizontalAlignment="Stretch" Foreground="#FFFB9E60">
<TextBlock Text="{x:Bind Path=m_viewModel.Detail.Payment.Dialog.Title,Mode=OneWay}"></TextBlock>
<TextBlock Text="{x:Bind Path=m_viewModel.Detail.Payment.Dialog.Title,Mode=OneWay}" Foreground="{ThemeResource TextColor}"></TextBlock>
</Button>
<toolkit:AdaptiveGridView x:Name="listEpisode"
DesiredWidth="120" ItemHeight="36"
Expand All @@ -217,7 +217,7 @@
<Grid ToolTipService.ToolTip="{x:Bind Path=LongTitle}">
<TextBlock VerticalAlignment="Center" TextAlignment="Center" TextTrimming="CharacterEllipsis"><Run Text="{x:Bind Path=Title}"/></TextBlock>
<Border Visibility="{x:Bind Path=ShowBadge}" VerticalAlignment="Top" Padding="4 2" CornerRadius="0 0 0 4" Background="{ThemeResource HighLightColor}" HorizontalAlignment="Right">
<TextBlock FontSize="12" Foreground="White" Text="{x:Bind Path=Badge}"></TextBlock>
<TextBlock FontSize="12" Foreground="{ThemeResource HighLightTextColor}" Text="{x:Bind Path=Badge}"></TextBlock>
</Border>
</Grid>
</DataTemplate>
Expand Down
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Services/GrpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bilibili.App.Dynamic.V2;
using Bilibili.App.Interface.V1;
using BiliLite.gRPC.Api;
using BiliLite.Models.Exceptions;

namespace BiliLite.Services
{
Expand All @@ -24,6 +25,11 @@ public async Task<SearchArchiveReply> SearchSpaceArchive(string mid, int page =
{
var reply = SearchArchiveReply.Parser.ParseFrom(result.results);
return reply;
}
// 用户搜索一个不存在的关键字导致的
else if (result.code == -102 && result.message == "请求失败,没有数据返回")
{
throw new NotFoundException(result.message);
}
else
{
Expand Down
93 changes: 26 additions & 67 deletions src/BiliLite.UWP/ViewModels/Season/SeasonDetailPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SeasonDetailPageViewModel : BaseViewModel
private readonly PlayerAPI m_playerApi;
private readonly FollowAPI m_followApi;
private readonly IMapper m_mapper;
private static readonly ILogger _logger = GlobalLogger.FromCurrentType();

#endregion

Expand Down Expand Up @@ -156,69 +157,56 @@ public async Task LoadSeasonDetail(string seasonId)
throw new CustomizedErrorException(results.message);
}

//通过代理访问番剧详情
var data = await results.GetJson<ApiResultModel<SeasonDetailModel>>();
//代理访问失败,使用Web的Api访问
if (!data.success)
{
data = await GetWebSeasonDetail(seasonId);
}
//访问番剧详情
var data = await results.GetJson<ApiDataModel<SeasonDetailModel>>();

if (!data.success)
{
throw new CustomizedErrorException(data.message);
}

if (data.result.Limit != null)
try
{
var reulstsWeb = await m_seasonApi.DetailWeb(seasonId).Request();
if (reulstsWeb.status)
//build 75900200
data.data.Episodes = JsonConvert.DeserializeObject<List<SeasonDetailEpisodeModel>>(
data.data.Modules.FirstOrDefault(x => x["style"].ToString() == "positive")?["data"]?["episodes"]
?.ToString() ?? "[]");
data.data.Seasons = JsonConvert.DeserializeObject<List<SeasonDetailSeasonItemModel>>(
data.data.Modules.FirstOrDefault(x => x["style"].ToString() == "season")?["data"]?["seasons"]
?.ToString() ?? "[]");
var pv = JsonConvert.DeserializeObject<List<SeasonDetailEpisodeModel>>(
data.data.Modules.FirstOrDefault(x => x["style"].ToString() == "section")?["data"]?["episodes"]
?.ToString() ?? "[]");
foreach (var item in pv)
{
var data_2 = reulstsWeb.GetJObject();
if (data_2["code"].ToInt32() == 0)
{
data.result.Episodes = await data_2["result"]["episodes"].ToString().DeserializeJson<List<SeasonDetailEpisodeModel>>();
}
item.SectionType = 1;
data.data.Episodes.Add(item);
}
}
else
catch (Exception ex)
{
try
{
//build 6235200
data.result.Episodes = JsonConvert.DeserializeObject<List<SeasonDetailEpisodeModel>>(data.result.Modules.FirstOrDefault(x => x["style"].ToString() == "positive")?["data"]?["episodes"]?.ToString() ?? "[]");
data.result.Seasons = JsonConvert.DeserializeObject<List<SeasonDetailSeasonItemModel>>(data.result.Modules.FirstOrDefault(x => x["style"].ToString() == "season")?["data"]?["seasons"]?.ToString() ?? "[]");
var pv = JsonConvert.DeserializeObject<List<SeasonDetailEpisodeModel>>(data.result.Modules.FirstOrDefault(x => x["style"].ToString() == "section")?["data"]?["episodes"]?.ToString() ?? "[]");
foreach (var item in pv)
{
item.SectionType = 1;
data.result.Episodes.Add(item);
}
}
catch (Exception)
{
}
_logger.Warn("解析番剧相关数据失败", ex);
}

if (data.result.Section != null)
if (data.data.Section != null)
{
foreach (var item in data.result.Section)
foreach (var item in data.data.Section)
{
foreach (var item2 in item.Episodes)
{
item2.SectionType = 1;
}
data.result.Episodes.InsertRange(0, item.Episodes);
//data.result.episodes= data.result.episodes.Concat(item.episodes).ToList();
data.data.Episodes.InsertRange(0, item.Episodes);
//data.data.episodes= data.data.episodes.Concat(item.episodes).ToList();
}
}

var seasonDetail = m_mapper.Map<SeasonDetailViewModel>(data.result);
var seasonDetail = m_mapper.Map<SeasonDetailViewModel>(data.data);
Detail = seasonDetail;

Episodes = data.result.Episodes.Where(x => !x.IsPreview).ToList();
Episodes = data.data.Episodes.Where(x => !x.IsPreview).ToList();
ShowEpisodes = Episodes.Count > 0;
Previews = data.result.Episodes.Where(x => x.IsPreview).ToList();
Previews = data.data.Episodes.Where(x => x.IsPreview).ToList();
ShowPreview = Previews.Count > 0;
NothingPlay = !ShowEpisodes && !ShowPreview;
Loaded = true;
Expand All @@ -236,35 +224,6 @@ public async Task LoadSeasonDetail(string seasonId)
}
}

public async Task<ApiResultModel<SeasonDetailModel>> GetWebSeasonDetail(string seasonId)
{
var reulsts_web = await m_seasonApi.DetailWeb(seasonId).Request();
if (!reulsts_web.status)
return new ApiResultModel<SeasonDetailModel>()
{
code = -101,
message = "无法读取内容"
};
var data = reulsts_web.GetJObject();
if (data["code"].ToInt32() != 0)
return new ApiResultModel<SeasonDetailModel>()
{
code = -101,
message = "无法读取内容"
};
var objText = data["result"].ToString();
//处理下会出错的字段
objText = objText.Replace("\"staff\"", "staff1");
var model = JsonConvert.DeserializeObject<SeasonDetailModel>(objText);
model.Episodes = await data["result"]["episodes"].ToString().DeserializeJson<List<SeasonDetailEpisodeModel>>();
model.UserStatus = new SeasonDetailUserStatusModel()
{
FollowStatus = 0,
Follow = 0
};
return new ApiResultModel<SeasonDetailModel>() { code = 0, message = "", result = model, };
}

public async void DoFollow()
{
if (!SettingService.Account.Logined && !await Notify.ShowLoginDialog())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ public SeasonDetailSeasonItemModel CurrentSeason
public SeasonDetailPaymentModel Payment { get; set; }

[JsonProperty("show_payment")]
public bool ShowPayment => Payment is { Dialog: { } };
public bool ShowPayment => Payment?.Dialog?.Title != null;
}
}
25 changes: 14 additions & 11 deletions src/BiliLite.UWP/ViewModels/User/UserSubmitVideoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ public async Task GetSubmitVideo()
LoadingSubmitVideo = true;
if (string.IsNullOrEmpty(Keyword))
{
var api = m_userDetailApi.SubmitVideosCursor(Mid, order: (SubmitVideoOrder)SelectOrder, cursor: m_lastAid);
var api = m_userDetailApi.SubmitVideosCursor(Mid, order: (SubmitVideoOrder)SelectOrder,
cursor: m_lastAid);
CurrentTid = SelectTid.Tid;
var results = await api.Request();
if (!results.status)
{
throw new CustomizedErrorException(results.message);
}

var data = results.GetJObject();
if (data["code"].ToInt32() != 0)
{
Expand All @@ -164,18 +166,19 @@ public async Task GetSubmitVideo()
AttachSubmitVideoItems(submitVideoItems, (int)searchArchive.Total);
}
}
catch (CustomizedErrorException ex)
{
Notify.ShowMessageToast(ex.Message);
_logger.Error("获取用户投稿失败", ex);
}
catch (NotFoundException ex)
{
Notify.ShowMessageToast("(っ °Д °;)っ 没有找到相应的视频~");
}
catch (Exception ex)
{
if (ex is CustomizedErrorException)
{
Notify.ShowMessageToast(ex.Message);
}
else
{
var handel = HandelError<UserSubmitVideoViewModel>(ex);
Notify.ShowMessageToast(handel.message);
}

var handel = HandelError<UserSubmitVideoViewModel>(ex);
Notify.ShowMessageToast(handel.message);
_logger.Error("获取用户投稿失败", ex);
}
finally
Expand Down

0 comments on commit a708fa9

Please sign in to comment.