Beispiel #1
0
        /// <summary>
        /// This event should trigger when a new episode is downloaded via 
        /// a bittorrent client. Move the completed video file to its appropriate
        /// show directory
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFileSystemWatcher_Created(object sender, FileSystemEventArgs e)
        {
            FileNameParser fileNameParser = new FileNameParser();
            fileNameParser.Parse(e.Name);
            if (fileNameParser.Matched() == false)
            {
                _logger.Info("Cannot parse the following downloaded file: " + e.Name);
                return;
            }

            Series series = Helper.GetSeries(_configuration, fileNameParser.SeriesName);
            if (series == null)
            {
                _logger.Info("Cannot locate series for the following downloaded file: " + e.Name);
                return;
            }

            Episode episode = Helper.GetEpisode(_configuration, series.Id, fileNameParser.SeasonNumber, fileNameParser.EpisodeNumber);
            if (episode == null)
            {
                _logger.Info("Cannot locate episode for the following downloaded file: " + e.Name);
                return;
            }

            if (episode.FileName.Length > 0)
            {
                if (episode.Quality > fileNameParser.Quality)
                {
                    _logger.Info("Downloaded episode quality is less than current: (Current: " + episode.Quality + "#Downloaded: " + fileNameParser.Quality + "): " + e.Name);
                    Misc.MoveFile(e.FullPath, Path.Combine(_settings.DefaultDirectory, e.Name));
                    return;
                }
            }
            string ret = string.Empty;
            if (_settings.SeparateSeasonFolders == false)
            {
                ret = Misc.MoveFile(e.FullPath, Path.Combine(series.Path, e.Name));
            }
            else
            {
                string dir = Path.Combine(series.Path,
                                          string.Format(_settings.SeasonFolderFormat, episode.SeasonNumber));

                if (Directory.Exists(dir) == false)
                {
                    ret = Misc.CreateDirectory(dir);
                    if (ret.Length > 0)
                    {
                        _logger.Error("Unable to create series directory (" + dir + "): " + ret);
                        return;
                    }
                }

                ret = Misc.MoveFile(e.FullPath, Path.Combine(dir, e.Name));
            }

            if (ret.Length > 0)
            {
                _logger.Info("An error occurred whilst moving the downloaded file: " + ret + Environment.NewLine + e.Name);
                return;
            }

            episode.FileName = e.Name;
            episode.Quality = fileNameParser.Quality;
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTimerTvData_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                _timerTvData.Enabled = false;

                if (_configuration.Shows.Count == 0)
                {
                    return;
                }

                foreach (Series series in _configuration.Shows)
                {
                    // Redownload the series info. Ideally we would be able to determine new episodes but the API doesn't allow that
                     _retriever.DownloadSeries(series.Id,
                                               Helper.GetSeriesCacheFolderPath(series.Id));

                    TvDbSeries seriesCache = Cache.Series(series.Id, Helper.GetSeriesCacheFilePath(series.Id));
                    series.Name = seriesCache.Name;
                    series.Overview = seriesCache.Description;
                    series.FirstAired = seriesCache.FirstAired;
                    series.ImdbId = seriesCache.ImdbId;

                    foreach (TvDbEpisode episodeCache in Cache.Episodes(series.Id, Helper.GetSeriesCacheFilePath(series.Id)))
                    {
                        var episode = (from epi in series.Episodes where epi.Id == episodeCache.Id select epi).SingleOrDefault();
                        if (episode != null)
                        {
                            // Update the episode data
                            episode.SeriesId = series.Id;
                            episode.EpisodeNumber = episodeCache.EpisodeNumber;
                            episode.SeasonNumber = episodeCache.SeasonNumber;
                            episode.Name = episodeCache.EpisodeName;
                            episode.Overview = episodeCache.Overview;
                            episode.Id = episodeCache.Id;
                        }
                        else
                        {
                            // This is a new episode so add it
                            episode = new Episode();
                            episode.SeriesId = series.Id;
                            episode.EpisodeNumber = episodeCache.EpisodeNumber;
                            episode.SeasonNumber = episodeCache.SeasonNumber;
                            episode.Name = episodeCache.EpisodeName;
                            episode.Overview = episodeCache.Overview;
                            episode.Id = episodeCache.Id;

                            series.Episodes.Add(episode);

                            bool found = false;
                            // Now look for files associated with the episode
                            FileNameParser fileNameParser = new FileNameParser();
                            foreach (string file in Misc.GetFiles(series.Path,
                                                                  Global.FILE_EXTENSIONS,
                                                                  SearchOption.AllDirectories))
                            {
                                fileNameParser.Parse(System.IO.Path.GetFileName(file));
                                if (fileNameParser.Matched() == false)
                                {
                                    continue;
                                }

                                if (episode.SeasonNumber == fileNameParser.EpisodeNumber &
                                    episode.EpisodeNumber == fileNameParser.SeasonNumber)
                                {
                                    OnEpisodeFound(series.Id,
                                                    fileNameParser.SeasonNumber,
                                                    fileNameParser.EpisodeNumber,
                                                    System.IO.Path.Combine(series.Path, file),
                                                    fileNameParser.Quality);
                                }
                            }

                            if (found == false)
                            {
                                episode.Status = _settings.NewStatus;
                                if (episode.Status == Global.EpisodeStatus.Wanted)
                                {
                                    AddTorrent(series, episode);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                _timerTvData.Enabled = true;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="seriesId"></param>
        /// <param name="tvId"></param>
        /// <returns></returns>
        private List<RssResult> GetShowRssResults(int seriesId, int tvId)
        {
            List<RssResult> rssResults = new List<RssResult>();

            WebClient wc = new WebClient();
            byte[] temp = wc.DownloadData(string.Format(URL_SHOW_FEED, HOST, seriesId));
            string rss = Encoding.ASCII.GetString(temp);

            FileNameParser fileNameParser = new FileNameParser();

            XDocument xDoc = XDocument.Parse(rss);
            foreach (var item in xDoc.Descendants("item"))
            {
                RssResult rssResult = new RssResult();
                rssResult.SeriesId = tvId;
                rssResult.Title = Misc.GetElementValueAsString(item, "title");

                var enclosure = from e in item.Elements("enclosure") select e;
                if (enclosure.Any() == false)
                {
                    continue;
                }

                rssResult.Url = Misc.GetAttributeValueAsString(enclosure.First(), "url");

                fileNameParser.Parse(rssResult.Title);
                if (fileNameParser.Matched() == true)
                {
                    rssResult.SeasonNumber = fileNameParser.SeasonNumber;
                    rssResult.EpisodeNumber = fileNameParser.EpisodeNumber;
                    rssResult.Quality = fileNameParser.Quality;

                    rssResults.Add(rssResult);
                }
            }

            return rssResults;
        }
Beispiel #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="seriesId"></param>
 /// <param name="path"></param>
 private void EnumerateFiles(int seriesId, string path)
 {
     FileNameParser fileNameParser = new FileNameParser();
     foreach (string file in Misc.GetFiles(path,
                                           Global.FILE_EXTENSIONS,
                                           SearchOption.AllDirectories))
     {
         fileNameParser.Parse(System.IO.Path.GetFileName(file));
         if (fileNameParser.Matched() == true)
         {
             OnEpisodeFound(seriesId,
                             fileNameParser.SeasonNumber,
                             fileNameParser.EpisodeNumber,
                             System.IO.Path.Combine(path, file),
                             fileNameParser.Quality);
         }
     }
 }