Skip to content

Commit

Permalink
Merge pull request #41 from cnapolit/main
Browse files Browse the repository at this point in the history
Update for v5.0
  • Loading branch information
cnapolit authored Oct 29, 2022
2 parents 4394639 + 7580a59 commit d82fe3d
Show file tree
Hide file tree
Showing 33 changed files with 296 additions and 411 deletions.
182 changes: 1 addition & 181 deletions Common/Constants/Resource.cs

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions Downloaders/KHDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ public IEnumerable<Album> GetAlbumsForGame(string gameName, bool auto = false)
var tableRows = htmlDoc.DocumentNode.Descendants("tr").Skip(1);
foreach (var row in tableRows)
{
var columnEntries = row.Descendants("td").Skip(1).ToList();
var columnEntries = row.Descendants("td").ToList();

var titleField = columnEntries.FirstOrDefault();
var iconUrl = string.Empty;
var iconField = columnEntries.FirstOrDefault();
if (iconField != null)
{
var img = iconField.Descendants("img").FirstOrDefault();
if (img != null)
{
iconUrl = img.GetAttributeValue("src", string.Empty);
}
}

var titleField = columnEntries.ElementAtOrDefault(1);
if (titleField == null)
{
Logger.Info($"Found album entry of game '{gameName}' without title field");
Expand All @@ -66,7 +77,8 @@ public IEnumerable<Album> GetAlbumsForGame(string gameName, bool auto = false)
{
Name = StringUtilities.StripStrings(albumName),
Id = albumPartialLink,
Source = Source.KHInsider
Source = Source.KHInsider,
IconUrl = iconUrl
};

var platformEntry = columnEntries.ElementAtOrDefault(1);
Expand Down
9 changes: 6 additions & 3 deletions Downloaders/YtDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ from VideoSearchResult videoSearchResult in videoEnumerator.Current.Items
Name = videoSearchResult.Title,
Id = videoSearchResult.Id,
Length = videoSearchResult.Duration,
Source = DlSource
Source = DlSource,
IconUrl = videoSearchResult.Thumbnails.FirstOrDefault()?.Url
};

videos.AddRange(batchOfVideos);
Expand Down Expand Up @@ -89,7 +90,8 @@ from PlaylistSearchResult playlistSearchResult in playlistEnumerator.Current.Ite
{
Name = playlistSearchResult.Title,
Id = playlistSearchResult.Id,
Source = DlSource
Source = DlSource,
IconUrl = playlistSearchResult.Thumbnails.FirstOrDefault()?.Url
};

albums.AddRange(batchOfPlaylists);
Expand All @@ -105,7 +107,8 @@ private IAsyncEnumerable<Song> GetSongsFromExplodeApiAsync(Album album)
Name = video.Title,
Id = video.Id,
Length = video.Duration,
Source = DlSource
Source = DlSource,
IconUrl= video.Thumbnails.FirstOrDefault()?.Url
});

private async Task<bool> DownloadSongExplodeAsync(Song song, string path)
Expand Down
21 changes: 14 additions & 7 deletions Localization/LocSource.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

<!-- Settings Resources -->

<sys:String x:Key="LOC_PLAYNITESOUNDS_SoundWhere">Play Sound where:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_MusicWhere">Play Music where:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_SoundWhere">Play Sound State:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_MusicWhere">Play Music State:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_MusicType">Music Type:</sys:String>

<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusic">One music for all games and platforms</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatform">One music per platform</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatformGame">One music per platform and game</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkSkipFirstSelectSound">Skip first 'select sound' after playnite startup</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_Music">Music</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_Sound">Sound</sys:String>

<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusic">Default</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatform">Platform</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatformGame">Game</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeFilter">Filter</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkSkipFirstSelectSound">Skip first 'select' sound on startup</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkPauseOnDeactivate">Pause music when Playnite deactivates or minimizes</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkTagMissing">Tag titles that fail to download</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkAutoDownload">Automatically download music for newly added games on library update</sys:String>
Expand All @@ -23,6 +27,7 @@
<sys:String x:Key="LOC_PLAYNITESOUNDS_Normalize">Automatically normalize music when downloading</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_Normalize_Tag">Tag Normalized Games</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FF_Path">FFmpeg Path</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FF_Hint">FFmpeg is required for audio normalization and downloading</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FFNorm_Path">FFmpeg-Normalize Path</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FFNorm_Hint">Normalizing audio allows consistent volume between tracks without compromising quality</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FFNorm_Doc">FFmpeg-Normalize Documentation</sys:String>
Expand Down Expand Up @@ -77,7 +82,6 @@
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsCopyDeleteMusicFile">Delete</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsCopyPlayMusicFile">Play</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsSubMenuSongs">Songs</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsUpdateLegacy">Update Legacy Directory</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsPlatform">Platforms</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsFilter">Filters</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsDefault">Default</sys:String>
Expand Down Expand Up @@ -110,4 +114,7 @@
<sys:String x:Key="LOC_PLAYNITESOUNDS_ManagerImport">Import</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ManagerOpenManagerFolder">Open Sound Manager Folder</sys:String>

<sys:String x:Key="LOC_PLAYNITESOUNDS_Migrate">It appears the Playnite Sounds file layout is outdated. These files must be moved for Sounds to function. Would you like to migrate them?</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CreateBackup">This process may fail. Would you like to select a backup location for the Sounds files?</sys:String>

</ResourceDictionary>
21 changes: 14 additions & 7 deletions Localization/en_US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

<!-- Settings Resources -->

<sys:String x:Key="LOC_PLAYNITESOUNDS_SoundWhere">Play Sound where:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_MusicWhere">Play Music where:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_SoundWhere">Play Sound State:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_MusicWhere">Play Music State:</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_MusicType">Music Type:</sys:String>

<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusic">One music for all games and platforms</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatform">One music per platform</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatformGame">One music per platform and game</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkSkipFirstSelectSound">Skip first 'select sound' after playnite startup</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_Music">Music</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_Sound">Sound</sys:String>

<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusic">Default</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatform">Platform</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeOneMusicPlatformGame">Game</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CmbMusicTypeFilter">Filter</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkSkipFirstSelectSound">Skip first 'select' sound on startup</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkPauseOnDeactivate">Pause music when Playnite deactivates or minimizes</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkTagMissing">Tag titles that fail to download</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ChkAutoDownload">Automatically download music for newly added games on library update</sys:String>
Expand All @@ -23,6 +27,7 @@
<sys:String x:Key="LOC_PLAYNITESOUNDS_Normalize">Automatically normalize music when downloading</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_Normalize_Tag">Tag Normalized Games</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FF_Path">FFmpeg Path</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FF_Hint">FFmpeg is required for audio normalization and downloading</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FFNorm_Path">FFmpeg-Normalize Path</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FFNorm_Hint">Normalizing audio allows consistent volume between tracks without compromising quality</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_FFNorm_Doc">FFmpeg-Normalize Documentation</sys:String>
Expand Down Expand Up @@ -77,7 +82,6 @@
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsCopyDeleteMusicFile">Delete</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsCopyPlayMusicFile">Play</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsSubMenuSongs">Songs</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsUpdateLegacy">Update Legacy Directory</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsPlatform">Platforms</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsFilter">Filters</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ActionsDefault">Default</sys:String>
Expand Down Expand Up @@ -110,4 +114,7 @@
<sys:String x:Key="LOC_PLAYNITESOUNDS_ManagerImport">Import</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_ManagerOpenManagerFolder">Open Sound Manager Folder</sys:String>

<sys:String x:Key="LOC_PLAYNITESOUNDS_Migrate">It appears the Playnite Sounds file layout is outdated. These files must be moved for Sounds to function. Would you like to migrate them?</sys:String>
<sys:String x:Key="LOC_PLAYNITESOUNDS_CreateBackup">This process may fail. Would you like to select a backup location for the Sounds files?</sys:String>

</ResourceDictionary>
34 changes: 5 additions & 29 deletions Models/Album.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,20 @@

namespace PlayniteSounds.Models
{
internal class Album
internal class Album : DownloadItem
{
public string Name { get; set; }
public string Id { get; set; }
public string Type { get; set; }
public string Url { get; set; }
public string Artist { get; set; }
public Source Source { get; set; }
public uint? Count { get; set; }
public uint? Year { get; set; }
public IEnumerable<string> Platforms { get; set; }
public IEnumerable<Song> Songs { get; set; }

private static readonly IEnumerable<PropertyInfo> Properties = typeof(Album).GetProperties();
private static readonly IEnumerable<string> IgnoredFields = new[]
{
// Ignored Types
"Name",
"Url",
"Songs",
// Needs Custom Handling
"Id",
"Platforms"
};
protected override IEnumerable<PropertyInfo> Properties => typeof(Album).GetProperties();

public override string ToString()
{
var albumStrings =
from property in Properties
let propertyValue = property.GetValue(this)
where IsValidField(property, propertyValue)
select $"{property.Name}: {propertyValue}";
var albumStringsList = albumStrings.ToList();
var baseString = base.ToString();

if (Platforms != null)
{
Expand All @@ -45,16 +26,11 @@ where IsValidField(property, propertyValue)

if (!string.IsNullOrWhiteSpace(platformsValue))
{
albumStringsList.Add($"{nameof(Platforms)}: {platformsValue}");
baseString += $", {nameof(Platforms)}: {platformsValue}";
}
}

return string.Join(", ", albumStringsList);
return baseString;
}

private static bool IsValidField(PropertyInfo property, object propertyValue)
=> propertyValue != null
&& !IgnoredFields.ContainsString(property.Name)
&& !(propertyValue is string propertyString && string.IsNullOrWhiteSpace(propertyString));
}
}
45 changes: 45 additions & 0 deletions Models/DownloadItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace PlayniteSounds.Models
{
public abstract class DownloadItem
{
public string Name { get; set; }
public string Id { get; set; }
public string IconUrl { get; set; }
public Source Source { get; set; }


protected abstract IEnumerable<PropertyInfo> Properties { get; }

protected static readonly IEnumerable<string> IgnoredFields = new[]
{
// Ignored Types
"Name",
"Url",
"Songs",
"IconUrl",
// Needs Custom Handling
"Id",
"Platforms"
};

public override string ToString()
{
var strings =
from property in Properties
let propertyValue = property.GetValue(this)
where IsValidField(property, propertyValue)
select $"{property.Name}: {propertyValue}";

return string.Join(", ", strings);
}

private static bool IsValidField(PropertyInfo property, object propertyValue)
=> propertyValue != null
&& !IgnoredFields.ContainsString(property.Name)
&& !(propertyValue is string propertyString && string.IsNullOrWhiteSpace(propertyString));
}
}
5 changes: 1 addition & 4 deletions Models/GenericObjectOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ internal class GenericObjectOption : GenericItemOption
public Source Source { get; set; }
public object Object { get; set; }

public GenericObjectOption(string name, string description, object obj) : base(name, description)
{
Object = obj;
}
public GenericObjectOption(string name, string description, object obj) : base(name, description) => Object = obj;
}
}
26 changes: 2 additions & 24 deletions Models/Song.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,11 @@

namespace PlayniteSounds.Models
{
internal class Song
internal class Song : DownloadItem
{
public string Name { get; set; }
public string Id { get; set; }
public string Description { get; set; }
public string SizeInMb { get; set; }
public TimeSpan? Length { get; set; }
public Source Source { get; set; }

private static readonly IEnumerable<PropertyInfo> Properties = typeof(Song).GetProperties();
private static readonly IEnumerable<string> IgnoredFields = new[]
{
// Ignored Types
"Name",
"Id"
};

public override string ToString()
{
var albumStrings =
from property in Properties
let propertyValue = property.GetValue(this)
where propertyValue != null && !IgnoredFields.ContainsString(property.Name) &&
(!(propertyValue is string propertyString) || !string.IsNullOrWhiteSpace(propertyString))
select $"{property.Name}: {propertyValue}";

return string.Join(", ", albumStrings);
}
protected override IEnumerable<PropertyInfo> Properties => typeof(Song).GetProperties();
}
}
Loading

0 comments on commit d82fe3d

Please sign in to comment.