Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
- Fixed a couple bugs, see details in change log
- Improved performance by queuing playlist tasks on threads
  • Loading branch information
ifBars committed Feb 3, 2023
1 parent d50f2f9 commit a188e34
Show file tree
Hide file tree
Showing 27 changed files with 275 additions and 66 deletions.
Binary file modified .vs/UrlArray/v16/.suo
Binary file not shown.
23 changes: 19 additions & 4 deletions UrlArray/Form1.Designer.cs

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

127 changes: 83 additions & 44 deletions UrlArray/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using System.Collections.Concurrent;

namespace UrlArray
{
Expand Down Expand Up @@ -48,7 +49,7 @@ private void button1_Click(object sender, EventArgs e)
// Register YouTube Service
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "YOUR_API_KEY",
ApiKey = "AIzaSyAribhLCMFwNSyRWQ08tvDUorRg_36CPqA",
ApplicationName = this.GetType().ToString()
});

Expand Down Expand Up @@ -90,8 +91,8 @@ private void button1_Click(object sender, EventArgs e)
nameList.Insert(index, videoName);

// Clearing up
textBox1.Text = "";
textBox4.Text = "";
textBox1.Text = "URL";
textBox4.Text = "Name (Optional)";
label1.Text = "Link added";
index++;
label3.Text = index.ToString();
Expand Down Expand Up @@ -141,7 +142,7 @@ private void button2_Click(object sender, EventArgs e)
prefix = textBox2.Text;
}

if(textBox5.Text.Contains("File Name (No Need for .txt)") == false)
if (textBox5.Text.Contains("File Name (No Need for .txt)") == false)
{
userInput = textBox5.Text;
}
Expand All @@ -159,34 +160,50 @@ private void button2_Click(object sender, EventArgs e)
filePath = Path.Combine(folderPath, userInput + ".txt");
}

// Make sure the lists are the same length
if (urlList.Count != nameList.Count)
// Make sure the lists are the same length
if (urlList.Count != nameList.Count)
{
MessageBox.Show("Error: lists are not the same length");
return;
}

try
{
// Erase the file each time before rewriting to it
File.WriteAllText(filePath, string.Empty);
BlockingCollection<Tuple<string, string>> queue = new BlockingCollection<Tuple<string, string>>(new ConcurrentQueue<Tuple<string, string>>());

// Write the list of URLs and names to a file
using (StreamWriter sw = new StreamWriter(filePath))
{
// Producer task
Task.Factory.StartNew(() => {
for (int i = 0; i < urlList.Count; i++)
{
sw.WriteLine(urlList[i]);
sw.WriteLine(nameList[i]);
sw.WriteLine("");
queue.Add(new Tuple<string, string>(urlList[i], nameList[i]));
}
label1.Text = "File written successfully";
}
queue.CompleteAdding();
});

// Consumer task
Task.Factory.StartNew(() => {
// Erase the file each time before rewriting to it
File.WriteAllText(filePath, string.Empty);

// Write the list of URLs and names to a file
using (StreamWriter sw = new StreamWriter(filePath))
{
foreach (var item in queue.GetConsumingEnumerable())
{
sw.WriteLine(item.Item1);
sw.WriteLine(item.Item2);
sw.WriteLine("");
}
}

textBox5.Text = "File Name (No Need for .txt)";
});
}
catch (IOException)
{
MessageBox.Show("An error occurred while trying to access the file: Is the file open in another program?");
}
label1.Text = "File written successfully";
}

private async void button3_Click(object sender, EventArgs e)
Expand All @@ -196,13 +213,16 @@ private async void button3_Click(object sender, EventArgs e)
// Register YouTube Service
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "YOUR_API_KEY",
ApiKey = "AIzaSyAribhLCMFwNSyRWQ08tvDUorRg_36CPqA",
ApplicationName = this.GetType().ToString()
});

// Get the playlist ID from the text box
var playlistId = textBox3.Text;
textBox3.Text = "";
textBox3.Text = "Playlist ID";

// Initialize the blocking collection to hold the results
var playlistItemsBuffer = new BlockingCollection<PlaylistItem>();

// Try playlist ID and throw error if Incorrect
try
Expand All @@ -211,44 +231,54 @@ private async void button3_Click(object sender, EventArgs e)
var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
playlistItemsListRequest.PlaylistId = playlistId;
playlistItemsListRequest.MaxResults = 500;
playlistItemsListRequest.MaxResults = 500;

// Set the PageToken property to an empty string to retrieve the first page of results
playlistItemsListRequest.PageToken = "";

// Initialize the list to hold the results
playlistItems = new List<PlaylistItem>();

// Initialize the counter variable
var totalResults = 0;

// Retrieve the results
while (totalResults < 500)
// Execute the request in a background thread
await Task.Run(async () =>
{
// Execute the request
playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();

// Add the results to the list
playlistItems.AddRange(playlistItemsListResponse.Items);

// Increment the counter variable
totalResults += playlistItemsListResponse.Items.Count;
// Initialize the counter variable
var totalResults = 0;

// Set the page token for the next request
playlistItemsListRequest.PageToken = playlistItemsListResponse.NextPageToken;

// If there are no more pages, break out of the loop
if (string.IsNullOrEmpty(playlistItemsListResponse.NextPageToken))
while (totalResults < 500)
{
break;
// Execute the request
playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();

// Add the results to the blocking collection
foreach (var playlistItem in playlistItemsListResponse.Items)
{
playlistItemsBuffer.Add(playlistItem);
}

// Increment the counter variable
totalResults += playlistItemsListResponse.Items.Count;

// Set the page token for the next request
playlistItemsListRequest.PageToken = playlistItemsListResponse.NextPageToken;

// If there are no more pages, break out of the loop
if (string.IsNullOrEmpty(playlistItemsListResponse.NextPageToken))
{
break;
}
}
}
});

// Complete the blocking collection to signal that no more items will be added
playlistItemsBuffer.CompleteAdding();

// Update the UI with the results (if needed)
}
catch (GoogleApiException ev)
{
if (ev.Error.Code == 404)
{
MessageBox.Show("Invalid playlist ID. Is the playlist private? All playlists must be public to grab.");
MessageBox.Show("The program will now close due to GoogleAPIException issue.");
Environment.Exit(0);
}
else
{
Expand All @@ -257,15 +287,14 @@ private async void button3_Click(object sender, EventArgs e)
}

// Print the title and URL of each video in the playlist
foreach (var playlistItem in playlistItems)
foreach (var playlistItem in playlistItemsBuffer.GetConsumingEnumerable())
{

string videoTitle = "";
realVideoTitle = playlistItem.Snippet.Title;

if (textBox4.Text.Contains("Name (Optional)") == false)
if (checkBox1.Checked == true)
{
Console.WriteLine("Custom Name");
Form2 f2 = new Form2();
videoTitle = f2.openName();
}
Expand Down Expand Up @@ -293,5 +322,15 @@ private void button4_Click(object sender, EventArgs e)
index = 0;
label3.Text = index.ToString();
}

private void label3_Click(object sender, EventArgs e)
{

}

private void label2_Click(object sender, EventArgs e)
{

}
}
}
2 changes: 1 addition & 1 deletion UrlArray/ProTVUploader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>15</ApplicationRevision>
<ApplicationRevision>16</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
6 changes: 3 additions & 3 deletions UrlArray/bin/Debug/UrlArray.application
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<assemblyIdentity name="UrlArray.application" version="1.0.0.14" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
<assemblyIdentity name="UrlArray.application" version="1.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="UrlArray" asmv2:product="UrlArray" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" mapFileExtensions="true" />
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.7.2" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="UrlArray.exe.manifest" size="8314">
<assemblyIdentity name="UrlArray.exe" version="1.0.0.14" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<assemblyIdentity name="UrlArray.exe" version="1.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>uLqO2o0s7/2AkoxiLmRkWirTWbbv7uNGwubp0jYrMOY=</dsig:DigestValue>
<dsig:DigestValue>nTniX6qNIZ8dAyS3Agz/vkyWJYE/94V6UCn7GcXArIk=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified UrlArray/bin/Debug/UrlArray.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions UrlArray/bin/Debug/UrlArray.exe.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<asmv1:assemblyIdentity name="UrlArray.exe" version="1.0.0.14" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<asmv1:assemblyIdentity name="UrlArray.exe" version="1.0.0.16" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<application />
<entryPoint>
<assemblyIdentity name="UrlArray" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
Expand Down Expand Up @@ -126,14 +126,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="UrlArray.exe" size="19936">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="UrlArray.exe" size="23008">
<assemblyIdentity name="UrlArray" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>lBKhYWZi20DLFeBS8FztjPyKt6sfDr/X5LPTuy7LW4w=</dsig:DigestValue>
<dsig:DigestValue>8USorpyS1CVNkKaFC1lraCU7Pcv31roGnHla2iuCvGY=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified UrlArray/bin/Debug/UrlArray.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Binary file not shown.
Loading

0 comments on commit a188e34

Please sign in to comment.