Пример #1
0
        private void DownloadFile(ShowToDownload show)
        {
            var folder = show.TargetFolder;

            folder = Path.Combine(folder, "__Files");

            this.EnsureFolderExists(folder);

            var file = show.Uri.Segments.Last();

            // Prefix with feed name
            file = show.Feedname + " - " + file;

            file = this.CleanupFilename(file, show.PublishDate);

            var targetpath = Path.Combine(folder, file);
            var fi         = new FileInfo(targetpath);

            /*
             * // a) doesn't exist yet -- great, write it
             * // b) exists with about the same time -- already done, skip
             * // c) exists with other time -- write under new name
             */

            if (fi.Exists)
            {
                if (Math.Abs((show.PublishDate - fi.CreationTimeUtc).TotalHours) < 1.0)
                {
                    // TODO move to separate message(-handler)
                    Context.Parent.Tell(new ShowProgressMessage(show.Feedname, file, fi.Length, "File already downloaded: skipping."), this.Self);
                    Context.Parent.Tell(new FileStored(file, show.PublishDate));
                    this.Self.Tell(ProcessQueueMessage);
                }
                else
                {
                    var ext = Path.GetExtension(file);
                    file       = Path.GetFileNameWithoutExtension(file);
                    file       = file + show.PublishDate.ToString("-yyyy-MM-dd") + ext;
                    targetpath = Path.Combine(folder, file);

                    this.DownloadFileToLocal(show.Uri, targetpath, show.PublishDate);
                }
            }
            else
            {
                this.DownloadFileToLocal(show.Uri, targetpath, show.PublishDate);
            }
        }
Пример #2
0
        private void ReadAllShows()
        {
            DateTimeOffset latest = this.config.LatestDownload;

            bool haschild = false;

            foreach (var item in this.podcast.Items.Where(it => it.PublishDate > latest).OrderBy(it => it.PublishDate))
            {
                Logger.Log(LogSeverity.Information, LogCategory, "Podcast: " + item.Title.Text);
                if (item.Links != null)
                {
                    foreach (var link in item.Links.Where(l => l.RelationshipType == "enclosure"))
                    {
                        Logger.Log(LogSeverity.Debug, LogCategory, "Link: " + link.Uri);
                        var msg = new ShowToDownload(link.Uri, item.PublishDate, this.config.TargetFolder, this.config.Name);
                        this.downloader.Tell(msg, this.Self);
                        haschild = true;
                    }
                }
                else
                {
                    Logger.Log(LogSeverity.Warning, LogCategory, "No links found!");
                }

                ////if (item.PublishDate > latest)
                ////{
                ////    latest = item.PublishDate;
                ////    this.feed.LatestDownload = latest;
                ////    this.feed.LatestError = String.Empty;
                ////}
            }

            if (!haschild)
            {
                Logger.Log(LogSeverity.Warning, LogCategory, "Nothing found to download.");
                this.Self.Tell(QueueIsDoneMessage);
            }
        }