Example #1
0
        private async void HandleDataObject(IDataObject data)
        {
            if (string.IsNullOrEmpty(Settings.OutputFolder))
            {
                await Application.Current.Dispatcher.InvokeAsync(() => MessageBox.Show(this, "You need to set an output folder for your converted songs first.", "There was a problem"));
            }
            else if (data.GetDataPresent(DataFormats.UnicodeText))
            {
                HandleYoutubeConversion((string)data.GetData(DataFormats.UnicodeText));
            }
            else if (data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] filepaths = (string[])data.GetData(DataFormats.FileDrop);
                foreach (var filepath in filepaths)
                {
                    string extension = Path.GetExtension(filepath);

                    if (string.IsNullOrWhiteSpace(extension))
                    {
                        await Application.Current.Dispatcher.InvokeAsync(() => MessageBox.Show(this, "Folders aren't supported.  Instead, select all of the files inside the folder you wish to convert.", "There was a problem"));
                    }
                    else if (string.Compare(extension, ".url", true) == 0)
                    {
                        HandleYoutubeConversion(YoutubeHelpers.ExtractURLFromShortcut(filepath));
                    }
                    else
                    {
                        HandleFileConversion(filepath);
                    }
                }
            }
        }
Example #2
0
        public void ShouldReturnURLFromShortcut()
        {
            var testCases = new[]
            {
                new { ExpectedURL = "https://www.youtube.com/watch?v=p6j8fuvQICI", ShortcutFilepath = "TestShortcuts/Link1.url" },
                new { ExpectedURL = "https://www.youtube.com/watch?v=f9qavey27Kc", ShortcutFilepath = "TestShortcuts/Link2.url" },
                new { ExpectedURL = "https://www.youtube.com/watch?v=WpTOzX4xDUw", ShortcutFilepath = "TestShortcuts/Link3.url" },
                new { ExpectedURL = "https://www.youtube.com/watch?v=QGHlVLsbuoc", ShortcutFilepath = "TestShortcuts/Link4.url" },
            };

            foreach (var test in testCases)
            {
                Assert.AreEqual(test.ExpectedURL, YoutubeHelpers.ExtractURLFromShortcut(test.ShortcutFilepath));
            }
        }