Skip to content

Commit

Permalink
Extractor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Oct 17, 2019
1 parent 4f3ad75 commit af8f126
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<RepositoryType>git</RepositoryType>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<NeutralLanguage>en</NeutralLanguage>
<Version>0.8.16</Version>
<Version>0.8.17</Version>
<Platform>AnyCPU</Platform>

<LangVersion>7.3</LangVersion>
Expand Down
7 changes: 4 additions & 3 deletions MediaManager/Library/DownloadStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
{
public enum DownloadStatus
{
NotDownloaded = 0,
Downloading,
Downloaded
Unknown = 0,
NotDownloaded = 1,
Downloading = 2,
Downloaded = 3
}
}
9 changes: 9 additions & 0 deletions MediaManager/Library/IMediaItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public interface IMediaItem : IContentItem
/// </summary>
int DiscNumber { get; set; }

object DisplayImage { get; set; }

string DisplayImageUri { get; set; }

/// <summary>
/// The metadata for a CharSequence or string typed value to retrieve the information about the description that is suitable for display to the user.
/// </summary>
Expand Down Expand Up @@ -166,6 +170,11 @@ public interface IMediaItem : IContentItem
/// </summary>
string FileExtension { get; set; }

/// <summary>
/// The name of the media file
/// </summary>
string FileName { get; set; }

/// <summary>
/// The type of the media item
/// Standard Type is Default which will try to play in the standard way.
Expand Down
102 changes: 84 additions & 18 deletions MediaManager/Library/MediaItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,101 @@ public int DiscNumber
set => SetProperty(ref _discNumber, value);
}

private string _displayDescription;
public string DisplayDescription
private object _displayImage;
public object DisplayImage
{
get => _displayDescription;
set => SetProperty(ref _displayDescription, value);
get
{
if (_displayImage != null)
return _displayImage;
if (Image != null)
return Image;
else if (AlbumImage != null)
return AlbumImage;
else
return null;
}

set => SetProperty(ref _displayImage, value);
}

private object _displayIcon;
public object DisplayIcon
private string _displayImageUri;
public string DisplayImageUri
{
get => _displayIcon;
set => SetProperty(ref _displayIcon, value);
get
{
if (!string.IsNullOrEmpty(_displayImageUri))
return _displayImageUri;
if (!string.IsNullOrEmpty(ImageUri))
return ImageUri;
else if (!string.IsNullOrEmpty(AlbumImageUri))
return AlbumImageUri;
else
return string.Empty;
}

set => SetProperty(ref _displayImageUri, value);
}

private string _displayIconUri;
public string DisplayIconUri
private string _displayTitle;
public string DisplayTitle
{
get => _displayIconUri;
set => SetProperty(ref _displayIconUri, value);
get
{
if (!string.IsNullOrEmpty(_displayTitle))
return _displayTitle;
else if (!string.IsNullOrEmpty(Title))
return Title;
else if (!string.IsNullOrEmpty(FileName))
return FileName;
else
return string.Empty;
}

set => SetProperty(ref _displayTitle, value);
}

private string _displaySubtitle;
public string DisplaySubtitle
{
get => _displaySubtitle;
get
{
if (!string.IsNullOrEmpty(_displaySubtitle))
return _displaySubtitle;
else if (!string.IsNullOrEmpty(Artist))
return Artist;
else if (!string.IsNullOrEmpty(AlbumArtist))
return AlbumArtist;
else if (!string.IsNullOrEmpty(Album))
return Album;
else
return string.Empty;
}

set => SetProperty(ref _displaySubtitle, value);
}

private string _displayTitle;
public string DisplayTitle
private string _displayDescription;
public string DisplayDescription
{
get => _displayTitle;
set => SetProperty(ref _displayTitle, value);
get
{
if (!string.IsNullOrEmpty(_displayDescription))
return _displayDescription;
else if (!string.IsNullOrEmpty(Album))
return Album;
else if (!string.IsNullOrEmpty(Artist))
return Artist;
else if (!string.IsNullOrEmpty(AlbumArtist))
return AlbumArtist;
else
return string.Empty;
}

set => SetProperty(ref _displayDescription, value);
}

private DownloadStatus _downloadStatus = DownloadStatus.NotDownloaded;
private DownloadStatus _downloadStatus = DownloadStatus.Unknown;
public DownloadStatus DownloadStatus
{
get => _downloadStatus;
Expand Down Expand Up @@ -235,6 +294,13 @@ public string FileExtension
set => SetProperty(ref _fileExtension, value);
}

private string _fileName;
public string FileName
{
get => _fileName;
set => SetProperty(ref _fileName, value);
}

private MediaType _mediaType = MediaType.Default;
public MediaType MediaType
{
Expand Down
26 changes: 3 additions & 23 deletions MediaManager/Library/MediaItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static string GetTitle(this IMediaItem mediaItem)
else if (!string.IsNullOrEmpty(mediaItem.Title))
return mediaItem.Title;
else
return "";
return string.Empty;
}

public static string GetContentTitle(this IMediaItem mediaItem)
Expand All @@ -37,7 +37,7 @@ public static string GetContentTitle(this IMediaItem mediaItem)
else if (!string.IsNullOrEmpty(mediaItem.Album))
return mediaItem.Album;
else
return "";
return string.Empty;
}

public static string GetSubText(this IMediaItem mediaItem)
Expand All @@ -49,27 +49,7 @@ public static string GetSubText(this IMediaItem mediaItem)
else if (!string.IsNullOrEmpty(mediaItem.AlbumArtist))
return mediaItem.AlbumArtist;
else
return "";
}

public static string GetImageUri(this IMediaItem mediaItem)
{
if (!string.IsNullOrEmpty(mediaItem.ImageUri))
return mediaItem.ImageUri;
else if (!string.IsNullOrEmpty(mediaItem.AlbumImageUri))
return mediaItem.AlbumImageUri;
else
return "";
}

public static object GetImage(this IMediaItem mediaItem)
{
if (mediaItem.Image != null)
return mediaItem.Image;
else if (mediaItem.AlbumImage != null)
return mediaItem.AlbumImage;
else
return null;
return string.Empty;
}
}
}
61 changes: 45 additions & 16 deletions MediaManager/Media/MediaExtractorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,29 @@ public virtual async Task<IMediaItem> CreateMediaItemFromResource(string resourc

public virtual async Task<IMediaItem> UpdateMediaItem(IMediaItem mediaItem)
{
if (!mediaItem.IsMetadataExtracted)
if (string.IsNullOrEmpty(mediaItem.FileName))
{
mediaItem.FileName = GetFileName(mediaItem);
}
if (string.IsNullOrEmpty(mediaItem.FileExtension))
{
mediaItem.FileExtension = GetFileExtension(mediaItem);
}
if (mediaItem.MediaLocation == MediaLocation.Unknown)
{
mediaItem.MediaLocation = GetMediaLocation(mediaItem);
}
if (mediaItem.MediaType == MediaType.Default)
{
mediaItem.MediaType = GetMediaType(mediaItem);
}
if (mediaItem.DownloadStatus == DownloadStatus.Unknown)
{
if (string.IsNullOrEmpty(mediaItem.FileExtension))
{
mediaItem.FileExtension = GetFileExtension(mediaItem);
}
if (mediaItem.MediaLocation == MediaLocation.Unknown)
{
mediaItem.MediaLocation = GetMediaLocation(mediaItem);
}
if (mediaItem.MediaType == MediaType.Default)
{
mediaItem.MediaType = GetMediaType(mediaItem);
}
mediaItem.DownloadStatus = GetDownloadStatus(mediaItem);
}

if (!mediaItem.IsMetadataExtracted)
{
mediaItem = await GetMetadata(mediaItem).ConfigureAwait(false);
mediaItem.Image = await GetMediaImage(mediaItem).ConfigureAwait(false);
mediaItem.IsMetadataExtracted = true;
Expand All @@ -172,7 +179,7 @@ public async Task<object> GetMediaImage(IMediaItem mediaItem)
object image = null;

if (mediaItem.IsMetadataExtracted)
image = mediaItem.GetImage();
image = mediaItem.DisplayImage;

if (image == null)
{
Expand Down Expand Up @@ -200,21 +207,42 @@ public async Task<object> GetVideoFrame(IMediaItem mediaItem, TimeSpan timeFromS

protected abstract Task<string> GetResourcePath(string resourceName);

public virtual string GetFileName(IMediaItem mediaItem)
{
if (string.IsNullOrEmpty(mediaItem?.MediaUri))
return string.Empty;

string url;
if (!Uri.TryCreate(mediaItem.MediaUri, UriKind.Absolute, out var uri))
uri = new Uri(mediaItem.MediaUri);

url = Path.GetFileName(uri.LocalPath);
if (string.IsNullOrEmpty(url))
url = uri.Segments.LastOrDefault();

return url;
}

public virtual string GetFileExtension(IMediaItem mediaItem)
{
var url = mediaItem?.MediaUri?.ToLower();
var fileName = mediaItem?.FileName;

if (string.IsNullOrEmpty(url) && string.IsNullOrEmpty(fileName))
return string.Empty;

var suffixes = VideoSuffixes.Union(AudioSuffixes).Union(HlsSuffixes).Union(DashSuffixes).Union(SmoothStreamingSuffixes);

//Try to find the best match
foreach (var item in suffixes)
{
if (url.EndsWith(item))
if (fileName.EndsWith(item) || url.EndsWith(item))
return item;
}
//If no match available see if the url contains info
foreach (var item in suffixes)
{
if (url.Contains(item))
if (fileName.Contains(item) || url.Contains(item))
return item;
}
return mediaItem?.FileExtension;
Expand Down Expand Up @@ -278,6 +306,7 @@ public virtual DownloadStatus GetDownloadStatus(IMediaItem mediaItem)
switch (mediaItem.MediaLocation)
{
case MediaLocation.Unknown:
return DownloadStatus.Unknown;
case MediaLocation.Remote:
return DownloadStatus.NotDownloaded;
case MediaLocation.FileSystem:
Expand Down
19 changes: 9 additions & 10 deletions MediaManager/Platforms/Android/Media/MediaDescriptionAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Android.Runtime;
using Com.Google.Android.Exoplayer2;
using Com.Google.Android.Exoplayer2.UI;
using MediaManager.Library;

namespace MediaManager.Platforms.Android.Media
{
Expand All @@ -29,31 +28,31 @@ public PendingIntent CreateCurrentContentIntent(IPlayer player)

public string GetCurrentContentText(IPlayer player)
{
return MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex)?.GetTitle();
return MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex)?.DisplayTitle;
}

public string GetCurrentContentTitle(IPlayer player)
{
return MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex)?.GetContentTitle();
return MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex)?.DisplaySubtitle;
}

public string GetCurrentSubText(IPlayer player)
{
return MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex)?.DisplayDescription;
}

public Bitmap GetCurrentLargeIcon(IPlayer player, PlayerNotificationManager.BitmapCallback callback)
{
var mediaItem = MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex);
if (mediaItem != null)
if (mediaItem != null && mediaItem.DisplayImage == null)
{
Task.Run(async () =>
{
var image = await MediaManager.Extractor.GetMediaImage(mediaItem).ConfigureAwait(false) as Bitmap;
callback.OnBitmap(image);
}).ConfigureAwait(false);
}
return null;
}

public string GetCurrentSubText(IPlayer player)
{
return MediaManager.Queue.ElementAtOrDefault(player.CurrentWindowIndex)?.GetSubText();
return mediaItem?.DisplayImage as Bitmap;
}
}
}
Loading

0 comments on commit af8f126

Please sign in to comment.