Ejemplo n.º 1
0
        public bool Run(string name, NzbModel nzb)
        {
            //result should be output from the script...
            var scriptDir = Path.GetFullPath(_config.GetValue("ScriptDir", AllScripts(), true));

            var scriptPath = Path.GetFullPath(scriptDir + Path.DirectorySeparatorChar + name);

            if (!_disk.FileExists(scriptPath))
            {
                Logger.Error("Script does not exist.");
                return(false);
            }

            //1     The final directory of the job (full path)
            //2     The original name of the NZB file
            //3     Clean version of the job name (no path info and ".nzb" removed)
            //4     Indexer's report number (if supported) - Don't have this information right now....
            //5     User-defined category
            //6     Group that the NZB was posted in e.g. alt.binaries.x
            //7     Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+21

            var arguments = String.Format("{0} {1} {2} {3} {4} {5} {6}", GetStringForArgument(nzb.FinalDirectory), GetStringForArgument(nzb.Name), GetStringForArgument(nzb.Name), String.Empty, nzb.Category, nzb.Files[0].Groups[0], (int)nzb.PostProcessingStatus);

            var process = new Process();

            process.StartInfo.UseShellExecute        = false; //Must be false to redirect the output
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.FileName  = scriptPath;
            process.StartInfo.Arguments = arguments;
            process.Start();                                       //Start the Process
            process.WaitForExit();                                 //Wait for the Process to Exit

            nzb.ScriptOutput = process.StandardOutput.ReadToEnd(); //Save the output of the script to ScriptOutput (For later use in History)

            if (process.ExitCode != 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool Send(NzbModel nzb)
        {
            //Get the Template
            //Get SMTP Server Information, To/From Address, etc

            var  toAddress      = _config.GetValue("EmailToAddress", String.Empty, false);
            var  fromAddress    = _config.GetValue("EmailFromAddress", String.Empty, false);
            var  host           = _config.GetValue("SmtpServerHost", String.Empty, false);
            int  port           = Convert.ToInt32(_config.GetValue("SmtpServerPort", "25", true));
            bool ssl            = Convert.ToBoolean(_config.GetValue("SmtpServerSsl", "0", true));
            bool authentication = Convert.ToBoolean(_config.GetValue("SmtpServerAthentication", "0", true));
            var  username       = _config.GetValue("SmtpServerUsername", String.Empty, false);
            var  password       = _config.GetValue("SmtpServerPassword", String.Empty, false);

            MailMessage email = new MailMessage(); //Create a new MailMessage named email

            email.To.Add(toAddress);
            email.From = new MailAddress(fromAddress); //Create a new MailAddress for the senders address;

            //Todo: Need to Build these from a template
            email.Subject = String.Empty;         //Set the subject of the email
            email.Body    = String.Empty;         //set the body of the email

            SmtpClient client = new SmtpClient(); //Create a new SMTP client

            client.Host = host;                   //Set the host for the client
            client.Port = port;                   //Set the port for the client

            try
            {
                client.Send(email); //Try to send the message
            }

            catch (Exception ex)
            {
                Logger.DebugException(ex.Message, ex);
                return(false);
            }

            //return true;
            throw new NotImplementedException("Email Provider - Send");
        }
Ejemplo n.º 3
0
 public bool Insert(NzbModel nzb, int index)
 {
     _list.Insert(index, nzb);
     return(true);
 }
Ejemplo n.º 4
0
 public bool Add(NzbModel nzb)
 {
     _list.Add(nzb);
     return(true);
 }
Ejemplo n.º 5
0
        public NzbModel Process(NzbImportModel import)
        {
            XNamespace ns = "http://www.newzbin.com/DTD/2003/nzb";

            import.Stream.Seek(0, SeekOrigin.Begin);
            XDocument xDoc = XDocument.Load(import.Stream);

            var nzb = from n in xDoc.Descendants(ns + "nzb") select n;

            if (nzb.Count() != 1)
            {
                return(null);
            }

            NzbModel newNzb = new NzbModel();

            newNzb.Name           = !String.IsNullOrEmpty(import.NewName) ? import.NewName : import.Name;
            newNzb.Id             = Guid.NewGuid();
            newNzb.Status         = NzbStatus.Queued;
            newNzb.Priority       = (Priority)import.Priority;
            newNzb.Script         = import.Script;
            newNzb.Category       = import.Category;
            newNzb.PostProcessing = GetPostProcessing(import);

            var nzbFileList = new List <NzbFileModel>();

            //Get all the files for this NZB
            var files = from f in nzb.Elements(ns + "file") select f;

            foreach (var file in files)
            {
                var nzbFile = new NzbFileModel();
                nzbFile.Status = NzbFileStatus.Queued;
                nzbFile.NzbId  = newNzb.Id;
                var segmentList = new List <NzbSegmentModel>();

                //Get the Age of the File and Convert to DateTime
                var date = Convert.ToInt64((from d in file.Attributes("date") select d.Value).FirstOrDefault());
                nzbFile.DatePosted = TicksToDateTime(date);

                //Get the Subject and set the NzbFile's Filename
                var subject       = (from s in file.Attributes("subject") select s).FirstOrDefault();
                int fileNameStart = subject.Value.IndexOf("\"") + 1;
                int fileNameEnd   = subject.Value.LastIndexOf("\"") - fileNameStart;
                nzbFile.Filename = subject.Value.Substring(fileNameStart, fileNameEnd);

                //Get the groups for the NzbFile
                nzbFile.Groups = (from g in file.Descendants(ns + "group") select g.Value).ToList();

                //Get the Segments for this file
                var segments = from s in file.Descendants(ns + "segment") select s;
                foreach (var segment in segments)
                {
                    var nzbFileSegment = new NzbSegmentModel();
                    nzbFileSegment.Status      = NzbSegmentStatus.Queued;
                    nzbFileSegment.NzbFileName = nzbFile.Name;
                    nzbFileSegment.Number      = Convert.ToInt32((from n in segment.Attributes("number") select n.Value).FirstOrDefault());
                    nzbFileSegment.Size        = Convert.ToInt64((from n in segment.Attributes("bytes") select n.Value).FirstOrDefault());
                    nzbFileSegment.SegmentId   = segment.Value;
                    segmentList.Add(nzbFileSegment);
                }
                nzbFile.Segments = segmentList;
                nzbFileList.Add(nzbFile);
            }
            newNzb.Files = nzbFileList;
            return(newNzb);
        }
Ejemplo n.º 6
0
        public bool Run(NzbModel nzb)
        {
            //Run The Pre-Queue Script

            var script    = _config.GetValue("PreQueueScript", String.Empty, false);
            var scriptDir = _config.GetValue("ScriptDir", "scripts", true);

            //CHeck if the script dir contains / or \ if not it is a relevant path

            var scriptPath = scriptDir + Path.DirectorySeparatorChar + script;

            //If the script isn't on disk, then return true (Better to Accept than reject)
            if (!_disk.FileExists(scriptPath))
            {
                return(true);
            }

            //1 : Name of the NZB (no path, no ".nzb")
            //2 : PP (0, 1, 2 or 3)
            //3 : Category
            //4 : Script (no path)
            //5 : Priority (-100, -1, 0 or 1 meaning Default, Low, Normal, High)
            //6 : Size of the download (in bytes)
            //7 : Group list (separated by spaces)
            //8 : Show name
            //9 : Season (1..99)
            //10 : Episode (1..99)
            //11: Episode name

            string groups = String.Join(" ", nzb.Files[0].Groups.ToArray());

            var arguments = String.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", GetStringForArgument(nzb.Name), nzb.PostProcessing, nzb.Category, nzb.Script, nzb.Priority, nzb.Size,
                                          groups, nzb.ShowName, nzb.SeasonNumber, nzb.EpisodeNumber, nzb.EpisodeName);

            var process = new Process();

            process.StartInfo.UseShellExecute        = false; //Must be false to redirect the output
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.FileName  = scriptPath;
            process.StartInfo.Arguments = arguments;
            process.Start();       //Start the Process
            process.WaitForExit(); //Wait for the Process to Exit

            int    lineNumber = 0;
            string line;

            while ((line = process.StandardOutput.ReadLine()) != null)
            {
                if (lineNumber == 0)
                {
                    if (!Convert.ToBoolean(line))
                    {
                        return(false);                          //If set to Refuse then return false
                    }
                }

                if (lineNumber == 1)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        nzb.Name = line;
                    }
                }

                if (lineNumber == 2)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        nzb.PostProcessing = (PostProcessing)Convert.ToInt32(line);
                    }
                }

                if (lineNumber == 3)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        nzb.Category = line;
                    }
                }

                if (lineNumber == 4)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        nzb.Script = line;
                    }
                }

                if (lineNumber == 5)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        nzb.Priority = (Priority)Convert.ToInt32(line);
                    }
                }

                if (lineNumber == 6)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        //Set each File for this NZB to have the group set to line
                        foreach (var file in nzb.Files)
                        {
                            file.Groups.Clear();
                            file.Groups.Add(line);
                        }
                    }
                }

                if (lineNumber > 6)
                {
                    break;
                }

                lineNumber++;
            }
            return(true);
        }