Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Moder112 authored Jan 12, 2019
1 parent eb5863c commit 46ad706
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 52 deletions.
288 changes: 236 additions & 52 deletions AnnotationsMassDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@ class Program
static void Main(string[] args)
{
Console.SetWindowSize(100, Console.WindowHeight);
// string[] args = { "$(author)//$(title)-$(id)$(ext)", "https://www.youtube.com/watch?v=wsAXCI0R7VE" };
Console.WriteLine("Youtube Annotation Mass Downloader\nCoded in an hour to preserve old youtube annotations\nlike 6 days before they die.\nDirect any bug reports to @Moder112#0247 on Discord");
if (args.Length < 1)
{
Console.WriteLine("No Arguments use:\nAnnotationsMassDownloader.exe <Path> <Video,Channel or text file>");
}
else {
if (args[1].Contains("list="))
{
string youtube = "list=";
string cid = args[1].Substring(args[1].IndexOf(youtube) + youtube.Length).Replace("/", "");
try
{
getplaylist(cid, args[0]);
}
catch (Exception e)
{
Console.WriteLine("Playlist init failed\n" + e);
}
}
else
if (args[1].Contains("watch?v="))
{
string videoid = args[1].Substring(args[1].IndexOf("=")+1).Replace("/", "");
Expand Down Expand Up @@ -61,6 +76,7 @@ static void Main(string[] args)
Console.WriteLine("User init failed\n" + e);
}
}


else
{
Expand All @@ -80,7 +96,20 @@ static async void filoop(string[] args)
{
foreach (string ex in File.ReadAllLines(args[1]))
{
if (ex.Contains("watch?v="))
if (ex.Contains("list="))
{
string youtube = "list=";
string cid = ex.Substring(ex.IndexOf(youtube) + youtube.Length).Replace("/", "");
try
{
await getplaylist(cid, args[0]);
}
catch (Exception e)
{
Console.WriteLine("User playlist failed\n" + e);
}
}
else if (ex.Contains("watch?v="))
{
string videoid = ex.Substring(ex.IndexOf("=") + 1).Replace("/", "");
if (videoid.Contains("&"))videoid= videoid.Substring(0, videoid.IndexOf("&"));
Expand Down Expand Up @@ -109,6 +138,7 @@ static async void filoop(string[] args)
}
// getchannelshit(cid, args[0]);
}

else if (ex.Contains("https://www.youtube.com/channel/"))
{
string youtube = "https://www.youtube.com/channel/";
Expand All @@ -134,84 +164,238 @@ static async Task
getid(string channelid, string path)
{
var client = new YoutubeClient();
int retry2 = 10;
bool Bretry = false;
string video = null;
while (video == null)
{
if (retry2 == 0)
{
Bretry = true;
break;
}
try
{
video = await client.GetChannelIdAsync(channelid);
}
catch (Exception e)
{
Console.WriteLine("Retrying channel id download " + (11 - retry2) + " attempt");
}
retry2--;
if (video == null)
{
Thread.Sleep(1000);
}

}
await getchannelshit(video, path);

var id = await client.GetChannelIdAsync(channelid);
getchannelshit(id, path);

}
static async Task
static async Task
getchannelshit(string channelid, string path)
{
var client = new YoutubeClient();

var video = await client.GetChannelUploadsAsync(channelid);

IReadOnlyList<YoutubeExplode.Models.Video> video = null;
int retry2 = 10;
bool Bretry = false;
Console.WriteLine("Downloading channel started " + channelid);
foreach (var x in video)
while (video == null)
{
if (retry2 == 0)
{
Bretry = true;
break;
}
try
{
video = await client.GetChannelUploadsAsync(channelid);
}
catch (Exception e)
{
Console.WriteLine("Retrying channel download " + (11 - retry2) + " attempt");
}
retry2--;
if (video == null)
{
Thread.Sleep(1000);
}
else
{
break;
}

}

// var video = await client.GetChannelUploadsAsync(channelid);

try
{
foreach (var x in video)
{
await getshit(x.Id, path);
}
}catch(Exception x)
{
await getshit(x.Id, path);
Console.WriteLine(x);
}
Console.WriteLine("Downloading channel finished " + channelid);
// Console.WriteLine("Downloading channel finished " + channelid);
}
static async Task
getshit(string videoid, string path)
static async Task getplaylist(string channelid, string path)
{
var client = new YoutubeClient();
var video = await client.GetVideoAsync(videoid);
var WClient = new WebClient();
int retry = 5;
while (retry > 0)

YoutubeExplode.Models.Playlist video = null;
int retry2 = 10;
bool Bretry = false;
Console.WriteLine("Downloading playlist started " + channelid);
while (video == null)
{
if (retry2 == 0)
{
Bretry = true;
break;
}
try
{
WClient.DownloadFile("http://www.youtube.com/annotations_invideo?features=1&legacy=1&video_id=" + videoid, videoid);
while (WClient.IsBusy) Thread.Sleep(100);

if (vetforformatting(videoid))
{
string titletest = title(path, videoid, video.Title, video.Author);
if (!File.Exists(titletest))
{
File.Copy(videoid, titletest);
Console.WriteLine("Downloaded annotations for video: " + video.Title);
if (File.Exists(videoid)) File.Delete(videoid);
break;
}
else
{
Console.WriteLine("Annotations file exists already: " + video.Title);
if (File.Exists(videoid)) File.Delete(videoid);
break;
}
}
else
{
Console.WriteLine("Video doesn't contain old youtube annotations: " + video.Title);
if (File.Exists(videoid)) File.Delete(videoid);
break;
}
video = await client.GetPlaylistAsync(channelid);
}
catch (Exception e)
{
retry--;

if (retry==0)

Console.WriteLine(e);
else
Console.WriteLine("Retrying playlist download " + (11 - retry2) + " attempt");
}
retry2--;
if (video == null)
{
Thread.Sleep(1000);
}
else
{
break;
}

}

// var video = await client.GetChannelUploadsAsync(channelid);

try
{
foreach (var x in video.Videos)
{
await getshit(x.Id, path);
}
}
catch (Exception x)
{
Console.WriteLine(x);
}
// Console.WriteLine("Downloading channel finished " + channelid);
}
static async Task
getshit(string videoid, string path)
{

var client = new YoutubeClient();
YoutubeExplode.Models.Video video = null;
int retry2 = 10;
bool Bretry = false;
while (video == null)
{
if (retry2 == 0)
{
Console.WriteLine("Downloading failed, retrying " + video.Title);
Bretry = true;
break;
}
try
{
if (File.Exists(videoid)) File.Delete(videoid);
video= await client.GetVideoAsync(videoid);
}
catch
catch (Exception e)
{

Console.WriteLine("Retrying video metadata download " + (11 - retry2) + " attempt");
}
Console.ReadLine();
retry2--;
if (video == null)
{
Thread.Sleep(1000);
}
else
{
break;
}


}
var WClient = new WebClient();
Console.WriteLine(video);
int retry = 10;
if (Bretry == false)
{
while (retry > 0)
{
try
{
WClient.DownloadFile("http://www.youtube.com/annotations_invideo?features=1&legacy=1&video_id=" + videoid, videoid);
while (WClient.IsBusy) Thread.Sleep(100);
}
catch (Exception e)
{
retry--;

if (retry == 0)

Console.WriteLine(e);
else
{
Thread.Sleep(1000);
Console.WriteLine("Downloading failed, retrying " + video.Title);

}
try
{
if (File.Exists(videoid)) File.Delete(videoid);
}
catch
{

}

// Console.ReadLine();
}
if (vetforformatting(videoid))
{
string titletest = title(path, videoid, video.Title, video.Author);
if (!File.Exists(titletest))
{
File.Copy(videoid, titletest);
Console.WriteLine("Downloaded annotations for video: " + video.Title);
if (File.Exists(videoid)) File.Delete(videoid);
break;
}
else
{
Console.WriteLine("Annotations file exists already: " + video.Title);
if (File.Exists(videoid)) File.Delete(videoid);
break;
}
}
else
{
Console.WriteLine("Video doesn't contain old youtube annotations: " + video.Title);
if (File.Exists(videoid)) File.Delete(videoid);
break;
}

}
}
else
{
Console.WriteLine("Cannot retrieve metadata with YoutubeExplode, abandoning download");
return;
}


}
static bool vetforformatting(string path)
Expand Down
Binary file added AnnotationsMassDownloader/bin/ADL1.4.zip
Binary file not shown.
Binary file added AnnotationsMassDownloader/bin/ADL1.5.1.zip
Binary file not shown.
Binary file added AnnotationsMassDownloader/bin/ADL1.5.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions AnnotationsMassDownloader/bin/channellist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://www.youtube.com/watch?v=YoB8t0B4jx4&list=PLbpi6ZahtOH7bL0IJkliFsWD8txSJsHZd
https://www.youtube.com/watch?v=wsAXCI0R7VE&t=2s
https://www.youtube.com/channel/UCBR8-60-B28hp2BmDPdntcQ
https://www.youtube.com/channel/UCMaOD7q-u-p6-ysGOjgYBZw
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 46ad706

Please sign in to comment.