Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
Update packages
Browse files Browse the repository at this point in the history
Update DownloadController.cs
Fix error "Video is removed or has an age restriction"
Change package YoutubeExtractor (Original) -> YoutubeExtractor (LinPolly Fork)
  • Loading branch information
ChrisF23 committed Jan 27, 2020
1 parent 93ab658 commit b5151ea
Show file tree
Hide file tree
Showing 53 changed files with 96,246 additions and 17 deletions.
37 changes: 26 additions & 11 deletions RedMint_UI/DownloadController.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YoutubeExtractor;

namespace RedMint_UI
{
public enum DownloadQuality
{
High,
Medium,
Low
}
// private enum DownloadOutputFormat { };


interface IDownloadController
{
void DownloadVideo(string url, DownloadQuality quality);
void DownloadAudio(string url, DownloadQuality quality);
VideoDownloader ObtenerVideoDownloader(string url, string directorioSalida);
AudioDownloader ObtenerAudioDownloader(string url, string directorioSalida);
}

public class DownloadController : IDownloadController
Expand All @@ -25,14 +24,30 @@ private string ParseUrl(string url)
throw new NotImplementedException();
}

public void DownloadVideo(string url, DownloadQuality quality)
public VideoDownloader ObtenerVideoDownloader(string url, string directorioSalida)
{
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url);
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url, false);

// Obtener el video con la mejor calidad.
VideoInfo video = videoInfos
.Where( info => info.VideoType == VideoType.Mp4)
.OrderByDescending( info => info.Resolution)
.First();

// Desencriptar de ser necesario.
if (video.RequiresDecryption)
{
DownloadUrlResolver.DecryptDownloadUrl(video);
}

// Crear el descargador.
var directorioFinal = Path.Combine(directorioSalida, video.Title + video.VideoExtension);
var videoDownloader = new VideoDownloader(video, directorioFinal);

return videoDownloader;
}

public void DownloadAudio(string url, DownloadQuality quality)
public AudioDownloader ObtenerAudioDownloader(string url, string directorioSalida)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion RedMint_UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Label x:Name="lbl_formato" Content="Formato:" Margin="20,146,384,0" VerticalAlignment="Top" Foreground="#FFF1F1F1" FontStretch="Normal" FontWeight="Thin" FontStyle="Normal" FontFamily="Lato" FontSize="16" Height="30"/>
<ComboBox x:Name="cbb_calidad" HorizontalAlignment="Left" Margin="20,244,0,0" VerticalAlignment="Top" Width="120" FontSize="16" Height="28"/>

<Button x:Name="btn_descargar" Content="Descargar" Margin="110,297,110,0" Background="Red" BorderBrush="#FFBB0000" Foreground="White" FontWeight="DemiBold" FontStretch="Expanded" FontSize="14" FontFamily="Lato" ClickMode="Press" RenderTransformOrigin="0.5,0.001" Height="30" VerticalAlignment="Top"/>
<Button x:Name="btn_descargar" Content="Descargar" Margin="110,297,110,0" Background="Red" BorderBrush="#FFBB0000" Foreground="White" FontWeight="DemiBold" FontStretch="Expanded" FontSize="14" FontFamily="Lato" ClickMode="Press" RenderTransformOrigin="0.5,0.001" Height="30" VerticalAlignment="Top" Click="btn_descargar_Click"/>
<ProgressBar x:Name="pgb_progress" Margin="0,2,0,0" Height="10" VerticalAlignment="Bottom" Value="50">
<ProgressBar.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
Expand Down
43 changes: 40 additions & 3 deletions RedMint_UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,41 @@
namespace RedMint_UI
{
/// <summary>
public enum Calidad { Alta, Media, Baja }
public enum Formato { Audio, Video }

/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

private IDownloadController downloadController;

public MainWindow()
{
InitializeComponent();
InitializeControls();
downloadController = new DownloadController();
}

private void InitializeControls()
{
// inputs:
// Inputs:
input_direccion.Text = string.Empty;
input_directorio_salida.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

cbb_calidad.ItemsSource = Enum.GetValues(typeof(DownloadQuality));
// Comboboxes:
// cbb_calidad.ItemsSource = Enum.GetValues(typeof(Calidad));
cbb_formato.ItemsSource = Enum.GetValues(typeof(Formato));
cbb_formato.SelectedIndex = 0;

// Progressbar:
pgb_progress.Value = 0;

// Controlador de Descargas:
if (downloadController == null)
{
downloadController = new DownloadController();
}
}

private void btn_directorio_salida_Click(object sender, RoutedEventArgs e)
Expand All @@ -56,7 +71,29 @@ private void btn_directorio_salida_Click(object sender, RoutedEventArgs e)

private void btn_descargar_Click(object sender, RoutedEventArgs e)
{
switch ((Formato) cbb_formato.SelectedValue)
{
case Formato.Audio:
var audioDownloader = downloadController.ObtenerAudioDownloader(input_direccion.Text, input_directorio_salida.Text);
audioDownloader.Execute();

break;
case Formato.Video:
var videoDownloader = downloadController.ObtenerVideoDownloader(input_direccion.Text, input_directorio_salida.Text);

videoDownloader.DownloadProgressChanged += (sender, args) => UpdateProgressBar(args.ProgressPercentage);
videoDownloader.Execute();

break;
default:
input_direccion.Text = "Error, formato no seleccionado";
break;
}
}

private void UpdateProgressBar(double pogressPercentage)
{
pgb_progress.Value = pogressPercentage;
}
}
}
5 changes: 4 additions & 1 deletion RedMint_UI/RedMint_UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

<ItemGroup>
<PackageReference Include="WPFFolderBrowser" Version="1.0.2" />
<PackageReference Include="YoutubeExtractor" Version="0.10.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\YoutubeExtractor\YoutubeExtractor.csproj" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion RedMint_UI/RedMint_UI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedMint_UI", "RedMint_UI.csproj", "{477617E1-7C54-49E9-B0F3-8FAE8A7D7805}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedMint_UI", "RedMint_UI.csproj", "{477617E1-7C54-49E9-B0F3-8FAE8A7D7805}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeExtractor", "..\YoutubeExtractor\YoutubeExtractor.csproj", "{ECDC127F-8DEF-4F99-8300-72C13597339D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{477617E1-7C54-49E9-B0F3-8FAE8A7D7805}.Debug|Any CPU.Build.0 = Debug|Any CPU
{477617E1-7C54-49E9-B0F3-8FAE8A7D7805}.Release|Any CPU.ActiveCfg = Release|Any CPU
{477617E1-7C54-49E9-B0F3-8FAE8A7D7805}.Release|Any CPU.Build.0 = Release|Any CPU
{ECDC127F-8DEF-4F99-8300-72C13597339D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECDC127F-8DEF-4F99-8300-72C13597339D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECDC127F-8DEF-4F99-8300-72C13597339D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECDC127F-8DEF-4F99-8300-72C13597339D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file not shown.
20 changes: 20 additions & 0 deletions RedMint_UI/packages/Newtonsoft.Json.12.0.3/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2007 James Newton-King

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit b5151ea

Please sign in to comment.