Skip to content

Commit

Permalink
Added Auto ffmpeg setup
Browse files Browse the repository at this point in the history
Changed UI
Changed Program needs admin permission to check if ffmpeg is installed
Removed unused using statements
Removed Crypt.cs since its useless for this project
  • Loading branch information
FabioGaming committed May 21, 2022
1 parent 2396209 commit af5b2ee
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 132 deletions.
125 changes: 0 additions & 125 deletions ListRipper/Crypt.cs

This file was deleted.

136 changes: 136 additions & 0 deletions ListRipper/FFMPEGManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Threading.Tasks;
using System.Net;
using System.IO.Compression;
using System.IO;
using System.Threading;

namespace ListRipper
{
class FFMPEGManager
{
private static bool isDownloaded = false;

public static Task setupFFMPEG()
{

bool hasAgreed = false;
Console.Clear();
FLSharp.PrintColor("FFMPEG has not been installed.", "yellow");
FLSharp.PrintColor("Do you want to get it set up? (not having FFMPEG setup will result in the Program not working properly)", "yellow");
FLSharp.PrintColor("Y | N", "yellow");
Console.WriteLine("");
string selection = Console.ReadLine();
switch(selection.ToLower())
{
case "y":
hasAgreed = true;
break;
case "yes":
hasAgreed = true;
break;
case "n":
return Task.CompletedTask;
case "no":
return Task.CompletedTask;
default:
setupFFMPEG();
break;

}
if(!hasAgreed)
{
setupFFMPEG();
}
Logging.LogSystem("Downloading FFMPEG, this might take a while.");
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgress);
Uri url = new Uri("https://github.com/FabioGaming/PlayListRipper/releases/download/v1.1/ffmpeg.zip");

try
{
client.DownloadFileAsync(url, $"C:/Users/{Environment.UserName}/ffmpeg.zip");
}
catch
{
Logging.LogError("Something went wrong while trying to Download ffmpeg.");
Task.Delay(3000);
return Task.CompletedTask;
}
while(!isDownloaded) {}

Logging.LogSuccess("Downloaded FFMPEG!");
Logging.LogSystem("Creating Folder...");
try
{
Directory.CreateDirectory("C:/ffmpeg/");
Logging.LogSuccess("Created Folder: C:/ffmpeg/");
}catch
{
Logging.LogError("Something went wrong.");
Thread.Sleep(3000);
return Task.CompletedTask;
}
Logging.LogSystem("Extracting...");
try
{
ZipFile.ExtractToDirectory($"C:/Users/{Environment.UserName}/ffmpeg.zip", "C:/ffmpeg/");
Logging.LogSuccess("Extracted ffmpeg into: C:/ffmpeg/");
} catch
{
Logging.LogError("Something went wrong.");
Thread.Sleep(3000);
return Task.CompletedTask;
}
Logging.LogSystem("Cleaning up...");
try
{
File.Delete($"C:/Users/{Environment.UserName}/ffmpeg.zip");
Logging.LogSuccess("Cleaned up data.");
}catch
{
Logging.LogError("Something went wrong.");
Thread.Sleep(3000);
return Task.CompletedTask;
}
Logging.LogSystem("Adding ffmpeg to system variables...");
try
{
var name = "PATH";
var scope = EnvironmentVariableTarget.Machine;
var oldValues = Environment.GetEnvironmentVariable(name, scope);
var newValues = oldValues + @";C:\ffmpeg";
Environment.SetEnvironmentVariable(name, newValues, scope);
Logging.LogSuccess("Added ffmpeg.");

} catch(Exception e)
{
Console.WriteLine(e);
Logging.LogError("Something went wrong.");
Thread.Sleep(3000);
return Task.CompletedTask;
}
Console.WriteLine("");
Logging.LogSuccess("FFMPEG has been successfully downloaded and installed to the system.");
FLSharp.PrintColor("Press any key to continue.", "yellow");
Console.ReadKey();

return Task.CompletedTask;
}


private static void DownloadProgress(object sender, DownloadProgressChangedEventArgs e)
{
string progress = null;
string progressmessage = null;

for (int i = 0; i != e.ProgressPercentage; i++) {
progress = progress + "=";
progressmessage = $"[{progress}".PadRight(100) + "]";

}
Console.Write("\r{0}", $"Downloading: {e.ProgressPercentage}% | {progressmessage}");
if(e.ProgressPercentage == 100) { isDownloaded = true; }
}
}
}
9 changes: 4 additions & 5 deletions ListRipper/FLSharp.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;

namespace ListRipper
{
Expand Down Expand Up @@ -90,6 +85,10 @@ public static void PrintColor(string message, string color)
Console.WriteLine(message);
Console.ResetColor();
}
public static string GetDateTime()
{
return DateTime.Now.ToString();
}

}
}
8 changes: 8 additions & 0 deletions ListRipper/ListRipper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>ListRipper</AssemblyName>
<SignAssembly>false</SignAssembly>
<Version>1.2.0</Version>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
<PackageReference Include="YoutubeExplode" Version="6.1.2" />
<PackageReference Include="YoutubeExplode.Converter" Version="6.1.2" />
</ItemGroup>
Expand Down
18 changes: 16 additions & 2 deletions ListRipper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using YoutubeExplode;
using YoutubeExplode.Videos.Streams;
using System.Threading.Tasks;
using YoutubeExplode.Converter;
using System.IO;
using YoutubeExplode.Common;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Principal;

namespace ListRipper
{
Expand All @@ -19,14 +19,28 @@ class Program
static async Task Main(string[] args)
{
Console.Title = "PlayListRipper";
await MainUIAsync();



var target = Environment.GetEnvironmentVariable("PATH");
if(!target.ToLower().Contains("ffmpeg")) {
await FFMPEGManager.setupFFMPEG();
}
await MainUIAsync();

}
static async Task MainUIAsync()
{


Console.Clear();
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
{
FLSharp.PrintColor("Please note that this Program needs admin permissions to Check if ffmpeg is installed properly.", "red");
FLSharp.PrintColor("Please run this Program as Administrator.", "red");
}
FLSharp.PrintColor("1: Download Video", "yellow");
FLSharp.PrintColor("2: Download PlayList", "yellow");
FLSharp.PrintColor("3: Download Video (AUDIO)", "yellow");
Expand Down
8 changes: 8 additions & 0 deletions ListRipper/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"ListRipper": {
"commandName": "Project",
"sqlDebugging": false
}
}
}

0 comments on commit af5b2ee

Please sign in to comment.