Skip to content

Commit

Permalink
#968 ニコレポの廃止およびフォロー新着に対応。チャンネル対応が今後必要になるかも。
Browse files Browse the repository at this point in the history
  • Loading branch information
tor4kichi committed Aug 8, 2024
1 parent 7788aba commit 4cfc3fa
Show file tree
Hide file tree
Showing 31 changed files with 673 additions and 823 deletions.
4 changes: 1 addition & 3 deletions Hohoema.Core/Hohoema.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@
<Compile Include="Models\Niconico\Mylist\MylistProvider.cs" />
<Compile Include="Models\Niconico\NiconicoObjectExtension.cs" />
<Compile Include="Models\Niconico\NiconicoSession.cs" />
<Compile Include="Models\Niconico\NicoRepo\LoginUser\LoginUserNicoRepoProvider.cs" />
<Compile Include="Models\Niconico\NicoRepo\NicoRepoSettings.cs" />
<Compile Include="Models\Niconico\Recommend\RecommendProvider.cs" />
<Compile Include="Models\Niconico\Search\SearchVideoPlaylist.cs" />
<Compile Include="Models\Niconico\Search\SearchVideoPlaylistSortOption.cs" />
Expand Down Expand Up @@ -377,7 +375,7 @@
<Version>2.7.2</Version>
</PackageReference>
<PackageReference Include="NiconicoToolkit">
<Version>0.6.2</Version>
<Version>0.6.5</Version>
</PackageReference>
<PackageReference Include="ReactiveProperty">
<Version>7.12.0</Version>
Expand Down
14 changes: 2 additions & 12 deletions Hohoema.Core/Models/Application/BackupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using Hohoema.Contracts.Subscriptions;
using Hohoema.Models.LocalMylist;
using Hohoema.Models.Niconico.NicoRepo;
using Hohoema.Models.Niconico.Video;
using Hohoema.Models.PageNavigation;
using Hohoema.Models.Pins;
Expand All @@ -12,7 +11,6 @@
using Hohoema.Models.Subscriptions;
using LiteDB;
using NiconicoToolkit.Live.WatchSession;
using NiconicoToolkit.NicoRepo;
using NiconicoToolkit.Ranking.Video;
using NiconicoToolkit.Video;
using System;
Expand Down Expand Up @@ -48,7 +46,6 @@ public sealed class BackupManager
private readonly VideoFilteringSettings _videoFilteringSettings;
private readonly PlayerSettings _playerSettings;
private readonly AppearanceSettings _appearanceSettings;
private readonly NicoRepoSettings _nicoRepoSettings;
private readonly CommentFliteringRepository _commentFliteringRepository;
private readonly JsonSerializerOptions _options;

Expand All @@ -64,7 +61,6 @@ public BackupManager(LocalMylistRepository playlistRepository,
VideoFilteringSettings videoFilteringSettings,
PlayerSettings playerSettings,
AppearanceSettings appearanceSettings,
NicoRepoSettings nicoRepoSettings,
CommentFliteringRepository commentFliteringRepository
)
{
Expand All @@ -76,8 +72,7 @@ CommentFliteringRepository commentFliteringRepository
_videoRankingSettings = videoRankingSettings;
_videoFilteringSettings = videoFilteringSettings;
_playerSettings = playerSettings;
_appearanceSettings = appearanceSettings;
_nicoRepoSettings = nicoRepoSettings;
_appearanceSettings = appearanceSettings;
_commentFliteringRepository = commentFliteringRepository;
_options = new JsonSerializerOptions()
{
Expand Down Expand Up @@ -213,11 +208,6 @@ public async Task BackupAsync(StorageFile storageFile, CancellationToken ct = de
ApplicationTheme = _appearanceSettings.ApplicationTheme.ToString()
},

NicoRepoSettings = new NicoRepoSettingsBackupEntry
{
DisplayNicoRepoMuteContextTriggers = _nicoRepoSettings.DisplayNicoRepoMuteContextTriggers.Select(x => x.ToString()).ToArray()
},

CommentSettingsBackupEntry = new CommentSettingsBackupEntry
{
ShareNGScore = _commentFliteringRepository.ShareNGScore,
Expand Down Expand Up @@ -477,7 +467,7 @@ public void RestoreNicoRepoSettings(BackupContainer backup)

if (backup.NicoRepoSettings.DisplayNicoRepoMuteContextTriggers?.Any() ?? false)
{
_nicoRepoSettings.DisplayNicoRepoMuteContextTriggers = backup.NicoRepoSettings.DisplayNicoRepoMuteContextTriggers.Select(x => Enum.TryParse<NicoRepoMuteContextTrigger>(x, out NicoRepoMuteContextTrigger type) ? type : default(NicoRepoMuteContextTrigger?)).Where(x => x != null).Select(x => x.Value).ToList();
//_nicoRepoSettings.DisplayNicoRepoMuteContextTriggers = backup.NicoRepoSettings.DisplayNicoRepoMuteContextTriggers.Select(x => Enum.TryParse<NicoRepoMuteContextTrigger>(x, out NicoRepoMuteContextTrigger type) ? type : default(NicoRepoMuteContextTrigger?)).Where(x => x != null).Select(x => x.Value).ToList();
}
}

Expand Down

This file was deleted.

24 changes: 0 additions & 24 deletions Hohoema.Core/Models/Niconico/NicoRepo/NicoRepoSettings.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ VideoWatchedRepository videoWatchedRepository
throw new HohoemaException("Failed get login user video watch history. Require LogIn.");
}

VideoWatchHistory res = await _niconicoSession.ToolkitContext.Activity.VideoWachHistory.GetWatchHistoryAsync(page, pageSize);
VideoWatchHistory res = await _niconicoSession.ToolkitContext.History.VideoWachHistory.GetWatchHistoryAsync(page, pageSize);

if (res.Meta.IsSuccess is false) { throw new HohoemaException("Failed get login user video watch history"); }

Expand All @@ -46,19 +46,19 @@ VideoWatchedRepository videoWatchedRepository

public async Task<bool> RemoveAllHistoriesAsync()
{
VideoWatchHistoryDeleteResult res = await _niconicoSession.ToolkitContext.Activity.VideoWachHistory.DeleteAllWatchHistoriesAsync();
VideoWatchHistoryDeleteResult res = await _niconicoSession.ToolkitContext.History.VideoWachHistory.DeleteAllWatchHistoriesAsync();
return res.IsSuccess;
}

public async Task<bool> RemoveHistoryAsync(VideoId videoId)
{
VideoWatchHistoryDeleteResult res = await _niconicoSession.ToolkitContext.Activity.VideoWachHistory.DeleteWatchHistoriesAsync(videoId);
VideoWatchHistoryDeleteResult res = await _niconicoSession.ToolkitContext.History.VideoWachHistory.DeleteWatchHistoriesAsync(videoId);
return res.IsSuccess;
}

public async Task<bool> RemoveHistoryAsync(IEnumerable<VideoId> videoIdList)
{
VideoWatchHistoryDeleteResult res = await _niconicoSession.ToolkitContext.Activity.VideoWachHistory.DeleteWatchHistoriesAsync(videoIdList);
VideoWatchHistoryDeleteResult res = await _niconicoSession.ToolkitContext.History.VideoWachHistory.DeleteWatchHistoriesAsync(videoIdList);
return res.IsSuccess;
}
}
2 changes: 1 addition & 1 deletion Hohoema.Core/Models/PageNavigation/HohoemaPageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum HohoemaPageType
Splash,
VideoPlayer,

NicoRepo,
FollowingsActivity,
Recommend,

ChannelInfo,
Expand Down
8 changes: 4 additions & 4 deletions Hohoema.Core/Models/Player/Video/Comment/CommentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CommentClient(NiconicoSession niconicoSession, string rawVideoid)
public string RawVideoId { get; }
public string VideoOwnerId => _watchApiData!.Owner.Id.ToString();

internal NicoVideoWatchApiResponse.Response? _watchApiData { get; set; }
internal WatchResponse? _watchApiData { get; set; }


private readonly NiconicoSession _niconicoSession;
Expand All @@ -48,7 +48,7 @@ public async Task<CommentPostResult> SubmitComment(string comment, TimeSpan posi
Guard.IsNotNull(_watchApiData);

VideoId videoId = _watchApiData.Video.Id;
NiconicoToolkit.Video.Watch.NicoVideoWatchApiResponse.Thread mainThread = _watchApiData.Comment.Threads.First(x => x.ForkLabel == ThreadTargetForkConstants.Main);
NiconicoToolkit.Video.Watch.Thread mainThread = _watchApiData.Comment.Threads.First(x => x.ForkLabel == ThreadTargetForkConstants.Main);
string threadId = mainThread.Id.ToString();

bool isPostCompleted = false;
Expand Down Expand Up @@ -154,7 +154,7 @@ private async Task<string> GetPostKeyLatestAsync(string threadForkLabel, Cancell
if (threadForkLabel == ThreadTargetForkConstants.Main)
{
Guard.IsNotNull(_watchApiData);
NiconicoToolkit.Video.Watch.NicoVideoWatchApiResponse.Thread thread = _watchApiData.Comment.Threads.First(x => x.ForkLabel == ThreadTargetForkConstants.Main);
NiconicoToolkit.Video.Watch.Thread thread = _watchApiData.Comment.Threads.First(x => x.ForkLabel == ThreadTargetForkConstants.Main);
ThreadPostKeyResponse res = await _nvCommentApi.GetPostKeyAsync(thread.Id.ToString(), ct);
Guard.IsTrue(res.IsSuccess);

Expand All @@ -163,7 +163,7 @@ private async Task<string> GetPostKeyLatestAsync(string threadForkLabel, Cancell
else if (threadForkLabel == ThreadTargetForkConstants.Easy)
{
Guard.IsNotNull(_watchApiData);
NiconicoToolkit.Video.Watch.NicoVideoWatchApiResponse.Thread thread = _watchApiData.Comment.Threads.First(x => x.ForkLabel == ThreadTargetForkConstants.Easy);
NiconicoToolkit.Video.Watch.Thread thread = _watchApiData.Comment.Threads.First(x => x.ForkLabel == ThreadTargetForkConstants.Easy);
ThreadEasyPostKeyResponse res = await _nvCommentApi.GetEasyPostKeyAsync(thread.Id.ToString(), ct);
Guard.IsTrue(res.IsSuccess);

Expand Down
28 changes: 14 additions & 14 deletions Hohoema.Core/Models/Player/Video/NicoVideoSessionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public interface INicoVideoDetails : IVideoDetail

public class DmcVideoDetails : INicoVideoDetails
{
private readonly Response _res;
private readonly WatchResponse _res;

internal DmcVideoDetails(Response dmcWatchData)
internal DmcVideoDetails(WatchResponse dmcWatchData)
{
_res = dmcWatchData;
Tags = _res.Tag.Items.Select(x => new NicoVideoTag(x.Name)).ToArray();
Expand Down Expand Up @@ -92,7 +92,7 @@ public double LoudnessCorrectionValue
}
else if (_res.Media.Domand != null)
{
return _res.Media.Domand.Audios.FirstOrDefault(x => x.IsAvailable ?? false)?.LoudnessCollection[0].Value ?? 1;
return _res.Media.Domand.Audios.FirstOrDefault(x => x.IsAvailable)?.LoudnessCollection[0].Value ?? 1;
}
}
catch { }
Expand Down Expand Up @@ -148,7 +148,7 @@ public class PreparePlayVideoResult : INiconicoVideoSessionProvider, INiconicoCo
public ImmutableArray<NicoVideoQualityEntity> AvailableQualities { get; }

private readonly NicoVideoSessionOwnershipManager _ownershipManager;
private readonly Response _dmcWatchData;
private readonly WatchResponse _dmcWatchData;
private readonly bool _isForceDmc;
private readonly NiconicoSession _niconicoSession;

Expand All @@ -166,7 +166,7 @@ public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession
IsSuccess = false;
}

public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession, PreparePlayVideoFailedReason failedReason, Response dmcWatchData = null)
public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession, PreparePlayVideoFailedReason failedReason, WatchResponse dmcWatchData = null)
: this(contentId, niconicoSession)
{
AvailableQualities = ImmutableArray<NicoVideoQualityEntity>.Empty;
Expand All @@ -175,7 +175,7 @@ public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession
_dmcWatchData = dmcWatchData;
}

public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession, NicoVideoSessionOwnershipManager ownershipManager, Response dmcWatchData, bool isForceDmc)
public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession, NicoVideoSessionOwnershipManager ownershipManager, WatchResponse dmcWatchData, bool isForceDmc)
: this(contentId, niconicoSession)
{
_ownershipManager = ownershipManager;
Expand All @@ -186,19 +186,19 @@ public PreparePlayVideoResult(VideoId contentId, NiconicoSession niconicoSession
if (_isForceDmc && _dmcWatchData?.Media.Delivery is not null)
{
AvailableQualities = _dmcWatchData.Media.Delivery.Movie.Videos
.Select(x => new NicoVideoQualityEntity(x.IsAvailable.Value, QualityIdToNicoVideoQuality(x.Id), x.Id, (int)x.BitRate.Value, (int)x.Width, (int)x.Height) { Label = x.Label })
.Select(x => new NicoVideoQualityEntity(x.IsAvailable, QualityIdToNicoVideoQuality(x.Id), x.Id, (int)x.BitRate, (int)x.Width, (int)x.Height) { Label = x.Label })
.ToImmutableArray();
}
else if (_dmcWatchData?.Media.Domand is { } domand)
{
AvailableQualities = domand.Videos
.Select(x => new NicoVideoQualityEntity(x.IsAvailable ?? false, QualityIdToNicoVideoQuality(x.Id), x.Id, x.BitRate, x.Width, x.Height) { Label = x.Label })
.Select(x => new NicoVideoQualityEntity(x.IsAvailable, QualityIdToNicoVideoQuality(x.Id), x.Id, x.BitRate, x.Width, x.Height) { Label = x.Label })
.ToImmutableArray();
}
else if (_dmcWatchData?.Media.Delivery is { } delivery)
{
AvailableQualities = delivery.Movie.Videos
.Select(x => new NicoVideoQualityEntity(x.IsAvailable.Value, QualityIdToNicoVideoQuality(x.Id), x.Id, (int)x.BitRate.Value, (int)x.Width, (int)x.Height) { Label = x.Label })
.Select(x => new NicoVideoQualityEntity(x.IsAvailable, QualityIdToNicoVideoQuality(x.Id), x.Id, (int)x.BitRate, (int)x.Width, (int)x.Height) { Label = x.Label })
.ToImmutableArray();
}
else
Expand Down Expand Up @@ -279,10 +279,10 @@ public Task<ICommentSession<IVideoComment>> CreateCommentSessionAsync()
return _dmcWatchData != null ? CreateCommentSession(ContentId, _dmcWatchData) : throw new NotSupportedException();
}

private Task<ICommentSession<IVideoComment>> CreateCommentSession(string contentId, Response watchData)
private Task<ICommentSession<IVideoComment>> CreateCommentSession(string contentId, WatchResponse watchData)
{
CommentClient commentClient = new(_niconicoSession, contentId);
Response dmcRes = watchData;
WatchResponse dmcRes = watchData;
//commentClient.CommentServerInfo = new CommentServerInfo()
//{
// ServerUrl = dmcRes.Comment.Threads[0].Server.OriginalString,
Expand Down Expand Up @@ -660,7 +660,7 @@ public class NiconicoContent

public static class DmcWatchSessionExtension
{
public static NicoVideoQuality ToNicoVideoQuality(this Response dmcWatchData, string qualityId)
public static NicoVideoQuality ToNicoVideoQuality(this WatchResponse dmcWatchData, string qualityId)
{
if (dmcWatchData.Media.Domand is { } domand
&& domand.Videos.FirstOrDefault(x => x.Id == qualityId) is { } videoQuality
Expand All @@ -677,10 +677,10 @@ public static NicoVideoQuality ToNicoVideoQuality(this Response dmcWatchData, st
};
}

NicoVideoWatchApiResponse.Video dmcVideoContent = dmcWatchData?.Media.Delivery.Movie.Videos.FirstOrDefault(x => x.Id == qualityId);
VideoContent dmcVideoContent = dmcWatchData?.Media.Delivery.Movie.Videos.FirstOrDefault(x => x.Id == qualityId);
if (dmcVideoContent != null)
{
NicoVideoWatchApiResponse.Video[] qualities = dmcWatchData.Media.Delivery.Movie.Videos;
VideoContent[] qualities = dmcWatchData.Media.Delivery.Movie.Videos;
int index = Array.IndexOf(qualities, dmcVideoContent);

// DmcInfo.Quality の要素数は動画によって1~5個まで様々である
Expand Down
Loading

0 comments on commit 4cfc3fa

Please sign in to comment.