public override List <episode_item> TOC() { List <episode_item> toc = new List <episode_item>(); var tbl = _driver.findElement(By.XPath("//*[@id=\"dslc-theme-content-inner\"]/table")); if (tbl == null) { throw new IncorrectPageStructureException("Table of contents not found"); } var items = tbl.FindElements(By.TagName("tr")); // check if table is in old format var firstrow = items[0].FindElements(By.TagName("td")); int firstitem = 0; if (firstrow[0].Text == "Time" && firstrow[1].Text == "Band" && (firstrow[2].Text == "Song" || firstrow[2].Text == "Name")) { firstitem = 1; } for (int i = firstitem; i < items.Count; i++) { var tds = items[i].FindElements(By.TagName("td")); var ei = new episode_item() { start = tds[0].Text, band = tds[1].Text, name = tds[2].Text, }; if (tds.Count == 4) { ei.duration = ""; ei.album = tds[3].Text; ei.year = 0; } else { ei.duration = tds[3].Text; ei.album = tds[4].Text; Int32 year = 0; Int32.TryParse(tds[5].Text, out year); ei.year = year; } toc.Add(ei); } return(toc); }
public override List <episode_item> TOC() { List <episode_item> toc = new List <episode_item>(); var tbls = _driver.FindElements(By.XPath("//*[@class='block-content post-content']/table")); if (tbls.Count == 0) { return(toc); } var tbl = tbls[tbls.Count - 1]; var items = tbl.FindElements(By.TagName("tr")); Tuple <int, string[]> t1 = new Tuple <int, string[]>(0, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "Label" }); Tuple <int, string[]> t2 = new Tuple <int, string[]>(1, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "Listeners" }); Tuple <int, string[]> t3 = new Tuple <int, string[]>(-2, new string[] { "Song", "Length", "Album", "Year", "Band", "Label", "Listeners" }); Tuple <int, string[]> t4 = new Tuple <int, string[]>(0, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "Label", "Listeners" }); Tuple <int, string[]> t5 = new Tuple <int, string[]>(0, new string[] { "Time Aired", "Band", "Song", "", "Album", "Year", "Composer", "Label", "Listeners" }); Tuple <int, string[]> t6 = new Tuple <int, string[]>(0, new string[] { "Time Aired", "Band", "Song", "", "Album", "Year", "Composer", "Label", "" }); Tuple <int, string[]> t7 = new Tuple <int, string[]>(0, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "Label", "" }); Tuple <int, string[]> t8 = new Tuple <int, string[]>(0, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "Lable", "" }); Tuple <int, string[]> t9 = new Tuple <int, string[]>(0, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "", "" }); Tuple <int, string[]> tA = new Tuple <int, string[]>(0, new string[] { "Air Time", "Band", "Song", "Song Time", "Album", "Year", "Composer", "Lable", "Listeners" }); Tuple <int, string[]> tB = new Tuple <int, string[]>(2, new string[] { "Song", "Artist", "Song", "Time", "Album", "Year", "Label", "Label" }); Tuple <int, string[]> tC = new Tuple <int, string[]>(-2, new string[] { "Time", "Band", "Song", "Year", "Composer", "Label", "Listeners" }); Tuple <int, string[]> tD = new Tuple <int, string[]>(-3, new string[] { "Time", "Band", "Song", "Album", "Year", "Composer", "Label", "Listeners" }); Tuple <int, string[]> tE = new Tuple <int, string[]>(-3, new string[] { "Time", "Band", "Song", "Album", "Year", "Composer", "Label", "" }); Tuple <int, string[]> tF = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "Composer", "Label", "" }); Tuple <int, string[]> tG = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "Composer", "Label", "Listeners" }); Tuple <int, string[]> tH = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "Composer", "Label" }); Tuple <int, string[]> tI = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "Composer", "", "" }); Tuple <int, string[]> tJ = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "", "", "", "" }); Tuple <int, string[]> tK = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "Composer", "Listeners", "" }); Tuple <int, string[]> tL = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "", "", "" }); Tuple <int, string[]> tM = new Tuple <int, string[]>(0, new string[] { "Time", "Band", "Song", "Time", "Album", "Year", "Composer", "Label", "", "" }); Tuple <int, string[]> tN = new Tuple <int, string[]>(0, new string[] { "Band", "Album", "Year", "Composer", "", "", "", "", "", "" }); Tuple <int, string[]> tO = new Tuple <int, string[]>(0, new string[] { "Time", "Artist", "Title", "Duration", "Album", "Year", "Composer", "Label", "" }); Tuple <int, string[]>[] types = new Tuple <int, string[]>[] { t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF, tG, tH, tI, tJ, tK, tL, tM, tN, tO }; var th = items[0].FindElements(By.TagName("td")); string[] ht = new string[th.Count]; for (int k = 0; k < th.Count; k++) { ht[k] = th[k].Text; } int type = -1; foreach (var t in types) { if (ht.Length != t.Item2.Length) { continue; } int c; for (c = 0; c < ht.Length; c++) { if (ht[c] != t.Item2[c]) { break; } } if (c == ht.Length) { type = t.Item1; break; } } int start = 1; // check if this is just table without header if (ht[0].isHMS() && ht[3].isMS()) { type = 0; start = 0; } if (type < 0) { return(toc); } for (int i = start; i < items.Count; i++) { var tds = items[i].FindElements(By.TagName("td")); if (tds.Count < 6) { continue; } var ei = new episode_item() { start = tds[0].Text, band = tds[1].Text, name = tds[2].Text, duration = tds[3].Text, album = tds[4].Text, }; if (!ei.start.isHMS() || !ei.duration.isMS()) { continue; } if (ei.band == "miwshowopen" || ei.name == "miwshowopen" || ei.name == "Musicinwidescreen ID1") { continue; } Int32 year = 0; Int32.TryParse(tds[5].Text, out year); ei.year = year; if (type == 0 && tds.Count > 7) { ei.composer = tds[6].Text; ei.label = tds[7].Text; } else if (type == 1 && tds.Count > 6) { ei.composer = tds[6].Text; } else if (type == 2 && tds.Count > 6) { ei.label = tds[6].Text; } toc.Add(ei); } return(toc); }