Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GBVideoTimeCalc
{
class Program
{
static void Main(string[] args)
{
int page = 1;
int pages = 0;
int amt = 0;
double results = 0;
int pageSize = 100;
string apiKey = "<INSERT YOUR API KEY HERE>";
string reqUrl = "https://www.giantbomb.com/api/videos/?api_key="+apiKey;
double totalLength = 0;
XElement response = XElement.Load(reqUrl);
results = Convert.ToDouble(response.Element("number_of_total_results").Value);
pages = Convert.ToInt32(Math.Ceiling(results / pageSize));
IEnumerable<XElement> videos = response.Element("results").Elements("video");
foreach (XElement video in videos)
{
string strLengthSeconds = video.Element("length_seconds").Value;
totalLength += (Convert.ToDouble(strLengthSeconds) / 60) / 60;
amt += 1;
}
while (page < pages)
{
reqUrl = "https://www.giantbomb.com/api/videos/?api_key="+apiKey+"&page="+page.ToString();
response = XElement.Load(reqUrl);
foreach (XElement video in videos)
{
string strLengthSeconds = video.Element("length_seconds").Value;
totalLength += (Convert.ToDouble(strLengthSeconds) / 60) / 60;
amt += 1;
}
Console.Clear();
Console.WriteLine("SCANNED " + amt + " VIDEOS");
Console.WriteLine("HOURS: " + totalLength );
page += 1;
}
Console.WriteLine("Hours of Content: " + totalLength.ToString());
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.