private void analyzeGenre(String responseFromServer, out TorrentInfo.Genre genre) { //TODO: [0-9]* has to match a number in site(?). On the bottom, the recommendations have the same regex. This only works because the match takes the // first match, which is the genre of the torrent we're looking at. If it wouldn't take the first match, the result would be wrong. Regex genreRegex = new Regex("<span id=\"cat_[0-9]*\"><strong><a href=\"/(\\w*)/\">(\\w*)<"); Match genreMatch = genreRegex.Match(responseFromServer); String genreStr = genreMatch.Groups[2].ToString(); switch (genreStr) { case "TV": genre = TorrentInfo.Genre.TV; break; case "Movies": genre = TorrentInfo.Genre.Movie; break; case "Anime": genre = TorrentInfo.Genre.Anime; break; case "Music": genre = TorrentInfo.Genre.Music; break; case "Games": genre = TorrentInfo.Genre.Game; break; case "Applications": genre = TorrentInfo.Genre.Application; break; case "Books": genre = TorrentInfo.Genre.Book; break; case "Other": genre = TorrentInfo.Genre.Other; break; case "XXX": genre = TorrentInfo.Genre.XXX; break; default: genre = TorrentInfo.Genre.Other; break; } }
private void analyzeAffiliation(String responeFromServer, TorrentInfo.Genre genre, out int IMDbId, out String kickAssAffiliation) { // All these entries are optional, may be none of them exist //Regex affiliationRegex = new Regex("<div class=\"dataList\">([\\s\\S]*)</ul>"); //Match affiliationMatch = affiliationRegex.Match(responeFromServer); //Match affiliationMatch = affiliationRegex.Match("<ul class=\"block overauto botmarg0\"><li><strong>Movie:</strong> <a href=\"/guardians-%of-the-galaxy-i2015381/\"><span>Guardians of the Galaxy</span></a></li></ul>"); //String affiliationStr = affiliationMatch.Groups[1].ToString(); Regex imdbRegex = new Regex("<li><strong>IMDb link:</strong> <a class=\"plain\" href=\"([^\"]*)\">([0-9]*)</a></li>"); Match imdbMatch = imdbRegex.Match(responeFromServer); String IMDbIdStr = imdbMatch.Groups[2].ToString(); // We encountered one torrent with IMDb Id > Int32.Max... This is not a valid IMDb Id, so the entry is bogus... With try we avoid the Int32-Parse Exception // and set the IMDbId to the default, i.e. 0. if (IMDbIdStr != "") { try { IMDbId = Int32.Parse(IMDbIdStr); } catch { IMDbId = 0; } } else { IMDbId = 0; } Regex affiliationRegex = new Regex("dummyInitialization"); switch (genre) { //{ Movie, TV, Music, Game, Application, Book, Anime, Other, XXX} case TorrentInfo.Genre.Movie: // Example: <li><strong>Movie:</strong> <a href="https://kickass.so/the-hobbit-there-and-back-again-i2310332/"><span>The Hobbit: There and Back Again</span></a></li> affiliationRegex = new Regex("<li><strong>Movie:</strong> <a href=\"([^\"]*)\"><span>([^\"]*)</span></a></li>"); // Why does [\\w\\s]* not work??? break; case TorrentInfo.Genre.TV: // Example: <li><a href="https://kickass.so/banshee-tv30823/">View all <strong>Banshee</strong> episodes</a></li> affiliationRegex = new Regex("<li><a href=\"([^\"]*)\">View all <strong>([^\"]*)</strong> episodes</a></li>"); break; case TorrentInfo.Genre.Music: // Example: <li><strong>Album: </strong><a href="https://kickass.so/search/amon%20amarth%20deceiver%20of%20the%20gods/"><span>Deceiver of the Gods</span></a> affiliationRegex = new Regex("<li><strong>Album: </strong><a href=\"([^\"]*)\"><span>([^\"]*)</span></a>"); break; case TorrentInfo.Genre.Game: // Example: <li><strong>Game:</strong> <a itemprop="url" href="https://kickass.so/far-cry-4-g46310/"><span itemprop="name">Far Cry 4</span></a></li> affiliationRegex = new Regex("<li><strong>Game:</strong> <a itemprop=\"url\" href=\"([^\"]*)\"><span itemprop=\"name\">([^\"]*)</span></a></li>"); break; case TorrentInfo.Genre.Application: // no affiliation break; case TorrentInfo.Genre.Book: // no affiliation break; case TorrentInfo.Genre.Anime: // Example: <li><a href="https://kickass.so/log-horizon-2014-a48494/">View all <strong>Log Horizon (2014)</strong> episodes</a></li> affiliationRegex = new Regex("<li><a href=\"([^\"]*)\">View all <strong>([^\"]*)</strong> episodes</a></li>"); break; case TorrentInfo.Genre.Other: // no affiliation break; case TorrentInfo.Genre.XXX: // no affiliation break; default: break; } Match affiliationMatch = affiliationRegex.Match(responeFromServer); kickAssAffiliation = affiliationMatch.Groups[1].ToString(); }