Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
76 changes: 76 additions & 0 deletions YoutubeExtractor/ExampleApplication.Portable/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.

<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

</application>
</compatibility>

<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->

</assembly>
14 changes: 11 additions & 3 deletions YoutubeExtractor/ExampleApplication/ExampleApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\YouTubeDownloader\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,7 +32,7 @@
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\YouTubeDownloader\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand All @@ -46,8 +46,16 @@
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Final Output|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\..\..\FinalOP\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
Expand Down
204 changes: 167 additions & 37 deletions YoutubeExtractor/ExampleApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using YoutubeExtractor;

namespace ExampleApplication
{
internal class Program
{
private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos)
/*ARGUMENTS RELATED ERRORS 1-5*/
const uint LESSARGS_ERR = 1;
const uint YLINK_ERR = 2;
const uint DWNPATH_ERR = 3;
const uint AVURL_ERR = 4;

/*FILE RELATED ERRORS 5-10*/
const uint FEXP_ERR = 5;
const uint FPATH_ERR = 6;

/*YOUTUBE LINK RELATED ERRORS 10-15*/
const uint YLINKFORMAT_ERR = 10;
const uint NETCON_ERR = 11;

/*OTHER ERRORS*/
const uint OTHER_ERR = 99;

private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos, string dwnpath)
{
/*
* We want the first extractable video with the highest audio quality.
Expand All @@ -19,28 +35,20 @@ private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos)
.OrderByDescending(info => info.AudioBitrate)
.First();

/*
* If the video has a decrypted signature, decipher it
*/
if (video.RequiresDecryption)
{
DownloadUrlResolver.DecryptDownloadUrl(video);
}

/*
* Create the audio downloader.
* The first argument is the video where the audio should be extracted from.
* The second argument is the path to save the audio file.
*/

var audioDownloader = new AudioDownloader(video,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
RemoveIllegalPathCharacters(video.Title) + video.AudioExtension));
Path.Combine(dwnpath, Clean_Title(video.Title) + video.AudioExtension));

// Register the progress events. We treat the download progress as 85% of the progress
// and the extraction progress only as 15% of the progress, because the download will
// take much longer than the audio extraction.
audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);

audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

/*
Expand All @@ -50,30 +58,22 @@ private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos)
audioDownloader.Execute();
}

private static void DownloadVideo(IEnumerable<VideoInfo> videoInfos)
private static void DownloadVideo(IEnumerable<VideoInfo> videoInfos, string dwnpath)
{
/*
* Select the first .mp4 video with 360p resolution
*/
VideoInfo video = videoInfos
.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);

/*
* If the video has a decrypted signature, decipher it
*/
if (video.RequiresDecryption)
{
DownloadUrlResolver.DecryptDownloadUrl(video);
}

/*
* Create the video downloader.
* The first argument is the video to download.
* The second argument is the path to save the video file.
*/

var videoDownloader = new VideoDownloader(video,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
RemoveIllegalPathCharacters(video.Title) + video.VideoExtension));
Path.Combine(dwnpath, Clean_Title(video.Title) + video.VideoExtension));

// Register the ProgressChanged event and print the current progress
videoDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage);
Expand All @@ -85,26 +85,156 @@ private static void DownloadVideo(IEnumerable<VideoInfo> videoInfos)
videoDownloader.Execute();
}

private static void Main()
/// <summary>
/// Used to maintain the log of the Current service.
/// Inputs: strmessage as a string.
/// Outputs: A log file containing the status of the Service.
/// Notes:
/// </summary>
public static void WriteLog(string strMessage)
{
// Our test youtube link
const string link = "https://www.youtube.com/watch?v=YQHsXMglC9A";
string Dt4 = DateTime.Now.AddDays(-2).ToString("dd/MM/yyyy").Substring(0, 2);
string Dt5 = DateTime.Now.AddDays(-2).ToString("dd/MM/yyyy").Substring(3, 2);
string Dt6 = DateTime.Now.AddDays(-2).ToString("dd/MM/yyyy").Substring(6, 4);

/*
* Get the available video formats.
* We'll work with them in the video and audio download examples.
*/
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link, false);
string yestPath = AppDomain.CurrentDomain.BaseDirectory + "\\YouTubeDownloader" + Dt4 + Dt5 + Dt6 + ".log";

if (File.Exists(yestPath))
{
File.Delete(yestPath);
}

string strPath = null;
System.IO.StreamWriter file = null;
string Dt1 = DateTime.Now.Date.ToString("dd/MM/yyyy").Substring(0, 2);
string Dt2 = DateTime.Now.Date.ToString("dd/MM/yyyy").Substring(3, 2);
string Dt3 = DateTime.Now.Date.ToString("dd/MM/yyyy").Substring(6, 4);

strPath = AppDomain.CurrentDomain.BaseDirectory + "\\YouTubeDownloader" + Dt1 + Dt2 + Dt3 + ".log";

// 06/05/2014 Changes Anil Nair
try
{
file = new System.IO.StreamWriter(strPath, true);
file.WriteLine(strMessage);
file.Close();
}
catch (IOException)
{
file.Flush();
}
}

//DownloadAudio(videoInfos);
DownloadVideo(videoInfos);
private static string Clean_Title(string video_title)
{
return Path.GetInvalidFileNameChars().Aggregate(video_title, (current, c) => current.Replace(c.ToString(), string.Empty));
}

private static int Main(string[] args)
{
IEnumerable<VideoInfo> videoInfos;
string link = String.Empty;
string[] normlink;
bool exists;
string path = String.Empty;

if (args.Length < 3)
{
WriteLog("Please Specify 3 arguments");
Console.WriteLine("Please Specify 3 arguments");
return (int)LESSARGS_ERR;
}

if (args[0].Length == 0)
{
WriteLog("Please Specify the Youtube Link");
Console.WriteLine("Please Specify the Youtube Link");
return (int)YLINK_ERR;
}

if (args[2].Length == 0)
{
WriteLog("Please Specify the Download Path");
Console.WriteLine("Please Specify the Download Path");
return (int)DWNPATH_ERR;
}


else
{
try
{
path = System.IO.Path.GetFullPath(args[2].ToString());
DirectoryInfo info = new DirectoryInfo(path);
exists = info.Exists;
}

catch (Exception ex)
{
WriteLog(ex.Message);
return (int)FEXP_ERR;
}
}

if (!exists)
{
WriteLog("Please check the path");
Console.WriteLine("Please check the path");
return (int)FPATH_ERR;
}

try
{
if ((args[0].ToString().ToLower().Contains("http://www.youtube.com/watch?v=")) || (args[0].ToString().ToLower().Contains("https://www.youtube.com/watch?v=")))
{

normlink = args[0].ToString().Split('&');
link = normlink[0].ToString();

videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

if (args[1].ToString().ToUpper() == "VIDEO")
{
Console.WriteLine(path);
DownloadVideo(videoInfos, path);
Console.WriteLine(args[2].ToString());
return 0;
}

if (args[1].ToString().ToUpper() == "AUDIO")
{
DownloadAudio(videoInfos, path);
Console.WriteLine(args[2].ToString());
return 0;
}

if ((args[1].Length == 0) || (args[1].ToString().ToUpper() != "AUDIO") || (args[1].ToString().ToUpper() != "VIDEO"))
{
WriteLog("Please Specify the Format AUDIO/VIDEO");
Console.WriteLine("Please Specify the Format AUDIO/VIDEO");
return (int)AVURL_ERR;
}
}

else
{
WriteLog("Youtube URL not in correct format");
Console.WriteLine("Youtube URL not in correct format");
return (int)YLINKFORMAT_ERR;
}
}

private static string RemoveIllegalPathCharacters(string path)
catch(Exception ex)
{
string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(path, "");
WriteLog(ex.Message);
Console.WriteLine("Please check the internet connection");
return (int)NETCON_ERR;
}

Console.WriteLine("Did not pass the validation checks please retify any mistakes in Parameters");
return (int)OTHER_ERR;

}

}
}
Loading