Exemplo n.º 1
0
        public static Torrent Parse(string strFormat)
        {
            Torrent torrent = new Torrent();

            try
            {
                string          info  = Regex.Match(strFormat, @"\d+(@.+?:[\d,]+)+sun").Value;
                MatchCollection mc    = Regex.Matches(info, @"@(.*?):([\d,]+)");
                string          value = strFormat.Replace(info, "");
                int             start = 0;
                foreach (Match match in mc)
                {
                    switch (match.Groups[1].Value)
                    {
                    case "trackerUrl":
                        int lenght = int.Parse(match.Groups[2].Value);
                        torrent.trackerUrl = value.Substring(start, lenght);
                        start += lenght;
                        break;

                    case "createdBy":
                        lenght            = int.Parse(match.Groups[2].Value);
                        torrent.createdBy = value.Substring(start, lenght);
                        start            += lenght;
                        break;

                    case "filesInfo":
                        string[]           lenghts     = match.Groups[2].Value.Split(',');
                        int                lenght1     = int.Parse(lenghts[0]);
                        int                lenght2     = int.Parse(lenghts[1]);
                        TorrentIncludeFile includeFile = new TorrentIncludeFile();
                        includeFile.FileName = value.Substring(start, lenght1);
                        start += lenght1;
                        includeFile.FileLenght = int.Parse(value.Substring(start, lenght2));
                        start += lenght2;
                        torrent.filesInfo.Add(includeFile);
                        break;
                    }
                }
            }
            catch
            {
                return(new Torrent());
            }
            return(torrent);
        }
Exemplo n.º 2
0
 public static Torrent Parse(string strFormat)
 {
     Torrent torrent = new Torrent();
     try
     {
         string info = Regex.Match(strFormat, @"\d+(@.+?:[\d,]+)+sun").Value;
         MatchCollection mc = Regex.Matches(info, @"@(.*?):([\d,]+)");
         string value = strFormat.Replace(info, "");
         int start = 0;
         foreach (Match match in mc)
         {
             switch (match.Groups[1].Value)
             {
                 case "trackerUrl":
                     int lenght = int.Parse(match.Groups[2].Value);
                     torrent.trackerUrl = value.Substring(start, lenght);
                     start += lenght;
                     break;
                 case "createdBy":
                     lenght = int.Parse(match.Groups[2].Value);
                     torrent.createdBy = value.Substring(start, lenght);
                     start += lenght;
                     break;
                 case "filesInfo":
                     string[] lenghts = match.Groups[2].Value.Split(',');
                     int lenght1 = int.Parse(lenghts[0]);
                     int lenght2 = int.Parse(lenghts[1]);
                     TorrentIncludeFile includeFile = new TorrentIncludeFile();
                     includeFile.FileName = value.Substring(start, lenght1);
                     start += lenght1;
                     includeFile.FileLenght = int.Parse(value.Substring(start, lenght2));
                     start += lenght2;
                     torrent.filesInfo.Add(includeFile);
                     break;
             }
         }
     }
     catch
     {
         return new Torrent();
     }
     return torrent;
 }
Exemplo n.º 3
0
        static Torrent ConvertToEntity(string analyzerString)
        {
            Torrent torrent = new Torrent();
            torrent.TrackerUrl = Regex.Match(analyzerString, "\"announce\"\"(.*?)\"").Groups[1].Value;
            torrent.CreateBy = Regex.Match(analyzerString, "\"created by\"\"(.*?)\"").Groups[1].Value;

            foreach (Match m in Regex.Matches(analyzerString, "\"length\"\"(.*?)\".*?\"path.utf-8\"[[{]*\"(.*?)\""))
            {
                TorrentIncludeFile fileInfo = new TorrentIncludeFile();
                fileInfo.FileLenght = Convert.ToInt32(m.Groups[1].Value);
                fileInfo.FileName = m.Groups[2].Value;
                torrent.FilesInfo.Add(fileInfo);
            }
            return torrent;
        }