Hi
I have below code of list if videos. I want to save it in Sql Database & Video to be downloaded in A folder with VideoId Name
protected void MyOwnVideos()
{
StringBuilder htmlTable = new StringBuilder();
var client = new RestClient("googleapis.com/youtube/v3");
var request = new RestRequest("search", Method.GET);
request.AddParameter("part", "snippet");
request.AddParameter("type", "video");
request.AddParameter("channelId", "UC_nNoaVw"); // Replace with your actual channelId
request.AddParameter("key", "AIz8..."); // Replace with your actual API key
IRestResponse response = client.Execute(request);
// Check if the response contains data
if (response.Data == null || response.Data.items == null || response.Data.items.Count == 0)
{
Console.WriteLine("No Data Found. Please check your channelId and API key.");
return;
}
// Build the HTML table
htmlTable.Append("");
htmlTable.Append("Video Id Video Title Description Published ");
htmlTable.Append("");
foreach (var data in response.Data.items.OrderBy(x => x.snippet.publishedAt))
{
htmlTable.Append("");
htmlTable.Append($"{data.id} ");
htmlTable.Append($"{data.snippet.title} ");
htmlTable.Append($"{data.snippet.description} ");
htmlTable.Append($"{data.snippet.publishedAt} ");
htmlTable.Append(" ");
}
htmlTable.Append("");
htmlTable.Append("
");
// Output the HTML table
Console.WriteLine(htmlTable.ToString());
}
Thanks
Muhammad Imran AnsariPosted Mar 21, 2025, 6:56 PM
Hello Ramco,
Steps to Implement:
Save Video Details in SQL Database
Download Videos into a Folder with
VideoIdas Filenameyoutube-dloryt-dlp(a Python-based tool) to download the video.VideoId.Than modify you code as:
Good Luck!
Daniel WrightPosted Mar 21, 2025, 3:31 PM
To save the video data in an SQL database and download the videos to a folder with the VideoId as the filename, you'll need to extend the existing code to include the database interaction and file handling functionalities. Here's an overview of the steps involved:
1. Setting up a Database Connection: Before saving data to an SQL database, establish a connection to the database using ADO.NET or an ORM (Object-Relational Mapping) tool like Entity Framework.
2. Create a Table: Design a table in the database that corresponds to the structure of the video data you intend to store. This table could include fields for VideoId, VideoTitle, Description, Published date, and potentially a filepath for the downloaded video.
3. Database Insertion: Within your `MyOwnVideos` method, modify the loop that generates the HTML table to also insert the video data into the SQL database. Utilize ADO.NET commands like `SqlCommand` to perform SQL insert operations.
4. File Handling: After saving the video data to the database, download the actual videos to a designated folder. Make sure to handle filenames using the VideoId to maintain uniqueness.
5. Exception Handling: Implement error handling mechanisms to manage any exceptions that may occur during database interactions or file operations.
6. Security: Prioritize securing your database connection and ensuring proper permissions for file read/write operations to prevent unauthorized access.
By integrating these steps into your existing code, you can achieve the goal of saving video data in an SQL database and downloading the videos to a specific folder based on their VideoId. Should you require more detailed assistance or specific code snippets for any of the steps outlined, feel free to ask!