public void IsDownloadingBasicTest()
        {
            MediaDownloadConvertManager manager = new MediaDownloadConvertManager();

            for (int i = 0; i < 8; i++)
            {
                VboxFile vboxFile = (VboxFile)MediaFile.CreateNew(VboxDownloadConvertTests.VboxDownloadVideo);
                vboxFile.Metadata.FileName = "file " + i;
                manager.EnqueueDownloadAndConvertRequest(vboxFile,
                                                         Directory.GetCurrentDirectory(),
                                                         new MediaConverterMetadata(Converter.Bitrates.Kbps192, "file " + i, SupportedConversionFormats.Mp3));
            }

            bool done = false;

            int count = 0;

            manager.DownloadConvertResult += delegate { done = ++count == 8; };
            manager.StartDownload();

            while (!done)
            {
                Thread.Sleep(200);
            }

            Assert.IsTrue(done);
        }
Exemplo n.º 2
0
        public void GetsCorrectVideoIdTest()
        {
            VboxFile file = MediaFile.CreateNew(MediaFileTests.VboxTestUrl) as VboxFile;
            string   id   = "a40c203d8b";

            Assert.AreEqual((file.Metadata as VboxFileMetadata).VideoId, id);
        }
Exemplo n.º 3
0
        public void GetsCorrectThumbnailLinkTest()
        {
            MediaFile downloader = MediaFile.CreateNew(MediaFileTests.VboxTestUrl);

            string thumbnailLink = downloader.Metadata.ThumbnailLink;

            Assert.AreEqual("i49.vbox7.com/o/a40/a40c203d8b0.jpg", thumbnailLink);
        }
        public void DownloadFileTest()
        {
            MediaDownloader downloader     = new MediaDownloader();
            MediaFile       file           = MediaFile.CreateNew(VboxDownloadVideo);
            string          downloadedFile = downloader.Download(file, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).DownloadPath;

            Assert.AreEqual(VboxDownloadedVideoPath, downloadedFile);
        }
Exemplo n.º 5
0
        public void GetsCorrectDownloaderTestVbox()
        {
            MediaFile MediaFile = MediaFile.CreateNew(VboxTestUrl);

            bool isVboxDownloader = MediaFile is VboxFile;

            Assert.AreEqual(true, isVboxDownloader);
        }
Exemplo n.º 6
0
        public void GetsCorrectMetadataTest()
        {
            MediaFile         MediaFile = MediaFile.CreateNew(VboxTestUrl);
            MediaFileMetadata metadata  = MediaFile.Metadata;

            bool isVboxMetadata = metadata is VboxFileMetadata;

            Assert.AreEqual(true, isVboxMetadata);
        }
Exemplo n.º 7
0
        public void IsResolvingBasicTest()
        {
            VboxResolver         resolver = new VboxResolver();
            IEnumerable <string> urls     = resolver.ResolveByName("bon jovi its my life HD");

            MediaFile file = MediaFile.CreateNew(urls.First());

            Assert.IsTrue(file.Metadata.FileName.ToLower().Contains("bon jovi"));
        }
Exemplo n.º 8
0
        public void GetsCorrectFileNameTest()
        {
            string fileName = "Как се наказва изневяра .. Смях";

            VboxFile file = MediaFile.CreateNew(MediaFileTests.VboxTestUrl) as VboxFile;

            string actualName = file.Metadata.FileName;

            Assert.AreEqual(fileName, actualName);
        }
Exemplo n.º 9
0
        public void GetsCorrectVideoDownloadLinkTest()
        {
            MediaFile downloader = MediaFile.CreateNew(MediaFileTests.VboxTestUrl);

            string downloadLink = downloader.Metadata.DownloadLink;

            bool isMatch = Regex.IsMatch(downloadLink, "http://media[0-9]{2}.vbox7.com/s/a4/a40c203d8br20619d829.mp4");

            Assert.IsTrue(isMatch);
        }
Exemplo n.º 10
0
        public void IsDownloadingTest()
        {
            MediaFile file = MediaFile.CreateNew(BasicSoundCloudFileTests.SoundCloudLink);

            MediaDownloader downloader = new MediaDownloader();
            var             result     = downloader.Download(file, Directory.GetCurrentDirectory());

            Assert.IsTrue(result.IsDownloaded);
            Assert.IsTrue(File.Exists(result.DownloadPath));
        }
Exemplo n.º 11
0
        public void DownloadFileStartingEventTest()
        {
            MediaDownloader downloader = new MediaDownloader();
            bool            fired      = false;
            MediaFile       file       = MediaFile.CreateNew(VboxDownloadVideo);

            downloader.MediaFileDownloadStarting += (s, e) => fired = true;
            string downloadedFile = downloader.Download(file, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).DownloadPath;

            Assert.AreEqual(fired, true);
        }
Exemplo n.º 12
0
        public void IsConvertingToMp3()
        {
            MediaDownloader downloader   = new MediaDownloader();
            MediaFile       mediaFile    = MediaFile.CreateNew(VboxDownloadConvertTests.VboxDownloadVideo);
            string          existingPath = Path.Combine(Directory.GetCurrentDirectory(), mediaFile.Metadata.FileName + mediaFile.Metadata.FileExtension);

            if (!File.Exists(existingPath))
            {
                downloader.Download(mediaFile, Directory.GetCurrentDirectory());
            }

            MediaConverter converter = new MediaConverter();
            ConvertResult  result    = converter.Convert(mediaFile, existingPath, Directory.GetCurrentDirectory(), new MediaConverterMetadata(Bitrates.Kbps192));

            Assert.IsTrue(result.IsConverted);
            Assert.IsTrue(File.Exists(result.ConvertedPath));
        }
Exemplo n.º 13
0
        public void DownloadFileCompletedEventTest()
        {
            MediaDownloader downloader = new MediaDownloader();

            bool downloaded = false;

            MediaFile file = MediaFile.CreateNew(VboxDownloadVideo);

            downloader.MediaFileDownloadFinished += (s, e) =>
            {
                downloaded = true;
            };

            string downloadedFile = downloader.Download(file, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).DownloadPath;

            Assert.AreEqual(true, downloaded);
        }
Exemplo n.º 14
0
        public void ResumesDownloadProperly()
        {
            MediaDownloader downloader = new MediaDownloader();

            bool canceled   = false;
            bool downloaded = false;

            downloader.MediaFileDownloadProgress += (s, e) =>
            {
                if (((int)e.PercentageComplete >= 25 && (int)e.PercentageComplete <= 30) && !canceled)
                {
                    e.Cancel = canceled = true;
                }

                if (e.PercentageComplete >= 100)
                {
                    downloaded = true;
                }
            };

            MediaFile file = MediaFile.CreateNew(MediaFileTests.VboxTestUrl);
            string    path = Path.Combine(Directory.GetCurrentDirectory(), file.Metadata.FileName + file.Metadata.FileExtension);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var firstResult = downloader.Download(file, Directory.GetCurrentDirectory());

            if (!firstResult.IsDownloaded || firstResult.Exceptions.Any())
            {
                throw new Exception();
            }

            var secondDownload = downloader.Download(file, Directory.GetCurrentDirectory(), true);

            if (!secondDownload.IsDownloaded || secondDownload.Exceptions.Any())
            {
                throw new Exception();
            }

            Assert.IsTrue(downloaded);
        }
Exemplo n.º 15
0
        public void ConversionEndedEventTest()
        {
            MediaDownloader downloader = new MediaDownloader();

            MediaFile file           = MediaFile.CreateNew(VboxDownloadVideo);
            string    downloadedPath = downloader.Download(file, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).DownloadPath;
            bool      converting     = false;

            MediaConverter converter = new MediaConverter();

            converter.MediaFileConvertionCompelete += delegate { converting = true; };
            converter.Convert(file, downloadedPath, Environment.GetFolderPath(Environment.SpecialFolder.Desktop), new MediaConverterMetadata
            {
                AudioBitrate = Bitrates.Kbps192,
                Extension    = SupportedConversionFormats.Mp3,
                FileName     = file.Metadata.FileName
            });

            Assert.AreEqual(true, converting);
        }
Exemplo n.º 16
0
        public void DownloadFileProgressEventTest()
        {
            MediaDownloader downloader = new MediaDownloader();

            bool hasDownloadSize = false;
            bool hasMaxSize      = false;
            bool hasProgress     = false;

            MediaFile file = MediaFile.CreateNew(VboxDownloadVideo);

            downloader.MediaFileDownloadProgress += (s, e) =>
            {
                hasDownloadSize = e.DownloadedSize > 0;
                hasMaxSize      = e.FileSize > 0;
                hasProgress     = e.PercentageComplete > 0;
            };

            string downloadedFile = downloader.Download(file, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).DownloadPath;

            Assert.AreEqual(true, hasDownloadSize && hasMaxSize && hasProgress);
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            List <string> files = new List <string>();

            //string[] dirFiles = Directory.GetFiles(@"E:\New folder");

            //foreach (var file in dirFiles)
            //{
            //    files.Add(Path.GetFileNameWithoutExtension(file).Replace(".mp3", ""));
            //}

            string line = null;

            while ((line = Console.ReadLine()) != "")
            {
                files.Add(line);
            }

            VboxResolver resolver = new VboxResolver();

            MediaFile[] vboxFiles = files.Select(x =>
            {
                Uri uri;
                if (!Uri.TryCreate(x, UriKind.Absolute, out uri))
                {
                    string preceedingNumberExpression = "[0-9]{3}.";
                    //string fullNameExpression = string.Format("{0}[a-z0-9].mp3", preceedingNumberExpression);

                    x        = Regex.Replace(x, preceedingNumberExpression, "").Trim();
                    var urls = resolver.ResolveByName(x);
                    if (urls.Any())
                    {
                        x = urls.First();
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(MediaFile.CreateNew(x));
            }).Where(x => x != null).ToArray();

            MediaDownloadConvertManager manager = new MediaDownloadConvertManager();

            manager.MaxParallelRequests = 10;

            manager.Downloader.MediaFileDownloadStarting += downloader_MediaFileDownloadStarting;
            manager.Downloader.MediaFileDownloadProgress += downloader_MediaFileDownloadProgress;
            manager.Downloader.MediaFileDownloadFinished += downloader_MediaFileDownloadFinished;

            manager.Converter.MediaFileConversionStarting  += downloader_MediaFileConversionStarting;
            manager.Converter.MediaFileConvertionCompelete += downloader_MediaFileConvertionCompelete;

            string desktop = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "DownloadedFiles");

            Directory.CreateDirectory(desktop);
            for (int i = 0; i < vboxFiles.Length; i++)
            {
                MediaConverterMetadata metadata = null;
                if (vboxFiles[i].FileOrigin == FileOrigin.SoundCloud)
                {
                    metadata = MediaConverterMetadata.Default;
                }
                else
                {
                    metadata = new MediaConverterMetadata(Converter.Bitrates.Kbps192, vboxFiles[i].Metadata.FileName, SupportedConversionFormats.Mp3);
                }

                manager.EnqueueDownloadAndConvertRequest(vboxFiles[i], desktop, metadata);
            }

            manager.StartDownload();

            Console.ReadLine();
            Console.ReadLine();
        }
Exemplo n.º 18
0
        public void IsFileCretedCorrectTest()
        {
            MediaFile file = MediaFile.CreateNew(SoundCloudLink);

            Assert.IsTrue(file is SoundCloudFile);
        }
Exemplo n.º 19
0
        public void IsOriginSoundCloud()
        {
            MediaFile file = MediaFile.CreateNew(SoundCloudLink);

            Assert.IsTrue(file.FileOrigin == FileOrigin.SoundCloud);
        }
Exemplo n.º 20
0
        public void IsInitializingMetadataCorrectly()
        {
            MediaFile file = MediaFile.CreateNew(SoundCloudLink);

            file.InitializeMetadata();
        }