예제 #1
0
        public virtual bool DownloadNzb(string url, string title, bool recentlyAired)
        {
            try
            {
                title = MediaFileProvider.CleanFilename(title);

                var filename = Path.Combine(_configProvider.BlackholeDirectory, title + ".nzb");

                if (_diskProvider.FileExists(filename))
                {
                    //Return true so a lesser quality is not returned.
                    logger.Info("NZB already exists on disk: {0}", filename);
                    return(true);
                }

                logger.Trace("Downloading NZB from: {0} to: {1}", url, filename);
                _httpProvider.DownloadFile(url, filename);

                logger.Trace("NZB Download succeeded, saved to: {0}", filename);
                return(true);
            }
            catch (Exception ex)
            {
                logger.WarnException("Failed to download NZB: " + url, ex);
                return(false);
            }
        }
예제 #2
0
        public ActionResult Newznab(string name)
        {
            var dir  = Server.MapPath("/Content/Images/Indexers");
            var path = Path.Combine(dir, String.Format("{0}.png", name));

            if (_diskProvider.FileExists(path))
            {
                return(File(path, "image/png"));
            }

            return(File(Path.Combine(dir, "Newznab.png"), "image/png"));
        }
예제 #3
0
        public FileContentResult File()
        {
            string log = string.Empty;

            if (_diskProvider.FileExists(_environmentProvider.GetArchivedLogFileName()))
            {
                log = _diskProvider.ReadAllText(_environmentProvider.GetArchivedLogFileName());
            }

            log += _diskProvider.ReadAllText(_environmentProvider.GetLogFileName());

            return(new FileContentResult(Encoding.ASCII.GetBytes(log), "text/plain"));
        }
예제 #4
0
        public virtual bool Delete(int seriesId)
        {
            var bannerPath     = _environmentProvider.GetBannerPath();
            var bannerFilename = Path.Combine(bannerPath, seriesId.ToString()) + ".jpg";

            try
            {
                logger.Trace("Checking if banner exists: {0}", bannerFilename);

                if (_diskProvider.FileExists(bannerFilename))
                {
                    logger.Trace("Deleting existing banner: {0}", bannerFilename);
                    _diskProvider.DeleteFile(bannerFilename);
                }
            }
            catch (Exception ex)
            {
                logger.WarnException("Failed to delete banner: " + bannerFilename, ex);
                return(false);
            }
            return(true);
        }
        public virtual bool DownloadNzb(string url, string title, bool recentlyAired)
        {
            try
            {
                //Todo: Allow full season releases
                if (Parser.ParseTitle(title).FullSeason)
                {
                    logger.Info("Skipping Full Season Release: {0}", title);
                    return(false);
                }

                title = MediaFileProvider.CleanFilename(title);

                //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC)
                var filename = Path.Combine(_configProvider.PneumaticDirectory, title + ".nzb");

                if (_diskProvider.FileExists(filename))
                {
                    //Return true so a lesser quality is not returned.
                    logger.Info("NZB already exists on disk: {0}", filename);
                    return(true);
                }

                logger.Trace("Downloading NZB from: {0} to: {1}", url, filename);
                _httpProvider.DownloadFile(url, filename);

                logger.Trace("NZB Download succeeded, saved to: {0}", filename);

                var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title);
                _diskProvider.WriteAllText(Path.Combine(_configProvider.DownloadClientTvDirectory, title + ".strm"), contents);

                return(true);
            }
            catch (Exception ex)
            {
                logger.WarnException("Failed to download NZB: " + url, ex);
                return(false);
            }
        }
        public virtual MediaInfoModel GetMediaInfo(string filename)
        {
            if (!_diskProvider.FileExists(filename))
            {
                throw new FileNotFoundException("Media file does not exist: " + filename);
            }

            var mediaInfo = new MediaInfo();

            try
            {
                logger.Trace("Getting media info from {0}", filename);

                mediaInfo.Option("ParseSpeed", "0.2");
                int open = mediaInfo.Open(filename);

                if (open != 0)
                {
                    int width;
                    int height;
                    int videoBitRate;
                    int audioBitRate;
                    int runTime;
                    int streamCount;
                    int audioChannels;

                    string subtitles = mediaInfo.Get(StreamKind.General, 0, "Text_Language_List");
                    string scanType  = mediaInfo.Get(StreamKind.Video, 0, "ScanType");
                    Int32.TryParse(mediaInfo.Get(StreamKind.Video, 0, "Width"), out width);
                    Int32.TryParse(mediaInfo.Get(StreamKind.Video, 0, "Height"), out height);
                    Int32.TryParse(mediaInfo.Get(StreamKind.Video, 0, "BitRate"), out videoBitRate);

                    string aBitRate = mediaInfo.Get(StreamKind.Audio, 0, "BitRate");
                    int    ABindex  = aBitRate.IndexOf(" /");
                    if (ABindex > 0)
                    {
                        aBitRate = aBitRate.Remove(ABindex);
                    }

                    Int32.TryParse(aBitRate, out audioBitRate);
                    Int32.TryParse(mediaInfo.Get(StreamKind.General, 0, "PlayTime"), out runTime);
                    Int32.TryParse(mediaInfo.Get(StreamKind.Audio, 0, "StreamCount"), out streamCount);

                    string audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)");
                    int    ACindex          = audioChannelsStr.IndexOf(" /");
                    if (ACindex > 0)
                    {
                        audioChannelsStr = audioChannelsStr.Remove(ACindex);
                    }

                    string  audioLanguages = mediaInfo.Get(StreamKind.General, 0, "Audio_Language_List");
                    decimal videoFrameRate = Decimal.Parse(mediaInfo.Get(StreamKind.Video, 0, "FrameRate"));
                    string  audioProfile   = mediaInfo.Get(StreamKind.Audio, 0, "Format_Profile");

                    int APindex = audioProfile.IndexOf(" /");
                    if (APindex > 0)
                    {
                        audioProfile = audioProfile.Remove(APindex);
                    }

                    Int32.TryParse(audioChannelsStr, out audioChannels);
                    var mediaInfoModel = new MediaInfoModel
                    {
                        VideoCodec       = mediaInfo.Get(StreamKind.Video, 0, "Codec/String"),
                        VideoBitrate     = videoBitRate,
                        Height           = height,
                        Width            = width,
                        AudioFormat      = mediaInfo.Get(StreamKind.Audio, 0, "Format"),
                        AudioBitrate     = audioBitRate,
                        RunTime          = (runTime / 1000),                    //InSeconds
                        AudioStreamCount = streamCount,
                        AudioChannels    = audioChannels,
                        AudioProfile     = audioProfile.Trim(),
                        VideoFps         = videoFrameRate,
                        AudioLanguages   = audioLanguages,
                        Subtitles        = subtitles,
                        ScanType         = scanType
                    };

                    mediaInfo.Close();
                    return(mediaInfoModel);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Unable to parse media info from file: " + filename, ex);
                mediaInfo.Close();
            }

            return(null);
        }
예제 #7
0
        public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false)
        {
            if (episodeFile == null)
            {
                throw new ArgumentNullException("episodeFile");
            }

            var    series      = _seriesProvider.GetSeries(episodeFile.SeriesId);
            var    episodes    = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId);
            string newFileName = _mediaFileProvider.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile);
            var    newFile     = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));

            //Only rename if existing and new filenames don't match
            if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName))
            {
                Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path);
                return(null);
            }

            if (!_diskProvider.FileExists(episodeFile.Path))
            {
                Logger.Error("Episode file path does not exist, {0}", episodeFile.Path);
                return(null);
            }

            _diskProvider.CreateDirectory(newFile.DirectoryName);

            Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName);
            _diskProvider.MoveFile(episodeFile.Path, newFile.FullName);

            //Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important.
            try
            {
                _diskProvider.InheritFolderPermissions(newFile.FullName);
            }
            catch (UnauthorizedAccessException ex)
            {
                Logger.Debug("Unable to apply folder permissions to: ", newFile.FullName);
                Logger.TraceException(ex.Message, ex);
            }

            episodeFile.Path = newFile.FullName;
            _mediaFileProvider.Update(episodeFile);

            var parseResult = Parser.ParsePath(episodeFile.Path);

            parseResult.Series  = series;
            parseResult.Quality = new QualityModel {
                Quality = episodeFile.Quality, Proper = episodeFile.Proper
            };
            parseResult.Episodes = episodes;

            var message = _downloadProvider.GetDownloadTitle(parseResult);

            if (newDownload)
            {
                _externalNotificationProvider.OnDownload(message, series);

                foreach (var episode in episodes)
                {
                    _signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Ready, parseResult.Quality);
                }
            }
            else
            {
                _externalNotificationProvider.OnRename(message, series);
            }

            return(episodeFile);
        }