Exemple #1
0
        private static void Main()
        {
            Console.WriteLine($"Using settings from {Path.GetFullPath(ConfigurationManager.CONFIG_PATH)}: \n{JsonConvert.SerializeObject(ConfigurationManager.Settings, Formatting.Indented)}");
            var client = new DelugeClient(ConfigurationManager.Settings.LocalDelugeUri);

            client.Login(ConfigurationManager.Settings.LocalDelugePassword);

            var torrents = client.GetTorrents();

            var torrentsRequiringFix = torrents.Where(torrent => torrent.Trackers.Any(t => t.Url != ConfigurationManager.Settings.PrivateTracker)).ToList();

            UploadToSeedbox(torrentsRequiringFix);

            FixTorrentLocally(torrentsRequiringFix, client);

            Console.WriteLine("Finished");
        }
Exemple #2
0
        private static void UploadToSeedbox(IReadOnlyCollection <Torrent> torrents)
        {
            if (!torrents.Any())
            {
                return;
            }

            Console.WriteLine("Uploading " + torrents.Count + " torrents to seedbox.");

            var client = new DelugeClient(ConfigurationManager.Settings.RemoteDelugeUri);

            client.Login(ConfigurationManager.Settings.RemoteDelugePassword);

            foreach (var torrent in torrents)
            {
                var magnetURI = GetMagnetURI(torrent);

                Console.Write("Uploading {0} ...", torrent.Name);
                client.AddMagnetURI(magnetURI);

                var trackersToSet = ConfigurationManager.Settings.AppendRemoteTracker
                            ? torrent.Trackers.Union(new[]
                {
                    new Tracker
                    {
                        Tier = torrent.Trackers.Max(t => t.Tier) + 1,
                        Url  = ConfigurationManager.Settings.PrivateTracker
                    }
                })
                            : torrent.Trackers;

                Console.WriteLine(" fixing trackers...");

                client.SetTrackers(torrent.Hash, trackersToSet.ToArray());

                Console.WriteLine(" done.");
            }
        }
Exemple #3
0
        private static void FixTorrentLocally(IEnumerable <Torrent> torrentsRequiringFix, DelugeClient client)
        {
            if (!ConfigurationManager.Settings.StripLocalTrackers)
            {
                return;
            }

            foreach (var torrent in torrentsRequiringFix)
            {
                Console.Write("Fixing {0} locally...", torrent.Name);
                client.SetTrackers(torrent.Hash, new Tracker {
                    Tier = 0, Url = ConfigurationManager.Settings.PrivateTracker
                });
                Console.WriteLine(" done.");
            }
        }
        public void event_btnMTDoUpload_Activated(object sender, EventArgs e)
        {
            string procName = "event_btnMTDoUpload_Activated";

            CookieContainer container = new CookieContainer();
            WebClientEx     client    = new WebClientEx(container);

            try
            {
                addQueueLog(DateTime.Now, "[UPLOAD] Starting upload...");

                if (string.IsNullOrEmpty(txtMTUserName.StringValue) || string.IsNullOrEmpty(txtMTPassword.StringValue))
                {
                    addQueueLog(DateTime.Now, "[UPLOAD] !! ERROR !! Please provide MT credentials.");
                    return;
                }

                addQueueLog(DateTime.Now, "[UPLOAD] Connecting and authenticating...");

                var values = new NameValueCollection {
                    { "username", txtMTUserName.StringValue },
                    { "password", txtMTPassword.StringValue },
                    { "login", "Log in" }
                };

                // Authenticate
                client.UploadValues("https://mac-torrents.me/login.php", values);

                string tempResponse = client.DownloadString("https://mac-torrents.me/upload.php");

                string searchFor      = "<input type=\"hidden\" name=\"auth\" value=\"";
                int    indexSearchFor = tempResponse.IndexOf(searchFor) + searchFor.Length;
                string authString     = tempResponse.Substring(indexSearchFor, 32);

                if (_uploadQueue != null)
                {
                    foreach (Queue.QueueDetail qd in _uploadQueue.queueList)
                    {
                        addQueueLog(DateTime.Now, string.Format("[UPLOAD] Uploading {0}...", qd.appTitle));

                        if (System.IO.File.Exists(qd.torrentFile))
                        {
                            FileInfo fInfo    = new FileInfo(qd.torrentFile);
                            long     numBytes = fInfo.Length;

                            FileStream   fStream = new FileStream(qd.torrentFile, FileMode.Open, FileAccess.Read);
                            BinaryReader br      = new BinaryReader(fStream);

                            FormUpload.FileParameter fp = new FormUpload.FileParameter(br.ReadBytes((int)numBytes),
                                                                                       Path.GetFileName(qd.torrentFile),
                                                                                       "application/octet-stream");

                            br.Close();
                            fStream.Close();

                            string releaseType = string.Empty;
                            if (qd.appType == "App")
                            {
                                releaseType = "1";
                            }
                            if (qd.appType == "Game")
                            {
                                releaseType = "2";
                            }
                            if (qd.appType == "Other")
                            {
                                releaseType = "5";
                            }
                            if (qd.appType == "E-Books")
                            {
                                releaseType = "6";
                            }

                            // Upload torrent
                            Dictionary <string, object> paramsDic = new Dictionary <string, object> ();
                            paramsDic.Add("submit", "true");
                            paramsDic.Add("auth", authString);
                            paramsDic.Add("type", releaseType);
                            paramsDic.Add("title", qd.appTitle);
                            paramsDic.Add("tags", qd.appTags);
                            paramsDic.Add("image", qd.appImage);
                            paramsDic.Add("desc", qd.appDescrip);
                            paramsDic.Add("file_input", fp);

                            if (qd.appVer == "10.6")
                            {
                                paramsDic.Add("macos[]", new string[] { "1", "2", "3", "4", "5" });
                            }
                            if (qd.appVer == "10.7")
                            {
                                paramsDic.Add("macos[]", new string[] { "2", "3", "4", "5" });
                            }
                            if (qd.appVer == "10.8")
                            {
                                paramsDic.Add("macos[]", new string[] { "3", "4", "5" });
                            }
                            if (qd.appVer == "10.9")
                            {
                                paramsDic.Add("macos[]", new string[] { "4", "5" });
                            }
                            if (qd.appVer == "10.10")
                            {
                                paramsDic.Add("macos[]", "5");
                            }

                            //Upload torrent
                            HttpWebResponse resp = FormUpload.MultipartFormDataPost(
                                "https://mac-torrents.me/upload.php",
                                "MTUploaderHelper2.NET",
                                paramsDic,
                                container);

                            string localFile = Path.GetDirectoryName(qd.torrentFile) + @"/" + Path.GetFileNameWithoutExtension(qd.torrentFile) + "_mt.torrent";

                            //from https://mac-torrents.me/torrents.php?id=1886
                            // to  https://mac-torrents.me/torrents.php?action=download&id=1887

                            int    numIndex = resp.ResponseUri.AbsoluteUri.IndexOf("=");
                            string strNum   = resp.ResponseUri.AbsoluteUri.Substring(numIndex + 1);
                            int    dlId;

                            int.TryParse(strNum, out dlId);
                            dlId += 1;
                            string remoteFile = string.Format("https://mac-torrents.me/torrents.php?action=download&id={0}", dlId);

                            addQueueLog(DateTime.Now, string.Format("[UPLOAD] Downloading torrent file {0}...", localFile));

                            client.DownloadFile(remoteFile, localFile);

                            if (cmbDelugeServer.StringValue.Length != 0 &&
                                txtPathOnServer.StringValue.Length != 0)
                            {
                                addQueueLog(DateTime.Now, string.Format("[DELUGE] Adding torrent {0}...", localFile));

                                string host = string.Empty, port = string.Empty, password = string.Empty;

                                switch (cmbDelugeServer.StringValue)
                                {
                                case "Pasta":
                                    host     = @"http://pasta.whatbox.ca";
                                    port     = "52114";
                                    password = "******";
                                    break;

                                case "Peanut":
                                    host     = @"http://peanut.whatbox.ca";
                                    port     = "39092";
                                    password = "******";
                                    break;
                                }

                                var dclient = new DelugeClient(host, int.Parse(port));
                                dclient.Login(password);
                                dclient.AddTorrentFile(localFile, txtPathOnServer.StringValue);
                            }

                            qd.uploadDone = true;

                            var tv = lstQueue.DocumentView as NSTableView;
                            var ds = tv.DataSource as QueueDataSource;
                            ds.queueList = _uploadQueue.queueList;
                            tv.ReloadData();

                            NSRunLoop.Current.RunUntil(DateTime.Now.AddMilliseconds(10000));
                        }
                        else
                        {
                            addQueueLog(DateTime.Now, string.Format("[UPLOAD] !! ERROR !! {0} not found, skipping.", qd.torrentFile));
                        }
                    }
                }

                addQueueLog(DateTime.Now, "[UPLOAD] Logging out...");
                //client.DownloadString ("https://mac-torrents.me/logout.php?auth=" + authString);
            } catch (Exception ex) {
                Console.WriteLine(string.Format("ERROR: [{0}]: {1}", procName, ex.Message));
            } finally {
                client.Dispose();
                client = null;

                saveQueue();

                addQueueLog(DateTime.Now, "[UPLOAD] Done.");
            }
        }