Example #1
0
        private ImportStatus AddUrl(NzbImportModel import)
        {
            //Determine if the file is a RAW NZB (or is zipped, gzipped, rarred) and then Import
            _http.DownloadAsStream(import);

            if (import.Stream == null)
            {
                import.RetryCount++;
                import.WaitUntil = DateTime.Now.AddMinutes(1);

                return(ImportStatus.Failed);
            }

            var nzb = _parse.Process(import);

            if (nzb == null) //If its null return
            {
                return(ImportStatus.Invalid);
            }

            //Run PreQueue if one is set
            if (!String.IsNullOrEmpty(_config.GetValue("PreQueueScript", String.Empty, false)))
            {
                if (!_preQueue.Run(nzb))
                {
                    return(ImportStatus.Rejected);                     //Return rejected status if NZB is not wanted due to PreQueue
                }
            }

            var position = _queue.AllItems().Count(q => (int)q.Priority >= (int)import.Priority); //Find all items with a higher or equal priority and insert it at that point (zero-indexed list mataches perfectly)

            _queue.Insert(nzb, position);                                                         //Do the insert!
            _nntp.Connect();                                                                      //Start Downloading if not already doing so

            return(ImportStatus.Ok);
        }