Skip to content

Commit

Permalink
Added preview + Fixed DecryptVideo error
Browse files Browse the repository at this point in the history
  • Loading branch information
theasern committed Nov 12, 2018
1 parent 42cd4f3 commit ce59f84
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 55 deletions.
48 changes: 48 additions & 0 deletions YTDownloader/API.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Mono.Web;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace YTDownloader
{
class API
{

public static string GetTitle(string url)
{
var api = $"http://youtube.com/get_video_info?video_id={GetArgs(url, "v", '?')}";
return GetArgs(new WebClient().DownloadString(api), "title", '&');
}

private static string GetArgs(string args, string key, char query)
{
var iqs = args.IndexOf(query);
return iqs == -1
? string.Empty
: HttpUtility.ParseQueryString(iqs < args.Length - 1
? args.Substring(iqs + 1) : string.Empty)[key];
}

public static void LogInfo(string info)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Information(info);
}

public static void LogError(string error)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Error(error);
}


}
}
8 changes: 4 additions & 4 deletions YTDownloader/App.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
39 changes: 32 additions & 7 deletions YTDownloader/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 24 additions & 27 deletions YTDownloader/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.IO;
using System.Windows.Forms;
using VideoLibrary;
using MediaToolkit;
using MediaToolkit.Model;
using System.Diagnostics;
using Serilog;
using VideoLibrary;

namespace YTDownloader
{
Expand Down Expand Up @@ -34,10 +33,7 @@ public void button1_Click(object sender, EventArgs e)
{
if (metrics.Checked)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Error("Path Selection Failed");
API.LogError("Path Selection Failed");
}
MessageBox.Show("Path selection failed!");
}
Expand All @@ -56,16 +52,13 @@ public void button2_Click(object sender, EventArgs e)
{
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
var youTube = YouTube.Default;
var video = youTube.GetVideo(link);
File.WriteAllBytes(path + @"\" + video.FullName, video.GetBytes());
var youtube = YouTube.Default;
var vid = youtube.GetVideo(link);
File.WriteAllBytes(path + vid.FullName, vid.GetBytes());

if (metrics.Checked)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Information("MP4Downl " + link);
API.LogInfo("MP4Downl " + link);
}

if (checkBox1.Checked)
Expand All @@ -88,19 +81,16 @@ private void button3_Click(object sender, EventArgs e)
{
if (metrics.Checked)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Error("Not pasted youtube video URL");
API.LogError("Not pasted youtube video URL");
}
MessageBox.Show("Please input a youtube video URL");
}
else
{
var youtube = YouTube.Default;
var vid = youtube.GetVideo(link);
string mp4filepath = path + @"\" + "Temp.mp4";
File.WriteAllBytes(path + @"\" + "Temp.mp4", vid.GetBytes());
string mp4filepath = path + @"\" + "Temp.mp4";
File.WriteAllBytes(mp4filepath, vid.GetBytes());

var inputFile = new MediaFile { Filename = path + @"\" + "Temp.mp4" };
var outputFile = new MediaFile { Filename = $"{path + @"\" + vid.Title}.mp3" };
Expand All @@ -113,10 +103,7 @@ private void button3_Click(object sender, EventArgs e)

if (metrics.Checked)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Information("MP3Downl " + link);
API.LogInfo("MP3Downl " + link);
}

if (checkBox1.Checked)
Expand All @@ -141,10 +128,20 @@ private void textBox1_Click(object sender, EventArgs e)

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("bf0c27b81711387d611e6d3af6ed2481")
.CreateLogger();
log.Information("Changed folder on download state");
if (metrics.Checked)
{
API.LogInfo("Changed folder on download state");
}

}

private void textBox1_TextChanged(object sender, EventArgs e)
{
var text = textBox1.Text;
string vidname = API.GetTitle(text);
label5.Text = vidname;
}


}
}
23 changes: 14 additions & 9 deletions YTDownloader/YTDownloader.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Costura.Fody.3.1.4\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.3.1.4\build\Costura.Fody.props')" />
<Import Project="..\packages\Costura.Fody.3.1.6\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.3.1.6\build\Costura.Fody.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -53,17 +53,23 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="libvideo, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VideoLibrary.2.0.2\lib\netstandard1.1\libvideo.dll</HintPath>
<Reference Include="libvideo">
<HintPath>..\..\libvideo-master\src\libvideo\bin\Debug\netstandard1.1\libvideo.dll</HintPath>
</Reference>
<Reference Include="MediaToolkit, Version=1.1.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaToolkit.1.1.0.1\lib\net40\MediaToolkit.dll</HintPath>
</Reference>
<Reference Include="Mono.HttpUtility, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.HttpUtility.1.0.0.1\lib\net40\Mono.HttpUtility.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.7.1\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Datadog.Logs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.Datadog.Logs.0.1.3\lib\net451\Serilog.Sinks.Datadog.Logs.dll</HintPath>
<HintPath>..\packages\Serilog.Sinks.Datadog.Logs.0.1.4\lib\net451\Serilog.Sinks.Datadog.Logs.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.PeriodicBatching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.PeriodicBatching.2.1.1\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
Expand All @@ -87,6 +93,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="API.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -137,10 +144,8 @@
<PropertyGroup>
<ErrorText>Este proyecto hace referencia a los paquetes NuGet que faltan en este equipo. Use la restauración de paquetes NuGet para descargarlos. Para obtener más información, consulte http://go.microsoft.com/fwlink/?LinkID=322105. El archivo que falta es {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Costura.Fody.3.1.4\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.1.4\build\Costura.Fody.props'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.3.1.4\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.1.4\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.3.2.9\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.2.9\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.3.2.17\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.2.17\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.3.1.6\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.1.6\build\Costura.Fody.props'))" />
</Target>
<Import Project="..\packages\Costura.Fody.3.1.4\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.3.1.4\build\Costura.Fody.targets')" />
<Import Project="..\packages\Fody.3.2.9\build\Fody.targets" Condition="Exists('..\packages\Fody.3.2.9\build\Fody.targets')" />
<Import Project="..\packages\Fody.3.2.17\build\Fody.targets" Condition="Exists('..\packages\Fody.3.2.17\build\Fody.targets')" />
</Project>
18 changes: 10 additions & 8 deletions YTDownloader/packages.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="3.1.4" targetFramework="net45" />
<package id="Fody" version="3.2.9" targetFramework="net45" developmentDependency="true" />
<package id="Costura.Fody" version="3.1.6" targetFramework="net451" />
<package id="Fody" version="3.2.17" targetFramework="net451" developmentDependency="true" />
<package id="MediaToolkit" version="1.1.0.1" targetFramework="net45" />
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net45" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net45" />
<package id="Microsoft.NETCore.Platforms" version="2.1.1" targetFramework="net451" />
<package id="Mono.HttpUtility" version="1.0.0.1" targetFramework="net451" />
<package id="NETStandard.Library" version="2.0.3" targetFramework="net451" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net451" />
<package id="Serilog" version="2.7.1" targetFramework="net45" />
<package id="Serilog.Sinks.Datadog.Logs" version="0.1.3" targetFramework="net451" />
<package id="Serilog.Sinks.Datadog.Logs" version="0.1.4" targetFramework="net451" />
<package id="Serilog.Sinks.PeriodicBatching" version="2.1.1" targetFramework="net45" />
<package id="System.Collections" version="4.3.0" targetFramework="net45" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net45" />
Expand All @@ -18,7 +20,7 @@
<package id="System.IO.Compression" version="4.3.0" targetFramework="net45" />
<package id="System.Linq" version="4.3.0" targetFramework="net45" />
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net45" />
<package id="System.Net.Http" version="4.3.0" targetFramework="net45" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net451" />
<package id="System.Net.Primitives" version="4.3.0" targetFramework="net45" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net45" />
<package id="System.Reflection" version="4.3.0" targetFramework="net45" />
Expand All @@ -35,7 +37,7 @@
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net45" />
<package id="System.Threading" version="4.3.0" targetFramework="net45" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net45" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net45" />
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net451" />
<package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net451" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net45" />
<package id="VideoLibrary" version="2.0.2" targetFramework="net45" />
</packages>

0 comments on commit ce59f84

Please sign in to comment.