Exemplo n.º 1
0
        public void CanGetYoutubeMediaInformation()
        {
            string ExpectedVideoTitle       = "sample-title";
            string ExpectedVideoID          = "hW9tIK5pcl8";
            string ExpectedUploaderID       = "sample-uploader";
            string ExpectedDescription      = "sample-description";
            int    ExpectedLikes            = 51;
            int    ExpectedDislikes         = 12;
            int    ExpectedViews            = 314;
            double ExpectedDuration         = 312.54;
            string ExpectedVideoUri         = $"https://www.youtube.com/watch?v={ExpectedVideoID}";
            string ExpectedIdentifiedArtist = "sample-artist";
            string ExpectedIdentifiedSong   = "sample-song";
            string ExpectedUploadDate       = "20181216";

            MockForGetMediaInformationWithYoutubeTest processMock = new MockForGetMediaInformationWithYoutubeTest(
                ExpectedVideoTitle,
                ExpectedVideoID,
                ExpectedUploaderID,
                ExpectedDescription,
                ExpectedLikes,
                ExpectedDislikes,
                ExpectedViews,
                ExpectedDuration,
                ExpectedVideoUri,
                ExpectedIdentifiedArtist,
                ExpectedIdentifiedSong,
                ExpectedUploadDate
                );

            YoutubeDl         downloader = new YoutubeDl(processMock);
            IMediaInformation actual     = downloader.GetMediaInformation(new Uri(ExpectedVideoUri));

            Assert.IsTrue(processMock.ProcessStarted, "Youtube-dl was not started.");
            Assert.IsTrue(processMock.ParametersPassedCorrectly, "Command-line arguments were passed incorrectly to youtube-dl.");

            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(ILikeableMedia));
            Assert.IsInstanceOfType(actual, typeof(IIdentifiedSong));

            Assert.AreEqual(ExpectedVideoUri, actual.MediaUri);
            Assert.AreEqual(ExpectedDuration, actual.Duration);
            Assert.AreEqual(ExpectedVideoTitle, actual.Title);
            Assert.AreEqual(ExpectedDescription, actual.Description);
            Assert.AreEqual(ExpectedVideoID, actual.VideoId);

            ILikeableMedia actual2 = (ILikeableMedia)actual;

            Assert.AreEqual(ExpectedLikes, actual2.Likes);
            Assert.AreEqual(ExpectedDislikes, actual2.Dislikes);

            IIdentifiedSong actual3 = (IIdentifiedSong)actual;

            Assert.AreEqual(ExpectedIdentifiedArtist, actual3.Artist);
            Assert.AreEqual(ExpectedIdentifiedSong, actual3.TrackTitle);
        }
Exemplo n.º 2
0
 protected void LoadThumbnailFromMediaInformaion(IMediaItemInfo item, IMediaInformation mediaInformation)
 {
     if (mediaInformation != null)
     {
         //재생 시간 설정
         item.Duration = mediaInformation.NaturalDuration;
         mediaInformation.GetBitmapPixelBuffer(ThumbnailSize).Completed = (bufferResult, bufferStatus) =>
         {
             if (bufferStatus == AsyncStatus.Completed)
             {
                 var buffer = bufferResult.GetResults();
                 if (buffer != null)
                 {
                     DispatcherHelper.CheckBeginInvokeOnUI(() =>
                     {
                         WriteableBitmap wb = BitmapFactory.New(0, 0);
                         //wb.FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height).AsAsyncOperation().Completed = async (bitmap, bitmapStatus) =>
                         BitmapFactory.FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height).AsAsyncOperation().Completed = async(bitmap, bitmapStatus) =>
                         {
                             if (bitmapStatus == AsyncStatus.Completed)
                             {
                                 var newWb             = bitmap.GetResults();
                                 item.ImageItemsSource = newWb;
                                 //썸네일 저장
                                 if (item is StorageItemInfo)
                                 {
                                     await SaveThumbail(item as StorageItemInfo, buffer.ToArray());
                                 }
                                 else if (item is NetworkItemInfo)
                                 {
                                     await SaveThumbail(item as NetworkItemInfo, buffer.ToArray());
                                 }
                             }
                         };
                     });
                 }
             }
             mediaInformation = null;
         };
     }
 }
Exemplo n.º 3
0
        protected async Task <ImageSource> GetThumbnailAsync(IMediaItemInfo item, IMediaInformation mediaInformation)
        {
            ImageSource imageSource = null;

            if (mediaInformation != null)
            {
                var buffer = await mediaInformation.GetBitmapPixelBuffer(ThumbnailSize);

                if (buffer != null)
                {
                    await DispatcherHelper.RunAsync(async() =>
                    {
                        //imageSource = await BitmapFactory.New(0, 0).FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height);
                        imageSource = await BitmapFactory.FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height);

                        //PNG로 압축 및 DB저장
                        item.Duration = mediaInformation.NaturalDuration;
                        //썸네일 저장
                        if (item is StorageItemInfo)
                        {
                            await SaveThumbail(item as StorageItemInfo, buffer.ToArray());
                        }
                        else if (item is NetworkItemInfo)
                        {
                            await SaveThumbail(item as NetworkItemInfo, buffer.ToArray());
                        }
                        //비동기 처리 임으로 여기서 초기화 해야함.
                        mediaInformation = null;
                    });
                }
                else
                {
                    mediaInformation = null;
                }
            }
            return(imageSource);
        }
        private void ShowFlyout(Message <DecoderTypes> message)
        {
            Task.Factory.StartNew(async() =>
            {
                string displayName = null;
                IMediaInformation mediaInformation = null;
                if (message.ContainsKey("StorageItemInfo"))
                {
                    var sii        = message.GetValue <StorageItemInfo>("StorageItemInfo");
                    StorageFile sf = await sii.GetStorageFileAsync();
                    if (sf != null)
                    {
                        try
                        {
                            var stream       = await sf.OpenReadAsync();
                            mediaInformation = MediaInformationFactory.CreateMediaInformationFromStream(stream);
                            displayName      = sf.DisplayName;
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("로컬 파일 열기 실패 : " + e.Message);
                        }
                    }
                }
                else if (message.ContainsKey("NetworkItemInfo"))
                {
                    var wdii = message.GetValue <NetworkItemInfo>("NetworkItemInfo");

                    if (message.ContainsKey("VideoStream"))
                    {
                        Stream videoStream = message.GetValue <Stream>("VideoStream");
                        mediaInformation   = MediaInformationFactory.CreateMediaInformationFromStream(videoStream.AsRandomAccessStream());
                        displayName        = wdii.Name;
                    }
                    else
                    {
                        if (wdii.Uri != null)
                        {
                            try
                            {
                                string url = wdii.Uri.AbsoluteUri;
                                Windows.Foundation.Collections.PropertySet ps = null;

                                if (message.ContainsKey("UserName"))
                                {
                                    string username = message.GetValue <string>("UserName");
                                    string password = message.GetValue <string>("Password");
                                    url             = wdii.GetAuthenticateUrl(username, password);
                                }

                                if (message.ContainsKey("CodePage"))
                                {
                                    int codepage   = message.GetValue <int>("CodePage");
                                    ps             = new Windows.Foundation.Collections.PropertySet();
                                    ps["codepage"] = codepage;
                                }

                                mediaInformation = MediaInformationFactory.CreateMediaInformationFromUri(url, ps);
                                displayName      = wdii.Name;
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine("리모트(Uri) 파일 열기 실패 : " + e.Message);
                            }
                        }
                    }
                }

                await DispatcherHelper.RunAsync(async() =>
                {
                    MessengerInstance.Send(new Message("IsOpen", false), "ShowLoadingPanel");

                    if (mediaInformation == null)
                    {
                        System.Diagnostics.Debug.WriteLine("에러 발생.");
                        var resource = ResourceLoader.GetForCurrentView();
                        var dlg      = DialogHelper.GetSimpleContentDialog(
                            resource.GetString("Message/Error/LoadMedia"),
                            resource.GetString("Message/Error/CheckFile"),
                            resource.GetString("Button/Close/Content"));
                        await dlg.ShowAsync();
                        App.ContentDlgOp = null;
                    }
                    else
                    {
                        var btnName       = message.GetValue <string>("ButtonName");
                        _PlaybackCallback = message.Action;
                        //기본 디코더로 설정
                        mediaInformation.RecommendedDecoderType = Settings.Playback.DefaultDecoderType;
                        //선택된 정보 저장
                        mediaInformation.Title  = displayName;
                        CurrentMediaInformation = mediaInformation;

                        StorageItemCodecSource.Clear();
                        foreach (var codecGroup in CurrentMediaInformation.CodecInformationList
                                 .GroupBy(x => x.CodecType).OrderBy(x => x.Key)
                                 .Select(x => new StorageItemCodec((MediaStreamTypes)x.Key)
                        {
                            Items = new ObservableCollection <CodecInformation>(x.ToArray())
                        }))
                        {
                            StorageItemCodecSource.Add(codecGroup);
                        }
                        Views.MainPage page = (Window.Current.Content as Frame).Content as Views.MainPage;
                        var button          = ElementHelper.FindVisualChild <Button>(page, btnName);

                        //정보창 표시
                        button.Flyout.ShowAt(button);
                    }
                });
            });
        }