Skip to content

Commit

Permalink
Merge pull request #403 from Fooxboy/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
Fooxboy authored Jul 18, 2024
2 parents 9e02898 + e1bdaea commit 02ba224
Show file tree
Hide file tree
Showing 50 changed files with 1,291 additions and 1,634 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
name: Download previous release

- name: Build package
run: vpk pack -c ${{ github.ref == 'refs/heads/develop' && 'win-beta' || 'win' }} -f vcredist140-x64 -p pub -u MusicX.WPF -v ${{ needs.compute-version.outputs.version }} --packTitle "MusicX Player" -e MusicX.exe -i MusicX/StoreLogo.scale-400.ico --includePdb --skipVeloAppCheck --packAuthors "Fooxboy, zznty" --releaseNotes notes.md -s MusicX/StoreLogo.scale-400.png
run: vpk pack -c ${{ github.ref == 'refs/heads/develop' && 'win-beta' || 'win' }} -f vcredist140-x64 -p pub -u MusicX.WPF -v ${{ needs.compute-version.outputs.version }} --packTitle "MusicX Player" -e MusicX.exe -i MusicX/StoreLogo.scale-400.ico --skipVeloAppCheck --packAuthors "Fooxboy, zznty" --releaseNotes notes.md -s MusicX/StoreLogo.scale-400.png

- name: Push pre-release package
if: ${{ github.ref == 'refs/heads/develop' }}
Expand Down
2 changes: 1 addition & 1 deletion IF.Lastfm.Core/IF.Lastfm.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
592 changes: 495 additions & 97 deletions IF.Lastfm.Core/packages.lock.json

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions MusicX.Core/Helpers/IIdentifiable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using MusicX.Core.Models.General;
using MusicX.Core.Models;

namespace MusicX.Core.Helpers;

public interface IIdentifiable
{
string Identifier { get; }

public static void Process(ResponseData data)
{
if (data.Block != null) ProcessBlock(data.Block, data);

if (data.Replacements?.ReplacementsModels is { Count: > 0 } replacementsModels)
foreach (var block in replacementsModels.SelectMany(b => b.ToBlocks))
{
ProcessBlock(block, data);
}

if (data.Playlists is { Count: > 0 } playlists)
foreach (var playlist in playlists)
{
FillPlaylistOwnerName(playlist, data);
}

if (data.Playlist != null) FillPlaylistOwnerName(data.Playlist, data);

if (data.Section != null) ProcessSection(data.Section, data);
}

private static IEnumerable<T> IntersectById<T>(IEnumerable<T>? enumerable, IEnumerable<string> ids)
where T : IIdentifiable => enumerable?.IntersectBy(ids, static b => b.Identifier) ?? Enumerable.Empty<T>();

private static IEnumerable<T> IntersectById<T>(IEnumerable<T>? enumerable, IEnumerable<long> ids)
where T : IIdentifiable => enumerable?.IntersectBy(ids, static b => long.Parse(b.Identifier)) ?? Enumerable.Empty<T>();

private static IEnumerable<T> IntersectById<T>(IEnumerable<T>? enumerable, IEnumerable<int> ids)
where T : IIdentifiable => enumerable?.IntersectBy(ids, static b => int.Parse(b.Identifier)) ?? Enumerable.Empty<T>();

private static void ProcessBlock(Block block, ResponseData data)
{
block.Curators.AddRange(IntersectById(data.Curators, block.CuratorsIds));
block.Groups.AddRange(IntersectById(data.Groups, block.GroupIds));
block.Playlists.AddRange(IntersectById(data.Playlists, block.PlaylistsIds));
block.Artists.AddRange(IntersectById(data.Artists, block.ArtistsIds));
block.Audios.AddRange(IntersectById(data.Audios, block.AudiosIds));
block.Suggestions.AddRange(IntersectById(data.Suggestions, block.SuggestionsIds));
block.Banners.AddRange(IntersectById(data.CatalogBanners, block.CatalogBannerIds));
block.Links.AddRange(IntersectById(data.Links, block.LinksIds));
block.Texts.AddRange(IntersectById(data.Texts, block.TextIds));
block.Suggestions.AddRange(IntersectById(data.Suggestions, block.SuggestionsIds));
block.PodcastSliderItems.AddRange(IntersectById(data.PodcastSliderItems, block.PodcastSliderItemsIds));
block.PodcastEpisodes.AddRange(IntersectById(data.PodcastEpisodes, block.PodcastEpisodesIds));
block.Longreads.AddRange(IntersectById(data.Longreads, block.LongreadsIds));
block.Videos.AddRange(IntersectById(data.Videos, block.VideosIds));
block.ArtistVideos.AddRange(IntersectById(data.ArtistVideos, block.ArtistVideosIds));
block.Placeholders.AddRange(IntersectById(data.Placeholders, block.PlaceholdersIds));
block.MusicOwners.AddRange(IntersectById(data.MusicOwners, block.MusicOwnerIds));
block.FollowingsUpdateInfos.AddRange(IntersectById(data.FollowingsUpdateInfos, block.FollowingUpdateInfoIds));
block.RecommendedPlaylists.AddRange(IntersectById(data.RecommendedPlaylists, block.PlaylistsIds));
foreach (var recommendedPlaylist in block.RecommendedPlaylists)
{
recommendedPlaylist.Audios.AddRange(IntersectById(data.Audios, recommendedPlaylist.AudiosIds));
recommendedPlaylist.Playlist = IntersectById(data.Playlists, new []{ ((IIdentifiable)recommendedPlaylist).Identifier }).FirstOrDefault()!;
}
foreach (var audio in block.Audios)
{
audio.ParentBlockId = block.Id;
}
}

private static void ProcessSection(Section section, ResponseData data)
{
foreach (var block in section.Blocks)
{
ProcessBlock(block, data);
}
RemoveEmptySeparators(section);
RemoveAds(section);
MergeRefBlocks(section);
}

private static void RemoveEmptySeparators(Section section)
{
var snippetsBannerIndex = section.Blocks.FindIndex(b => b is { Layout.Name: "snippets_banner" });

if (snippetsBannerIndex < 0) return;

section.Blocks.RemoveAt(snippetsBannerIndex);
section.Blocks.RemoveAt(snippetsBannerIndex); // excess separator
}

private static void RemoveAds(Section section)
{
section.Blocks.RemoveAll(block =>
block is { DataType: "radiostations" } or { Layout.Title: "Радиостанции" or "Эфиры" } ||
(
block is { Banners.Count: > 0 } &&
block.Banners.RemoveAll(banner => banner.ClickAction?.Action.Url.Contains("subscription") is true ||
banner.ClickAction?.Action.Url.Contains("combo") is true ||
banner.ClickAction?.Action.Url.Contains("https://vk.com/app") is true ||
banner.ClickAction?.Action.Url.Contains("https://vk.com/vk_music") is true) > 0 &&
block.Banners.Count == 0
) ||
(
block is { Links.Count: > 0 } &&
block.Links.RemoveAll(link => link.Url.Contains("audio_offline") ||
link.Url.Contains("radiostations") ||
link.Url.Contains("music_transfer") ||
link.Url.Contains("subscription")) > 0 &&
block.Links.Count == 0
)
);
}

private static void MergeRefBlocks(Section section)
{
for (var i = 0; i < section.Blocks.Count; i++)
{
var block = section.Blocks[i];

if (block is not { DataType: "action", Layout.Name: "horizontal_buttons" }) continue;

var refBlockIndex = section.Blocks.FindIndex(b =>
b.DataType == block.Actions[0].RefDataType && b.Layout?.Name == block.Actions[0].RefLayoutName) - 1;

if (refBlockIndex < 0 || block.Actions[0].Action.Type != "open_section") continue;

section.Blocks[refBlockIndex].Actions.AddRange(block.Actions);
section.Blocks.RemoveAt(i);
i--;
}
}

private static void FillPlaylistOwnerName(Playlist playlist, ResponseData data)
{
var ownerId = playlist.Original?.OwnerId ?? playlist.OwnerId;

if (ownerId < 0)
{
var value = data.Groups?.FirstOrDefault(b => b.Id == -ownerId);
playlist.OwnerName = value?.Name;
}
else
{
var value = data.Profiles?.FirstOrDefault(p => p.Id == ownerId);
playlist.OwnerName = $"{value?.FirstName} {value?.LastName}";
}
}
}
Loading

0 comments on commit 02ba224

Please sign in to comment.