Forked from anthonicaldwell/giant_bomb_hour_counter.cs
Created
April 3, 2020 06:14
-
-
Save dterracino/e0589afd646d7f4996b604383a0197c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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