mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-12 02:30:23 +01:00
Added initial implementation of the metadata provider network, along with the first few providers
This commit is contained in:
parent
803ce0968e
commit
d794eecec4
86
MediaBrowser.Controller/Providers/AudioInfoProvider.cs
Normal file
86
MediaBrowser.Controller/Providers/AudioInfoProvider.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Controller.FFMpeg;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
[Export(typeof(BaseMetadataProvider))]
|
||||
public class AudioInfoProvider : BaseMetadataProvider
|
||||
{
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is Audio;
|
||||
}
|
||||
|
||||
public async override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||
{
|
||||
Audio audio = item as Audio;
|
||||
|
||||
string outputDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, item.Id.ToString().Substring(0, 1));
|
||||
|
||||
string outputPath = Path.Combine(outputDirectory, item.Id + "-" + item.DateModified.Ticks + ".js");
|
||||
|
||||
FFProbeResult data = await FFProbe.Run(audio, outputPath);
|
||||
|
||||
MediaStream stream = data.streams.FirstOrDefault(s => s.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
audio.Channels = stream.channels;
|
||||
|
||||
string bitrate = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(stream.sample_rate))
|
||||
{
|
||||
audio.SampleRate = int.Parse(stream.sample_rate);
|
||||
|
||||
bitrate = stream.bit_rate;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(bitrate))
|
||||
{
|
||||
bitrate = data.format.bit_rate;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(bitrate))
|
||||
{
|
||||
audio.BitRate = int.Parse(bitrate);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetOutputCachePath(BaseItem item)
|
||||
{
|
||||
string outputDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, item.Id.ToString().Substring(0, 1));
|
||||
|
||||
return Path.Combine(outputDirectory, item.Id + "-" + item.DateModified.Ticks + ".js");
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
for (int i = 0; i <= 9; i++)
|
||||
{
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, i.ToString()));
|
||||
}
|
||||
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "a"));
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "b"));
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "c"));
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "d"));
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "e"));
|
||||
EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "f"));
|
||||
}
|
||||
|
||||
private void EnsureDirectory(string path)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
MediaBrowser.Controller/Providers/BaseMetadataProvider.cs
Normal file
23
MediaBrowser.Controller/Providers/BaseMetadataProvider.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
public abstract class BaseMetadataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// If the provider needs any startup routines, add them here
|
||||
/// </summary>
|
||||
public virtual void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool Supports(BaseItem item)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract Task Fetch(BaseItem item, ItemResolveEventArgs args);
|
||||
}
|
||||
}
|
||||
30
MediaBrowser.Controller/Providers/FolderProviderFromXml.cs
Normal file
30
MediaBrowser.Controller/Providers/FolderProviderFromXml.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Controller.Xml;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
[Export(typeof(BaseMetadataProvider))]
|
||||
public class FolderProviderFromXml : BaseMetadataProvider
|
||||
{
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is Folder;
|
||||
}
|
||||
|
||||
public override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var metadataFile = args.GetFileByName("folder.xml");
|
||||
|
||||
if (metadataFile.HasValue)
|
||||
{
|
||||
new FolderXmlParser().Fetch(item as Folder, metadataFile.Value.Key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
[Export(typeof(BaseMetadataProvider))]
|
||||
public class ImageFromMediaLocationProvider : BaseMetadataProvider
|
||||
{
|
||||
public override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (args.IsFolder)
|
||||
{
|
||||
PopulateImages(item, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills in image paths based on files win the folder
|
||||
/// </summary>
|
||||
private void PopulateImages(BaseItem item, ItemResolveEventArgs args)
|
||||
{
|
||||
List<string> backdropFiles = new List<string>();
|
||||
|
||||
foreach (KeyValuePair<string, FileAttributes> file in args.FileSystemChildren)
|
||||
{
|
||||
if (file.Value.HasFlag(FileAttributes.Directory))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string filePath = file.Key;
|
||||
|
||||
string ext = Path.GetExtension(filePath);
|
||||
|
||||
// Only support png and jpg files
|
||||
if (!ext.EndsWith("png", StringComparison.OrdinalIgnoreCase) && !ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string name = Path.GetFileNameWithoutExtension(filePath);
|
||||
|
||||
if (name.Equals("folder", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.PrimaryImagePath = filePath;
|
||||
}
|
||||
else if (name.StartsWith("backdrop", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
backdropFiles.Add(filePath);
|
||||
}
|
||||
if (name.Equals("logo", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.LogoImagePath = filePath;
|
||||
}
|
||||
if (name.Equals("banner", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.BannerImagePath = filePath;
|
||||
}
|
||||
if (name.Equals("art", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.ArtImagePath = filePath;
|
||||
}
|
||||
if (name.Equals("thumb", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.ThumbnailImagePath = filePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (backdropFiles.Any())
|
||||
{
|
||||
item.BackdropImagePaths = backdropFiles;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
MediaBrowser.Controller/Providers/LocalTrailerProvider.cs
Normal file
39
MediaBrowser.Controller/Providers/LocalTrailerProvider.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
[Export(typeof(BaseMetadataProvider))]
|
||||
public class LocalTrailerProvider : BaseMetadataProvider
|
||||
{
|
||||
public async override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||
{
|
||||
var trailerPath = args.GetFolderByName("trailers");
|
||||
|
||||
if (trailerPath.HasValue)
|
||||
{
|
||||
string[] allFiles = Directory.GetFileSystemEntries(trailerPath.Value.Key, "*", SearchOption.TopDirectoryOnly);
|
||||
|
||||
List<Video> localTrailers = new List<Video>();
|
||||
|
||||
foreach (string file in allFiles)
|
||||
{
|
||||
BaseItem child = await Kernel.Instance.ItemController.GetItem(null, file);
|
||||
|
||||
Video video = child as Video;
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
localTrailers.Add(video);
|
||||
}
|
||||
}
|
||||
|
||||
item.LocalTrailers = localTrailers;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user