Created
March 24, 2020 23:38
-
-
Save anthonicaldwell/62844f63bc511c423b25b4070c17ee50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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