Skip to content

Commit

Permalink
Added mp4 support and YouTube shorts video support
Browse files Browse the repository at this point in the history
  • Loading branch information
shaked6540 committed Jun 24, 2023
1 parent 3d64433 commit 2a58a85
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 80 deletions.
20 changes: 14 additions & 6 deletions YoutubePlaylistDownloader/DownloadPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class DownloadPage : UserControl, IDisposable, IDownload
private readonly DownloadSettings downloadSettings;
private FullPlaylist Playlist;
private string FileType;
private string VideoFileTypes;
private string VideoSaveFormat;
private readonly string CaptionsLanguage;
private int DownloadedCount;
private readonly int StartIndex;
Expand Down Expand Up @@ -168,7 +168,7 @@ public DownloadPage(FullPlaylist playlist, DownloadSettings settings, string sav
DownloadedVideosProgressBar.Maximum = Maximum;
Playlist = playlist;
FileType = settings.SaveFormat;
VideoFileTypes = settings.VideoSaveFormat;
VideoSaveFormat = settings.VideoSaveFormat;
DownloadedCount = 0;
Quality = settings.Quality;
DownloadCaptions = settings.DownloadCaptions;
Expand Down Expand Up @@ -642,8 +642,8 @@ await Dispatcher.InvokeAsync(() =>

var cleanVideoName = GlobalConsts.CleanFileName(downloadSettings.GetFilenameByPattern(video, i, title, Playlist));
var fileLoc = $"{GlobalConsts.TempFolderPath}{cleanVideoName}";
var outputFileLoc = $"{GlobalConsts.TempFolderPath}{cleanVideoName}.{VideoFileTypes}";
var copyFileLoc = $"{SavePath}\\{cleanVideoName}.{VideoFileTypes}";
var outputFileLoc = $"{GlobalConsts.TempFolderPath}{cleanVideoName}.{VideoSaveFormat}";
var copyFileLoc = $"{SavePath}\\{cleanVideoName}.{VideoSaveFormat}";
var audioLoc = $"{GlobalConsts.TempFolderPath}{cleanVideoName}.{bestAudio.Container.Name}";
var captionsLoc = $"{GlobalConsts.TempFolderPath}{cleanVideoName}.srt";

Expand Down Expand Up @@ -746,7 +746,15 @@ await Dispatcher.InvokeAsync(() =>
var captionsTask = client.Videos.ClosedCaptions.DownloadAsync(captions, captionsLoc, cancellationToken: token);
await ExtensionMethods.WhenAll(videoTask, audioTask, captionsTask);
sw.Stop();
ffmpegArguments = $"-i \"{fileLoc}\" -i \"{audioLoc}\" -i \"{captionsLoc}\" -y -c copy \"{outputFileLoc}\"";
if (VideoSaveFormat != "mkv")
{
ffmpegArguments = $"-i \"{fileLoc}\" -i \"{audioLoc}\" -y -c copy \"{outputFileLoc}\"";
File.Copy(captionsLoc, $"{SavePath}\\{cleanVideoName}.srt");
}
else
{
ffmpegArguments = $"-i \"{fileLoc}\" -i \"{audioLoc}\" -i \"{captionsLoc}\" -y -c copy \"{outputFileLoc}\"";
}
}
else
{
Expand Down Expand Up @@ -990,7 +998,7 @@ protected virtual void Dispose(bool disposing)
disposedValue = true;
Videos = null;
FileType = null;
VideoFileTypes = null;
VideoSaveFormat = null;
Bitrate = null;
NotDownloaded = null;
Videos = null;
Expand Down
6 changes: 4 additions & 2 deletions YoutubePlaylistDownloader/DownloadSettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
</StackPanel>
<Label Content="{DynamicResource Video}" Foreground="{DynamicResource MahApps.Brushes.Accent}" FontSize="26"/>
<WrapPanel Orientation="Vertical" Margin="10,0,0,0">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource SaveVideoFormat}" Margin="5" />
<ComboBox HorizontalContentAlignment="Left" HorizontalAlignment="Center" VerticalContentAlignment="Center" Width="Auto" x:Name="SaveVideosFormatDropDown" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" >
<CheckBox Content="{DynamicResource Prefer}" Margin="7" x:Name="PreferCheckBox" HorizontalAlignment="Center" IsChecked="False" />
<ComboBox HorizontalContentAlignment="Left" HorizontalAlignment="Center" VerticalContentAlignment="Center" Width="Auto" x:Name="ResulotionDropDown" VerticalAlignment="Center"/>
<Label Content="{DynamicResource FormatOf}" />
<ComboBox HorizontalContentAlignment="Left" HorizontalAlignment="Center" VerticalContentAlignment="Center" Width="Auto" x:Name="VideoExtensionsDropDown" VerticalAlignment="Center"/>
</StackPanel>
<CheckBox Margin="7" x:Name="PreferHighestFPSCheckBox" Content="{DynamicResource PreferFPS}" />
<CheckBox x:Name="CaptionsCheckBox" Margin="7" Content="{DynamicResource DownloadCaptions}" />
Expand Down
9 changes: 4 additions & 5 deletions YoutubePlaylistDownloader/DownloadSettingsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public DownloadSettingsControl()
InitializeComponent();

ResulotionDropDown.ItemsSource = Resolutions.Keys;
VideoExtensionsDropDown.ItemsSource = VideoFileTypes;
SaveVideosFormatDropDown.ItemsSource = VideoFileTypes;
ExtensionsDropDown.ItemsSource = FileTypes;
CaptionsLanguagesComboBox.ItemsSource = Languages.Values;

var settings = GlobalConsts.DownloadSettings;
SaveDirectoryTextBox.Text = GlobalConsts.settings.SaveDirectory;
ExtensionsDropDown.SelectedItem = settings.SaveFormat;
VideoExtensionsDropDown.SelectedItem = settings.VideoSaveFormat;
SaveVideosFormatDropDown.SelectedItem = settings.VideoSaveFormat;
ResulotionDropDown.SelectedItem = Resolutions.FirstOrDefault(x => x.Value == settings.Quality).Key;
PreferCheckBox.IsChecked = settings.PreferQuality;
PreferHighestFPSCheckBox.IsChecked = settings.PreferHighestFPS;
Expand Down Expand Up @@ -88,7 +88,7 @@ private void SubscribeToEvents()
ConvertCheckBox.Checked += ConvertCheckBox_Checked;
ConvertCheckBox.Unchecked += ConvertCheckBox_Unchecked;
ExtensionsDropDown.SelectionChanged += ExtensionsDropDown_SelectionChanged;
VideoExtensionsDropDown.SelectionChanged += VideoExtensionsDropDown_SelectionChanged;
SaveVideosFormatDropDown.SelectionChanged += VideoExtensionsDropDown_SelectionChanged;
BitrateCheckBox.Checked += BitrateCheckBox_Checked;
BitrateCheckBox.Unchecked += BitrateCheckBox_Unchecked;
BitRateTextBox.TextChanged += BitRateTextBox_TextChanged;
Expand Down Expand Up @@ -338,7 +338,6 @@ private void ConvertCheckBox_Checked(object sender, RoutedEventArgs e)
{
GlobalConsts.DownloadSettings.Convert = ConvertCheckBox.IsChecked.Value;
GlobalConsts.DownloadSettings.SaveFormat = (string)ExtensionsDropDown.SelectedItem;
GlobalConsts.DownloadSettings.VideoSaveFormat = (string)VideoExtensionsDropDown.SelectedItem;
GlobalConsts.SaveDownloadSettings();
}
}
Expand All @@ -365,7 +364,7 @@ private void VideoExtensionsDropDown_SelectionChanged(object sender, SelectionCh
{
if (GlobalConsts.settings.SaveDownloadOptions)
{
GlobalConsts.DownloadSettings.VideoSaveFormat = (string)VideoExtensionsDropDown.SelectedItem;
GlobalConsts.DownloadSettings.VideoSaveFormat = (string)SaveVideosFormatDropDown.SelectedItem;
GlobalConsts.SaveDownloadSettings();
}
}
Expand Down
17 changes: 8 additions & 9 deletions YoutubePlaylistDownloader/GlobalConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public static DownloadSettings DownloadSettings
{
get
{
downloadSettings ??= new DownloadSettings("mp4", "mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false);

downloadSettings ??= new DownloadSettings("mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false, "mkv");
return downloadSettings;
}
set
Expand Down Expand Up @@ -181,7 +180,7 @@ public static void RestoreDefualts()
{
Log("Restoring defaults", "RestoreDefaults at GlobalConsts").Wait();
settings = new Objects.Settings("Dark", "Red", "English", Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), false, false, true, TimeSpan.FromMinutes(1), true, 20, 2, true, true);
DownloadSettings = new DownloadSettings("mp4", "mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false);
DownloadSettings = new DownloadSettings("mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false, "mkv");
SaveConsts();
}
public static void LoadConsts()
Expand Down Expand Up @@ -313,7 +312,7 @@ static void CropAndSaveImage(byte[] imageBytes, string picLoc)
static readonly string[] ignoredComments = new string[] { "Auto-generated by YouTube.", "Provided to YouTube by" };
static async Task<string> TagMusicFile(Video fullVideo, string file, int vIndex)
{

// Index YouTube Auto Generated Description
string[] description = fullVideo.Description.Split("\n");
string title = "";
Expand All @@ -333,7 +332,7 @@ static async Task<string> TagMusicFile(Video fullVideo, string file, int vIndex)

if (line.Contains('·'))
{
var titleAndArtists = line.Split('·').Select(x=> x.Trim());
var titleAndArtists = line.Split('·').Select(x => x.Trim());
title = titleAndArtists.FirstOrDefault();
artists.AddRange(titleAndArtists.Skip(1));
album = description.ElementAtOrDefault(commentIndex + 2);
Expand All @@ -358,11 +357,11 @@ static async Task<string> TagMusicFile(Video fullVideo, string file, int vIndex)
goto loopEnd;
}

if (ignoredComments.Any(x=> line.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
if (ignoredComments.Any(x => line.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
{
goto loopEnd;
}


comment.AppendLine(line);

Expand Down Expand Up @@ -530,12 +529,12 @@ private static void LoadDownloadSettings()
{
Log(ex2.ToString(), "Delete download settings file path").Wait();
}
downloadSettings = new DownloadSettings("mp4" ,"mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false);
downloadSettings = new DownloadSettings("mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false, "mkv");
}
}
else
{
downloadSettings = new DownloadSettings("mp4", "mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false);
downloadSettings = new DownloadSettings("mp3", false, YoutubeHelpers.High720, false, false, false, false, "192", false, "en", false, false, 0, 0, false, true, false, true, 4, "$title", false, "mkv");
}
}
public static void SaveDownloadSettings()
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Deutsch.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Videos</s:String>
<s:String x:Key="Download">Download</s:String>
<s:String x:Key="ConvertToMp3">Konvertieren von Videos zu </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Wird konvertiert</s:String>
<s:String x:Key="files">Dateien</s:String>
<s:String x:Key="Author">Autor: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Videos</s:String>
<s:String x:Key="Download">Download</s:String>
<s:String x:Key="ConvertToMp3">Convert videos to</s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Still converting</s:String>
<s:String x:Key="files">files</s:String>
<s:String x:Key="Author">Author: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Español.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Videos</s:String>
<s:String x:Key="Download">Descargar</s:String>
<s:String x:Key="ConvertToMp3">Convertir videos a </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Todavía se estan convirtiendo</s:String>
<s:String x:Key="files">videos</s:String>
<s:String x:Key="Author">Autor: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Français.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Vidéos</s:String>
<s:String x:Key="Download">Téléchargement</s:String>
<s:String x:Key="ConvertToMp3">Convertir des vidéos en </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Conversion en cours</s:String>
<s:String x:Key="files">fichier</s:String>
<s:String x:Key="Author">Auteur: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Italiano.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Video</s:String>
<s:String x:Key="Download">Download</s:String>
<s:String x:Key="ConvertToMp3">Converti i video in </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Sto ancora convertendo</s:String>
<s:String x:Key="files">File</s:String>
<s:String x:Key="Author">Autore: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Polski.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Filmy</s:String>
<s:String x:Key="Download">Pobierz</s:String>
<s:String x:Key="ConvertToMp3">Konwertuj pliki do</s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Wciąż konvertuję</s:String>
<s:String x:Key="files">pliki</s:String>
<s:String x:Key="Author">Autor: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Português (BR).xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Vídeos</s:String>
<s:String x:Key="Download">Download</s:String>
<s:String x:Key="ConvertToMp3">Converter vídeos para </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Ainda convertendo</s:String>
<s:String x:Key="files">Arquivos</s:String>
<s:String x:Key="Author">Autor: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/Türkçe.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">Videolar</s:String>
<s:String x:Key="Download">İndir</s:String>
<s:String x:Key="ConvertToMp3">Videoyu Dönüştür </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">Dönüştürülüyor</s:String>
<s:String x:Key="files">dosyalar</s:String>
<s:String x:Key="Author">Yazar: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/עברית.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<s:String x:Key="Videos">סרטונים</s:String>
<s:String x:Key="Download">הורד</s:String>
<s:String x:Key="ConvertToMp3">המר את הסרטונים ל </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">שמור סרטונים בפורמט </s:String>
<s:String x:Key="StillConverting">עדיין ממיר</s:String>
<s:String x:Key="files">קבצים</s:String>
<s:String x:Key="Author">בעלים: </s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/العربية.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">مقاطع الفيديو </s:String>
<s:String x:Key="Download">تحميل </s:String>
<s:String x:Key="ConvertToMp3"> تحويل الفيديو الى </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">لا يزال قيد التحويل </s:String>
<s:String x:Key="files">الملفات</s:String>
<s:String x:Key="Author">:المؤلف</s:String>
Expand Down
2 changes: 1 addition & 1 deletion YoutubePlaylistDownloader/Languages/中文.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<s:String x:Key="Videos">视频</s:String>
<s:String x:Key="Download">下载</s:String>
<s:String x:Key="ConvertToMp3">转换视频成 </s:String>
<s:String x:Key="FormatOf">and format of</s:String>
<s:String x:Key="SaveVideoFormat">Save videos as </s:String>
<s:String x:Key="StillConverting">还转变</s:String>
<s:String x:Key="files">文件</s:String>
<s:String x:Key="Author">作者: </s:String>
Expand Down
12 changes: 7 additions & 5 deletions YoutubePlaylistDownloader/Objects/DownloadSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class DownloadSettings
[JsonProperty]
public string SavePath { get; set; }

[JsonProperty]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
[DefaultValue("mkv")]
public string VideoSaveFormat { get; set; }

[JsonProperty]
Expand Down Expand Up @@ -88,12 +89,12 @@ public class DownloadSettings


[JsonConstructor]
public DownloadSettings(string videoSaveFormat, string saveFormat, bool audioOnly, VideoQuality quality, bool preferHighestFPS,
public DownloadSettings(string saveFormat, bool audioOnly, VideoQuality quality, bool preferHighestFPS,
bool preferQuality, bool convert, bool setBitrate, string bitrate, bool downloadCaptions, string captionsLanguage,
bool savePlaylistsInDifferentDirectories, bool subset, int subsetStartIndex, int subsetEndIndex, bool openDestinationFolderWhenDone,
bool tagAudioFile, bool filterVideosByLength, bool filterMode, double filterByLengthValue, string filenamePattern, bool skipExisting)
bool tagAudioFile, bool filterVideosByLength, bool filterMode, double filterByLengthValue, string filenamePattern, bool skipExisting,
string videoSaveFormat)
{
VideoSaveFormat = videoSaveFormat;
SaveFormat = saveFormat;
AudioOnly = audioOnly;
Quality = quality;
Expand All @@ -115,11 +116,11 @@ public DownloadSettings(string videoSaveFormat, string saveFormat, bool audioOnl
FilterByLengthValue = filterByLengthValue;
FilenamePattern = filenamePattern;
SkipExisting = skipExisting;
VideoSaveFormat = videoSaveFormat;
}

public DownloadSettings(DownloadSettings settings)
{
VideoSaveFormat = settings.VideoSaveFormat;
SaveFormat = settings.SaveFormat;
AudioOnly = settings.AudioOnly;
Quality = settings.Quality;
Expand All @@ -141,6 +142,7 @@ public DownloadSettings(DownloadSettings settings)
FilterByLengthValue = settings.FilterByLengthValue;
FilenamePattern = settings.FilenamePattern;
SkipExisting = settings.SkipExisting;
VideoSaveFormat = settings.VideoSaveFormat;
}

public string GetFilenameByPattern(PlaylistVideo video, int vIndex, string file, FullPlaylist playlist = null)
Expand Down
Loading

0 comments on commit 2a58a85

Please sign in to comment.