Skip to content

Commit

Permalink
Merge changes from bill
Browse files Browse the repository at this point in the history
  • Loading branch information
oonqt committed May 20, 2021
1 parent 3fd17e5 commit d854deb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
12 changes: 5 additions & 7 deletions Emby.Notifications.Discord/Emby.Notifications.Discord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<AssemblyVersion>1.0.7.9</AssemblyVersion>
<FileVersion>1.0.7.9</FileVersion>
<AssemblyVersion>1.1.1.2</AssemblyVersion>
<FileVersion>1.1.1.2</FileVersion>
<Version>1.1.1.2</Version>
<Description>Unofficial Version</Description>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -45,11 +47,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediaBrowser.Server.Core" Version="4.3.0.30" />
<PackageReference Include="MediaBrowser.Server.Core" Version="4.6.0.50" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetPath)&quot; &quot;%AppData%\Emby-Server\programdata\plugins\&quot; /y" />
</Target>
</Project>
48 changes: 28 additions & 20 deletions Emby.Notifications.Discord/Notifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ private void CheckForMetadata(object sender, ElapsedEventArgs eventArgs)
string LibraryType = item.GetType().Name;
string serverName = options.ServerNameOverride ? serverConfig.ServerName : "Emby Server";

if (string.IsNullOrEmpty(serverName))
serverName = "Emby Server";

// for whatever reason if you have extraction on during library scans then it waits for the extraction to finish before populating the metadata.... I don't get why the fuck it goes in that order
// its basically impossible to make a prediction on how long it could take as its dependent on the bitrate, duration, codec, and processing power of the system
Boolean localMetadataFallback = queuedUpdateCheck[queuedItem.Key].Retries >= (itemLibraryOptions.ExtractChapterImagesDuringLibraryScan ? Constants.MaxRetriesBeforeFallback * 5.5 : Constants.MaxRetriesBeforeFallback);
Expand All @@ -124,7 +127,7 @@ private void CheckForMetadata(object sender, ElapsedEventArgs eventArgs)
{
_logger.Debug("{0}[{1}] has metadata (Local fallback: {2}), adding to queue", item.Id, item.Name, localMetadataFallback, options.MediaBrowserUserId);

if(queuedUpdateCheck.ContainsKey(queuedItem.Key)) queuedUpdateCheck.Remove(queuedItem.Key); // remove it beforehand because if some operation takes any longer amount of time it might allow enough time for another notification to slip through
if (queuedUpdateCheck.ContainsKey(queuedItem.Key)) queuedUpdateCheck.Remove(queuedItem.Key); // remove it beforehand because if some operation takes any longer amount of time it might allow enough time for another notification to slip through

// build primary info
DiscordMessage mediaAddedEmbed = new DiscordMessage
Expand All @@ -147,12 +150,11 @@ private void CheckForMetadata(object sender, ElapsedEventArgs eventArgs)
};

// populate title

string titleText;

if (LibraryType == "Episode")
{
titleText = $"{item.Parent.Parent.Name}{(item.ParentIndexNumber.HasValue ? $" S{formatIndex(item.ParentIndexNumber)}" : "")}{(item.IndexNumber.HasValue ? $"E{formatIndex(item.IndexNumber)}" : "")} {item.Name}";
titleText = $"{item.Parent.Parent.Name}{(item.ParentIndexNumber.HasValue ? $" S{formatIndex(item.ParentIndexNumber)}" : "")}{(item.IndexNumber.HasValue ? $"E{formatIndex(item.IndexNumber)}" : "")} {item.Name}";

} else if (LibraryType == "Season") {
titleText = $"{item.Parent.Name} {item.Name}";
}
Expand Down Expand Up @@ -230,7 +232,6 @@ private void CheckForMetadata(object sender, ElapsedEventArgs eventArgs)
};
}


if (options.MentionType == MentionTypes.Everyone)
{
mediaAddedEmbed.content = "@everyone";
Expand All @@ -253,7 +254,6 @@ private void CheckForMetadata(object sender, ElapsedEventArgs eventArgs)
};

Boolean didPopulate = true;

switch (provider.Key.ToLower())
{
case "imdb":
Expand All @@ -277,16 +277,16 @@ private void CheckForMetadata(object sender, ElapsedEventArgs eventArgs)
}

if (didPopulate == true) providerFields.Add(field);
});
});

if (providerFields.Count() > 0) mediaAddedEmbed.embeds.First().fields = providerFields;
if (providerFields.Count() > 0) mediaAddedEmbed.embeds.First().fields = providerFields;
}

pendingSendQueue.Add(mediaAddedEmbed, options);
}
}
else
{
if(queuedUpdateCheck.ContainsKey(queuedItem.Key)) queuedUpdateCheck[queuedItem.Key].Retries++;
if (queuedUpdateCheck.ContainsKey(queuedItem.Key)) queuedUpdateCheck[queuedItem.Key].Retries++;
}
}
});
Expand Down Expand Up @@ -338,17 +338,25 @@ private bool isInVisibleLibrary(string UserId, BaseItem item)
{
Boolean isIn = false;

_userViewManager.GetUserViews(
new UserViewQuery
{
UserId = _userManager.GetInternalId(Guid.Parse(UserId))
}
).ToList().ForEach(folder => {
if (folder.GetItemIdList(new InternalItemsQuery { IncludeItemTypes = new string[] { "MusicAlbum", "Movie", "Episode", "Series", "Season", "Audio" }, Recursive = true }).Contains(item.InternalId))
try
{
_userViewManager.GetUserViews(
new UserViewQuery
{
UserId = _userManager.GetInternalId(Guid.Parse(UserId))
}
).ToList().ForEach(folder =>
{
isIn = true;
}
});
if (folder.GetItemIdList(new InternalItemsQuery { IncludeItemTypes = new string[] { "MusicAlbum", "Movie", "Episode", "Series", "Season", "Audio" }, Recursive = true }).Contains(item.InternalId))
{
isIn = true;
}
});
}
catch (Exception ex)
{
_logger.ErrorException("Something unexpected happened in isInVisibleLibrary (Potentially options.MediaBrowserUserId is null). UserID = " + UserId, ex);
}

return isIn;
}
Expand Down

0 comments on commit d854deb

Please sign in to comment.