Пример #1
0
        public R <Image> GetThumbnail(PlayResource playResource)
        {
            var uri    = new Uri(playResource.PlayUri);
            var result = GetStreamFromUriUnsafe(uri);

            if (!result)
            {
                return(result.Error);
            }

            using (var stream = result.Value)
            {
                var data = AudioTagReader.GetImage(stream);
                if (data == null)
                {
                    return("No image found");
                }

                using (var memStream = new MemoryStream(data))
                {
                    try
                    {
                        return(new Bitmap(memStream));
                    }
                    catch (ArgumentException)
                    {
                        return("Inavlid image data");
                    }
                }
            }
        }
Пример #2
0
        private static HeaderData GetStreamHeaderData(Stream stream)
        {
            var headerData = AudioTagReader.GetData(stream) ?? new HeaderData();

            headerData.Title = headerData.Title ?? string.Empty;
            return(headerData);
        }
Пример #3
0
        public R <Stream, LocalStr> GetThumbnail(ResolveContext _, PlayResource playResource)
        {
            byte[] rawImgData;

            if (playResource is MediaPlayResource mediaPlayResource)
            {
                rawImgData = mediaPlayResource.Image;
            }
            else
            {
                var uri    = new Uri(playResource.PlayUri);
                var result = GetStreamFromUriUnsafe(uri);
                if (!result)
                {
                    return(result.Error);
                }

                using (var stream = result.Value)
                {
                    rawImgData = AudioTagReader.GetData(stream)?.Picture;
                }
            }

            if (rawImgData is null)
            {
                return(new LocalStr(strings.error_media_image_not_found));
            }

            return(new MemoryStream(rawImgData));
        }
Пример #4
0
        public async Task GetThumbnail(ResolveContext _, PlayResource playResource, Func <Stream, Task> action)
        {
            byte[]? rawImgData;

            if (playResource is MediaPlayResource mediaPlayResource)
            {
                rawImgData = mediaPlayResource.Image;
            }
            else
            {
                var uri = new Uri(playResource.PlayUri);

                if (uri.IsWeb())
                {
                    rawImgData = await WebWrapper.Request(uri)
                                 .ToAction(async response => AudioTagReader.GetData(await response.Content.ReadAsStreamAsync())?.Picture);
                }
                else if (uri.IsFile())
                {
                    rawImgData = AudioTagReader.GetData(File.OpenRead(uri.LocalPath))?.Picture;
                }
                else
                {
                    throw Error.LocalStr(strings.error_media_invalid_uri);
                }
            }

            if (rawImgData is null)
            {
                throw Error.LocalStr(strings.error_media_image_not_found);
            }

            await action(new MemoryStream(rawImgData));
        }
Пример #5
0
 private static void GetStreamData(string id, ref string name, Stream stream)
 {
     if (string.IsNullOrEmpty(name))
     {
         if (stream != null)
         {
             name = AudioTagReader.GetTitle(stream);
             name = string.IsNullOrWhiteSpace(name) ? id : name;
         }
         else
         {
             name = id;
         }
     }
 }
Пример #6
0
        public R <Image> GetThumbnail(PlayResource playResource)
        {
            byte[] rawImgData;

            if (playResource is MediaPlayResource mediaPlayResource)
            {
                rawImgData = mediaPlayResource.Image;
            }
            else
            {
                var uri    = new Uri(playResource.PlayUri);
                var result = GetStreamFromUriUnsafe(uri);
                if (!result)
                {
                    return(result.Error);
                }

                using (var stream = result.Value)
                {
                    rawImgData = AudioTagReader.GetData(stream)?.Picture;
                }
            }

            if (rawImgData == null)
            {
                return("No image found");
            }

            using (var memStream = new MemoryStream(rawImgData))
            {
                try
                {
                    return(new Bitmap(memStream));
                }
                catch (ArgumentException)
                {
                    return("Inavlid image data");
                }
            }
        }
Пример #7
0
 private static string GetStreamName(Stream stream)
 => AudioTagReader.GetTitle(stream) ?? string.Empty;