public void AddTorrent(Torrent torrent) { #region Information Contents /* **Information[0-10] -- Music information** * * information[0] --> Artist * information[1] --> Album * information[2] --> AlbumType * information[3] --> bitrate * information[4] --> year * information[5] --> physical format (CD,DVD,VINYL,WEB) * information[6] --> bit format (MP3,FLAC) * * **Information[10-20] -- File Information** * * information[10] --> path * information[11] --> file name * information[12] --> birth * information[13] --> destination path * information[14] --> discard * */ #endregion try { string[] information = torrent.GetInformation(); DataRow row; row = table.NewRow(); row["File"] = information[11]; row["Artist"] = information[0]; row["Album"] = information[1]; row["Save Structure"] = information[13]; row["Handled"] = false; row["Error"] = (information[14] == "true") ? true : false; row["Release Format"] = information[2]; row["Bitrate"] = information[3]; row["Year"] = information[4]; row["Physical Format"] = information[5]; row["Bit Format"] = information[6]; row["File Path"] = information[10]; row["Site Origin"] = (information[14] == "true") ? "Discarded" : information[12]; row["Processed"] = true; string currentfilename = torrent.GetFileName(); lock (obj) { DataRow dr = table.Rows.Find(currentfilename); if (dr != null) table.Rows[table.Rows.IndexOf(dr)].Delete(); table.Rows.Add(row); } } catch (Exception e) { DirectoryHandler.LogError(e.Message + "\n" + e.StackTrace); } }
public Torrent VerifyTorrent(Torrent torrent) { string[] information = torrent.GetInformation(); for (int a = 0; a < information.Length; a++) { /*Switch statement soley to improve readability*/ switch (a) { case 0: //Artist { if (information[a] == null) goto default; if (SettingsHandler.GetDoubleSpaceRemoval()) { while (information[0].Contains(" ")) information[0] = information[0].Replace(" ", " "); } /*MusicBrainzXMLDocumentCreator createXML = new MusicBrainzXMLDocumentCreator("http://musicbrainz.org/ws/1/artist/?type=xml&name=" + information[0]); MusicBrainzXMLDocumentArtist[] artists = createXML.ProcessArtist(); /*if (!artists[0].name.Equals(information[0]) && !artists[1].name.Equals(information[0])) { string trimmedArtist = information[0].Trim(); if (!artists[0].name.Equals(trimmedArtist) && !artists[1].name.Equals(trimmedArtist)) { information[0] = IssueWarning("Artist is not perfect match", information[10]); } }*/ } break; case 1: //Album { if (information[a] == null) goto default; /*MusicBrainzXMLDocumentCreator createXML = new MusicBrainzXMLDocumentCreator("http://musicbrainz.org/ws/1/release/?type=xml&title=" + information[1]); MusicBrainzXMLDocumentRelease[] releases = createXML.ProcessRelease(); /*if (!releases[0].releaseTitle.Equals(information[1]) && releases[0].ext_score.Equals("100")) { information[1] = IssueWarning("Album is not perfect match", information[10]); }*/ } break; case 2: //Release Type { if (information[a] == null) goto default; /*MusicBrainzXMLDocumentCreator createXML = new MusicBrainzXMLDocumentCreator("http://musicbrainz.org/ws/1/artist/?type=xml&name=" + information[0]); MusicBrainzXMLDocumentRelease[] releases = createXML.ProcessRelease(); if (!releases[0].releaseType.Equals(information[2]) && releases[0].ext_score.Equals("100")) { information[2] = IssueWarning("Release type is not perfect match", information[10]); } else if (!releases[1].releaseType.Equals(information[2])) { information[2] = IssueWarning("Release type is not perfect match", information[10]); }*/ } break; case 3: { if (information[a] == null) goto default; Match match = (Regex.Match(information[3], "(([0-2][0-9][0-9]|V0|V1|V2|APS|APX|V8)+[(]?(VBR)?[)]?)|Lossless")); if (!match.Success) { information[3] = IssueWarning("Bitrate is not perfect match", information[10], null); } } break; case 4: { if (information[a] == null) goto default; int year = 1899; ParseYear: try { year = int.Parse(information[4]); if (year < 1900 || year > DateTime.Today.Year + 1) { information[4] = IssueWarning("Year is unrealistic", information[10], information[4]); if (information[4] == null) { information[14] = "true"; break; } else { goto ParseYear; } } } catch (FormatException) { information[4] = IssueWarning("Year is unrealistic", information[10], information[4]); if (information[4] == null) { information[14] = "true"; break; } else { goto ParseYear; } } } break; case 5: { /*Musicbrainz doesn't have physical formats as far as I'm aware, and * since my means of getting the physical format are String.Contains(...) * it's pointless to do another check. * */ } break; case 6: { /*Bitrates are defined and verified by the birth of the torrent. There's nothing I can do to check if this is correct*/ } break; case 13: { if (information[13].EndsWith("EP EP")) { information[13] = information[13].Remove(information[13].Length - 2, 2); information[13] = information[13].Trim(); } while (information[13].Contains(" ")) { information[13] = information[13].Replace(" ", " "); } if (SettingsHandler.GetUppercaseAllFolderNames()) information[13] = information[13].ToUpper(); else if (SettingsHandler.GetLowercaseAllFolderNames()) information[13] = information[13].ToLower(); try { Match match = Regex.Match(information[13], "[<]|[>]|[/]|[|]|[?]|[*]"); if (match.Success) { information[13] = IssueError("Illegal characters", information[13]); } } catch { } if ((SettingsHandler.GetTorrentSaveFolder() + @"\[CSL] -- Handled Torrents\" + information[11]).Length >= 255) { IssueError("Torrent save location is greater than 255", information[10]); } } break; default: { //Check to see if null values are supposed to be null string switches = SettingsHandler.GetCustomDirectory().ToLower(); switch (a) { case 0: if (switches.Contains("%a")) { information[0] = IssueError("Can't parse artist", information[10]); } break; case 1: if (switches.Contains("%t")) { information[1] = IssueError("Can't parse album", information[10]); } break; case 2: Match match = Regex.Match(switches, "%l|%s|%c|%e|%r|%v|%n|%x|%u|%v|%z"); if (match.Success) { information[2] = IssueError("Can't parse release format", information[10]); } break; case 3: if (switches.Contains("%b")) { information[3] = IssueError("Can't parse bitrate", information[10]); } break; case 4: if (switches.Contains("%y")) { information[4] = IssueError("Can't parse year", information[10]); } break; case 5: if (switches.Contains("%p")) { information[5] = IssueError("Can't parse physical format", information[10]); } break; case 6: if (switches.Contains("%d")) { information[6] = IssueError("Can't parse bit format", information[10]); } break; } } break; } } return new Torrent(information); }