public static void GetTorrentMetadataUsingStream()
            {
                try
                {
                    using (Stream stream = File.Open(Common.MapSourceFilePath(filePath), FileMode.Open, FileAccess.ReadWrite))
                    {
                        using (TorrentFormat format = new TorrentFormat(stream))
                        {
                            TorrentMetadata info = format.TorrentInfo;
                            Console.WriteLine(info.Announce);
                            Console.WriteLine(info.CreatedBy);
                            Console.WriteLine(info.CreationDate);
                            Console.WriteLine(info.Comment);
                            Console.WriteLine(info.PieceLength);
                            Console.WriteLine(info.Pieces.Length);

                            foreach (TorrentFileInfo file in info.SharedFiles)
                            {
                                Console.WriteLine(file.Name);
                                Console.WriteLine(file.Length);
                            }
                        }
                        // The stream is still open here
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            /// <summary>
            /// Read BitTorrent File Metadata
            /// Feature is supported in version 18.4 or greater of the API
            /// </summary>
            public static void GetTorrentMetadata()
            {
                try
                {
                    using (TorrentFormat torrentFormat = new TorrentFormat(Common.MapDestinationFilePath(filePath)))
                    {
                        TorrentMetadata info = torrentFormat.TorrentInfo;
                        Console.WriteLine(info.Announce);
                        Console.WriteLine(info.CreatedBy);
                        Console.WriteLine(info.CreationDate);
                        Console.WriteLine(info.Comment);
                        Console.WriteLine(info.PieceLength);
                        Console.WriteLine(info.Pieces.Length);

                        foreach (TorrentFileInfo file in info.SharedFiles)
                        {
                            Console.WriteLine(file.Name);
                            Console.WriteLine(file.Length);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
Exemplo n.º 3
0
        private void OnStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.OldState == TorrentState.Metadata && e.NewState != TorrentState.Error)
            {
                MetadataLoaded.Invoke(sender, e);
            }
            switch (e.NewState)
            {
            case TorrentState.Error:
                TorrentError.Invoke(sender, e);
                break;

            case TorrentState.Stopped:
                TorrentStopped.Invoke(sender, e);
                break;

            case TorrentState.Paused:
                TorrentPaused.Invoke(sender, e);
                break;

            case TorrentState.Starting:
                TorrentStarting.Invoke(sender, e);
                break;

            case TorrentState.Downloading:
                TorrentDownloading.Invoke(sender, e);
                break;

            case TorrentState.Seeding:
                TorrentSeeding.Invoke(sender, e);
                break;

            case TorrentState.Hashing:
                TorrentHashing.Invoke(sender, e);
                break;

            case TorrentState.HashingPaused:
                TorrentHashingPaused.Invoke(sender, e);
                break;

            case TorrentState.Stopping:
                TorrentStopping.Invoke(sender, e);
                break;

            case TorrentState.Metadata:
                TorrentMetadata.Invoke(sender, e);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 4
0
        static async Task MainAsync()
        {
            TorrentMetadata meta = null;

            using (var stream = File.OpenRead("soldier.torrent"))
            {
                meta = stream.ReadTorrentFile();
            }

            using (var fl = File.OpenRead(meta.Files.First().Key))
            {
                var result = await fl.ValidateFileAsync(meta);
            }

            System.Console.ReadLine();
        }
            /// <summary>
            /// Update Bit Torrent File Metadata
            /// Feature is supported in version 18.4 or greater of the API
            /// </summary>
            public static void UpdateTorrentMedata()
            {
                try
                {
                    using (TorrentFormat torrentFormat = new TorrentFormat(Common.MapSourceFilePath(filePath)))
                    {
                        TorrentMetadata info = torrentFormat.TorrentInfo;

                        info.Comment      = "test comment";
                        info.CreatedBy    = "test application";
                        info.CreationDate = DateTime.Now;

                        torrentFormat.Save(Common.MapDestinationFilePath(filePath));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }