public static ClientInfo Parse(string rawInfo) { string[] sections = rawInfo.Split(' '); if (sections.Length == 2) { string key = sections[0]; string value = sections[1]; double version; if (double.TryParse(value,NumberStyles.Float, CultureInfo.GetCultureInfo("en-GB").NumberFormat, out version)) { var clientInfo = new ClientInfo {Tag = key, Version = version}; switch (clientInfo.Tag) { case "++": clientInfo.Type = ClientType.DCpp; break; case "UC": clientInfo.Type = ClientType.Jucy; break; default: clientInfo.Type = ClientType.Unknown; break; } return clientInfo; } } return null; }
public static MagnetLink CreateMagnetLink(ClientInfo clientInfo, string name, int seasonNumber, int episodeNumber) { // If we have no client type, we cant know if client support this if (clientInfo == null) return null; ClientType clientType = clientInfo.Type; bool clientSupportsMagnet = false; string displayNameFormat = string.Empty; switch (clientType) { case ClientType.DCpp: if (clientInfo.Version > 0.770d) { clientSupportsMagnet = true; } displayNameFormat = "{0} Season {1:00} Episode {2:00}"; break; case ClientType.Jucy: if (clientInfo.Version > 0.85d) { clientSupportsMagnet = true; } displayNameFormat = "Search for next episode"; break; } if (clientSupportsMagnet) { StringBuilder sb = new StringBuilder(name); sb.Replace(":", string.Empty); sb.Replace(",", string.Empty); sb.Replace(".", string.Empty); sb.Replace("-", string.Empty); sb.Replace("_", string.Empty); sb.Replace(";", string.Empty); sb.Replace("'", string.Empty); sb.Replace("´", string.Empty); sb.Replace("<", string.Empty); sb.Replace(">", string.Empty); sb.Replace("|", string.Empty); sb.Replace("*", string.Empty); sb.Replace("(", string.Empty); sb.Replace(")", string.Empty); sb.Replace("[", string.Empty); sb.Replace("]", string.Empty); string convertedName = sb.ToString(); string strThe = "The "; if (convertedName.StartsWith(strThe, StringComparison.InvariantCultureIgnoreCase)) { convertedName = convertedName.Remove(0, strThe.Length); } //HttpServerUtility string displayName = HttpUtility.UrlEncode(string.Format(displayNameFormat, name, seasonNumber, episodeNumber)); string searchText = HttpUtility.UrlEncode(string.Format("{0} s{1:00}e{2:00}", convertedName, seasonNumber, episodeNumber)); return new MagnetLink {Link = string.Format("magnet:?kt={0}&dn={1}", searchText, displayName)}; }else { return null; } }