-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
107 lines (70 loc) · 3.21 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using ArtistYoutubeListGenerator.VocaDbService;
using HtmlAgilityPack;
namespace ArtistYoutubeListGenerator {
class Program {
private static readonly Regex nicoRegex = new Regex(@"nicovideo\.jp/mylist/(\d+)");
private static bool IsFullLink(string str) {
return (str.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|| str.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)
|| str.StartsWith("mailto:", StringComparison.InvariantCultureIgnoreCase));
}
public static string MakeLink(string partialLink) {
if (string.IsNullOrEmpty(partialLink))
return partialLink;
if (IsFullLink(partialLink))
return partialLink;
return string.Format("http://{0}", partialLink);
}
static void Main(string[] args) {
Console.WriteLine("Getting artists from VocaDB.");
var client = new QueryServiceClient();
var artists = client.GetArtistsWithYoutubeChannels(ContentLanguagePreference.Romaji).OrderBy(a => a.Name).ToArray();
Console.WriteLine("Generating document.");
var template = ResourceHelper.ReadTextFile("Template.html");
var doc = new HtmlDocument();
doc.LoadHtml(template);
var count = doc.GetElementbyId("artistCount");
count.InnerHtml = artists.Length + " artists";
var generatedAt = doc.GetElementbyId("generatedAt");
generatedAt.InnerHtml = DateTime.Now.ToString();
var table = doc.GetElementbyId("artistsTable");
foreach (var artist in artists) {
var youtube = artist.WebLinks.FirstOrDefault(a => a.Url.Contains("youtube.com/user") || a.Url.Contains("youtube.com/channel"));
if (youtube == null) {
Console.WriteLine("Found no Youtube link for '{0}' - skipping.", artist.Name);
continue;
}
var tr = table.AppendChild(doc.CreateElement("tr"));
var titleTd = tr.AppendChild(doc.CreateElement("td"));
var titleLink = titleTd.AppendChild(doc.CreateElement("a"));
titleLink.InnerHtml = artist.Name;
titleLink.SetAttributeValue("href", MakeLink(youtube.Url));
titleLink.SetAttributeValue("title", artist.AdditionalNames);
titleLink.SetAttributeValue("class", "extLink youtubeLink");
var nicoTd = tr.AppendChild(doc.CreateElement("td"));
var nicoWebLink = artist.WebLinks.FirstOrDefault(w => w.Url.Contains("www.nicovideo.jp/mylist/"));
if (nicoWebLink != null) {
var match = nicoRegex.Match(nicoWebLink.Url);
if (match.Success) {
var nicoLink = nicoTd.AppendChild(doc.CreateElement("a"));
nicoLink.InnerHtml = "mylist/" + match.Groups[1].Value;
nicoLink.SetAttributeValue("href", MakeLink(nicoWebLink.Url));
nicoLink.SetAttributeValue("class", "extLink nicoLink");
}
}
var vocaDbTd = tr.AppendChild(doc.CreateElement("td"));
var vocaDbLink = vocaDbTd.AppendChild(doc.CreateElement("a"));
vocaDbLink.InnerHtml = "VocaDB page";
vocaDbLink.SetAttributeValue("href", string.Format("http://vocadb.net/Ar/{0}", artist.Id));
vocaDbLink.SetAttributeValue("class", "extLink vocaDbLink");
}
Console.WriteLine("Saving document.");
var path = (args.Any() ? args.First() : "ArtistYoutubes.html");
doc.Save(path, Encoding.UTF8);
}
}
}