diff --git a/PlaylistDownloader/PlaylistDownloader/App.config b/PlaylistDownloader/PlaylistDownloader/App.config
index edd8aa7..1d15fe9 100644
--- a/PlaylistDownloader/PlaylistDownloader/App.config
+++ b/PlaylistDownloader/PlaylistDownloader/App.config
@@ -11,4 +11,7 @@
+
+
+
diff --git a/PlaylistDownloader/PlaylistDownloader/Downloader.cs b/PlaylistDownloader/PlaylistDownloader/Downloader.cs
index 5c4876a..2890e45 100644
--- a/PlaylistDownloader/PlaylistDownloader/Downloader.cs
+++ b/PlaylistDownloader/PlaylistDownloader/Downloader.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -14,13 +15,15 @@ public class Downloader : BackgroundWorker
{
private readonly ICollection _playlist;
+ private readonly bool _isDebugMode = bool.Parse(ConfigurationManager.AppSettings.Get("debug"));
- //[download] 0.9% of 3.45MiB at 553.57KiB/s ETA 00:06
- private readonly Regex _extractDownloadProgress = new Regex(@"\[download\][\s]*([0-9\.]+)%");
+ //[download] 0.9% of 3.45MiB at 553.57KiB/s ETA 00:06
+ private readonly Regex _extractDownloadProgress = new Regex(@"\[download\][\s]*([0-9\.]+)%");
private int _progress;
private readonly int _totalSongs;
private readonly CancellationTokenSource _cts;
+
public Downloader(ICollection playlist)
{
_playlist = playlist;
@@ -91,12 +94,9 @@ private void DownloadPlaylistItem(PlaylistItem item, ParallelOptions po)
StartInfo =
{
FileName = "youtube-dl.exe",
- Arguments =
- string.Format(
- " --ffmpeg-location ./ffmpeg --extract-audio --audio-format mp3 -o \"{2}/{0}.%(ext)s\" {1}",
- item.FileName, youtubeLink.Url, SettingsWindow.SONGS_FOLDER),
- CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Hidden,
+ Arguments = string.Format(" --ffmpeg-location ./ffmpeg --extract-audio --audio-format mp3 -o \"{2}\\{0}.%(ext)s\" {1}", item.FileName, youtubeLink.Url, SettingsWindow.SONGS_FOLDER),
+ CreateNoWindow = !_isDebugMode,
+ WindowStyle = _isDebugMode ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
UseShellExecute = false
}
@@ -142,10 +142,11 @@ private void DownloadPlaylistItem(PlaylistItem item, ParallelOptions po)
private static string MakeValidFileName(string name)
{
- string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
- string invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars);
-
- return Regex.Replace(name, invalidRegStr, "_");
- }
+ return Regex.Replace(
+ name,
+ "[\\W-]+", /*Matches any nonword character. Equivalent to '[^A-Za-z0-9_]'*/
+ "-",
+ RegexOptions.IgnoreCase);
+ }
}
}
diff --git a/PlaylistDownloader/PlaylistDownloader/PlaylistDownloader.csproj b/PlaylistDownloader/PlaylistDownloader/PlaylistDownloader.csproj
index 771ff5a..90f6f96 100644
--- a/PlaylistDownloader/PlaylistDownloader/PlaylistDownloader.csproj
+++ b/PlaylistDownloader/PlaylistDownloader/PlaylistDownloader.csproj
@@ -69,6 +69,7 @@
True
+
diff --git a/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs b/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs
index 569b021..5c1ecf8 100644
--- a/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs
+++ b/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs
@@ -7,6 +7,7 @@
using System.Windows.Input;
using PlaylistDownloader.Annotations;
using System;
+using System.Configuration;
namespace PlaylistDownloader
{
@@ -33,6 +34,7 @@ public partial class SettingsWindow : INotifyPropertyChanged
private bool _isQueryValid;
private const string INSTRUCTIONS = "Enter songs (one per line)";
public static readonly string SONGS_FOLDER = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "PlaylistDownloader");
+ private readonly bool _isDebugMode = bool.Parse(ConfigurationManager.AppSettings.Get("debug"));
public SettingsWindow()
{
@@ -53,7 +55,7 @@ public SettingsWindow()
FileName = "youtube-dl.exe",
Arguments = " -U",
CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Hidden,
+ WindowStyle = _isDebugMode ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
UseShellExecute = false
}
diff --git a/PlaylistDownloader/PlaylistDownloader/YoutubeSearcher.cs b/PlaylistDownloader/PlaylistDownloader/YoutubeSearcher.cs
index 6de42a8..7ac5b07 100644
--- a/PlaylistDownloader/PlaylistDownloader/YoutubeSearcher.cs
+++ b/PlaylistDownloader/PlaylistDownloader/YoutubeSearcher.cs
@@ -11,13 +11,13 @@ namespace PlaylistDownloader
{
public static class YoutubeSearcher
{
- const string URL = "http://www.youtube.com/results?search_query={0}&page={1}";
+ private const string URL = "http://www.youtube.com/results?search_query={0}&page={1}";
public static IEnumerable GetYoutubeLinks(string query, int numberOfResults = 1)
{
List links = new List();
int page = 1;
- while (page < 20 && links.Count() < numberOfResults)
+ while (page < 20 && links.Count < numberOfResults)
{
string requestUrl = string.Format(URL, HttpUtility.UrlEncode(query)?.Replace("%20", "+"), page);
HtmlDocument doc = new HtmlDocument();
@@ -28,7 +28,7 @@ public static IEnumerable GetYoutubeLinks(string query, int numberO
page++;
}
return links;
- //TODO 040 make sure program correctly stops if page is not existent => message to user
+ // TODO 040 make sure program correctly stops if page is not existent => message to user
}
private static string GetWebPageCode(string url)
diff --git a/PlaylistDownloaderDist-v1.5.zip b/PlaylistDownloaderDist-v1.6.zip
similarity index 68%
rename from PlaylistDownloaderDist-v1.5.zip
rename to PlaylistDownloaderDist-v1.6.zip
index 17d8096..e62ce59 100644
Binary files a/PlaylistDownloaderDist-v1.5.zip and b/PlaylistDownloaderDist-v1.6.zip differ
diff --git a/PlaylistDownloaderSetup-v1.5.exe b/PlaylistDownloaderSetup-v1.6.exe
similarity index 64%
rename from PlaylistDownloaderSetup-v1.5.exe
rename to PlaylistDownloaderSetup-v1.6.exe
index 64662a4..a09a952 100644
Binary files a/PlaylistDownloaderSetup-v1.5.exe and b/PlaylistDownloaderSetup-v1.6.exe differ