Created
April 9, 2013 04:58
-
-
Save mikeminutillo/5343081 to your computer and use it in GitHub Desktop.
Loads all of the videos uploaded by "thedicetower" and categorizes them
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
void Main() | |
{ | |
var entries = GetEntries().Cache("from-youtube"); | |
(from e in entries | |
let category = Categorize(e.Title) | |
group e by category into g | |
orderby g.Key descending | |
select new | |
{ | |
g.Key, | |
Count = g.Count() | |
}).Dump(); | |
entries.Where(x => Categorize(x.Title) == "Other").OrderBy(e=> e.Updated).Dump(); | |
} | |
Tuple<string, string>[] hosts = new[] { | |
Tuple.Create("tom", "Tom"), | |
Tuple.Create("ryan", "Ryan"), | |
Tuple.Create("scott", "Scott"), | |
Tuple.Create("eric", "Eric"), | |
Tuple.Create("bart", "Bart"), | |
Tuple.Create("chief", "Bart"), | |
Tuple.Create("barry", "Barry"), | |
Tuple.Create("hoier", "Hoier"), | |
}; | |
public string Categorize(string title) | |
{ | |
title = title.ToLower(); | |
if(title.Contains("miami")) | |
return "Miami Dice"; | |
if(title.Contains("100")) | |
return "Top 100"; | |
if(title.Contains("top ten") || title.Contains("top 10")) | |
return "Top 10"; | |
if(title.Contains("preview")) | |
{ | |
foreach(var host in hosts) | |
if(title.Contains(host.Item1)) | |
return "Preview - " + host.Item2; | |
return "Preview - Other"; | |
} | |
if(title.Contains("review")) | |
{ | |
foreach(var host in hosts) | |
if(title.Contains(host.Item1)) | |
return "Review - " + host.Item2; | |
return "Review - Other"; | |
} | |
if(title.Contains("jim")) | |
return "Jim's Video"; | |
if(title.Contains("news")) | |
return "News"; | |
if(title.Contains("with")) | |
{ | |
// This is a guess | |
foreach(var host in hosts) | |
if(title.Contains(host.Item1)) | |
return "Review - " + host.Item2; | |
} | |
return "Other"; | |
} | |
public static IQueryable<Entry> GetEntries() | |
{ | |
var settings = new YouTubeRequestSettings(null, null); | |
settings.AutoPaging = true; | |
var request = new YouTubeRequest(settings); | |
var response = request.GetVideoFeed("thedicetower"); | |
return from e in response.Entries.AsQueryable() | |
select new Entry | |
{ | |
Title = e.Title, | |
Url = e.WatchPage.AbsoluteUri, | |
Updated = e.Updated | |
}; | |
} | |
[Serializable] | |
public class Entry | |
{ | |
public string Title { get; set; } | |
public string Url { get; set; } | |
public DateTime Updated { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment