Example #1
0
        internal Torrent(TorrentServer torrentServer, string hash, string name)
        {
            if (torrentServer == null) throw new ArgumentNullException(nameof(torrentServer));
            if (hash == null) throw new ArgumentNullException(nameof(hash));
            if (name == null) throw new ArgumentNullException(nameof(name));


            _server = torrentServer;
            Hash = hash;
            Name = name;
        }
Example #2
0
        public void Run(TorrentServer server)
        {
            string torrentUrl;
            if (_useMagnet)
            {
                torrentUrl = $"magnet:?xt=urn:btih:{_hash}&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%2Fannounce";
            }
            else
            {
                torrentUrl = $"http://torcache.net/torrent/{_hash}.torrent";
            }

            Trace.TraceInformation($"Adding Torrent: {_hash}");
            server.ExecuteAction($"add-url&s={torrentUrl}");
        }
Example #3
0
        public void Run(TorrentServer server)
        {
            Program.EnsureShell();

            var torrents = server.GetAllTorrents();

            switch (_executionLevel)
            {
                case Execution.Private:
                    torrents = torrents.Where(x => x.Private);
                    break;

                case Execution.Public:
                    torrents = torrents.Where(x => !x.Private);
                    break;
            }

            WriteLine("");

            if (!torrents.Any())
            {
                WriteLine("No relevant torrents found...");
                return;
            }
            
            var longestName = torrents.Max(x => x.Name.Length);
            var hashLength = torrents.Max(x => x.Hash.Length);

            var alignment = " | {0,-" + longestName + "}";


            WriteLine(" ♦");
            WriteLine(" | Listing torrents...");

            var line = " ♦" + new string('-', longestName + hashLength + 5) + "♦";
            WriteLine(line);

            foreach (var torrent in torrents)
            {
                Write(string.Format(alignment, torrent.Name));
                Write(" : ");                
                Write(torrent.Hash);
                WriteLine(" |");
            }

            WriteLine(line);
        }
Example #4
0
        internal Torrent(TorrentServer torrentServer, string hash)
            : this(torrentServer, hash, hash)
        {

        }
Example #5
0
        /*
        -host [VALUE]
        -user [VALUE]
        -password [VALUE]

        -hash [VALUE] (Can be used multiple times when using the same command on several hashes)
        
        -noTokenAuth
        -debug (appends tracing to debug.log)
        -ui (shows UI, will attach to parent if already in a console)
        -list
        -listprivate
        -listpublic


        -start[_ifprivate|_ifpublic]
        -stop[_ifprivate|_ifpublic]
        -forcestart[_ifprivate|_ifpublic]
        -unpause[_ifprivate|_ifpublic]
        -pause[_ifprivate|_ifpublic]
        -recheck[_ifprivate|_ifpublic]
        -remove[_ifprivate|_ifpublic]
        -removeData[_ifprivate|_ifpublic]
        -label[_ifprivate|_ifpublic] [VALUE]
        -removeLabel[_ifprivate|_ifpublic]
        -setPrio[_ifprivate|_ifpublic] [VALUE]
        -setProperty[_ifprivate|_ifpublic] [NAME] [VALUE]

        -save [NAME] [VALUE] [NAME2] [VALUE2] .... [NAME_N] [VALUE_N] (currently used: user, password and host)

        -add [HASH](uses magnet)
        -addResolved [HASH] (uses torcache)
        */
        public Governor(string[] args)
        {
            bool useToken = true;
            Uri host = null;
            string user = null;
            SecureString password = null;
            var actions = new List<Command>();
            var hashes = new List<string>();

            var serverCommands = new List<IServerCommand>();

            for (int i = 0; i < args.Length; i++)
            {
                var name = args[i];

                if (!name.StartsWith("-", StringComparison.Ordinal)) continue; //not considered a command

                name = name.Substring(1).Trim().ToUpperInvariant();
                
                switch (name)
                {
                    case "HOST":
                        host = new Uri(args[++i]);
                        break;
                    case "USER":
                        user = args[++i];
                        break;

                    case "PASSWORD":
                        password = args[++i].ToSecureString();
                        break;

                    case "HASH":
                        hashes.Add(args[++i]);
                        break;

                    case "NOTOKENAUTH":
                        useToken = false;
                        break;

                    case "ADD":
                        serverCommands.Add(new AddCommand(args[++i], true));
                        break;

                    case "ADDRESOLVED":
                        serverCommands.Add(new AddCommand(args[++i], false));
                        break;

                    case "DEBUG":
                        var writerListener = new TextWriterTraceListener(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "debug.log"));
                        writerListener.TraceOutputOptions |= TraceOptions.DateTime;
                        Trace.AutoFlush = true; //Otherwise nothing will be written to the file.
                        Trace.Listeners.Add(writerListener);
                        break;

                    case "LIST":
                        serverCommands.Add(new ListCommand(Execution.Always));
                        break;

                    case "LISTPRIVATE":
                        serverCommands.Add(new ListCommand(Execution.Private));
                        break;

                    case "LISTPUBLIC":
                        serverCommands.Add(new ListCommand(Execution.Public));
                        break;

                    case "UI":
                        //Ignore
                        break;


                    default:
                        actions.Add(Command.Build(name, ref i, args));
                        break;
                }
            }
            
            if (user == null || password == null || host == null)
            {
                var settings = new SettingsManger();

                if (user == null) user = settings.Get("USER");
                if (password == null) password = settings.GetSecure("PASSWORD");
                if (host == null) host = settings.GetUri("HOST");
            }

            Server = new TorrentServer(host, user, password, useToken);
            ServerCommands = serverCommands;
            Actions = actions;
            Hashes = hashes;
        }