Exemplo n.º 1
0
        public static void CreateAudioMetadata(string metadataFilePath, string podcastTitle, string releaseTitle, string author, string imageUrl,
                                               string comment, DateTime time)
        {
            FileStream fs = System.IO.File.Create(metadataFilePath);

            //Title
            FileTools.AddText(fs, $"{releaseTitle}\n");

            //Artist
            FileTools.AddText(fs, $"{author}\n");

            //Album
            FileTools.AddText(fs, $"{podcastTitle}\n");

            //Genre
            FileTools.AddText(fs, "Podcast\n");

            //Date
            FileTools.AddText(fs, $"{time.ToString("G")}\n");

            //ImageUrl
            FileTools.AddText(fs, $"{imageUrl}\n");

            //Comment
            comment = comment.Replace("\r", "");
            comment = comment.Replace("\n", "");
            FileTools.AddText(fs, $"{comment}\n");

            fs.Close();
        }
Exemplo n.º 2
0
        public void DownloadSelectIndexRelease(int[] selectIndex, string downloadDirectory, bool isSimpleFile, string downloadProgram, ref FileStream fs)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(FileName);

            var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd");

            var root = xmlDoc.DocumentElement;

            XmlNode channel = root.SelectSingleNode("channel");

            string title = channel.SelectSingleNode("title").InnerText;

            XmlNodeList nodeList = channel.ChildNodes;

            int index = 0;

            for (int i = 0; i < nodeList.Count; i++)
            {
                if (nodeList[i].Name == "item")
                {
                    index++;
                    if (selectIndex.Contains(index))
                    {
                        string   newlyReleasePubDate = nodeList[i].SelectSingleNode("pubDate").InnerText;
                        DateTime dt = DateTime.Now;
                        dt = DateTime.Parse(newlyReleasePubDate).ToUniversalTime();

                        newlyReleasePubDate = dt.ToString("yyyy_MM_dd", DateTimeFormatInfo.InvariantInfo);

                        string newlyReleaseTitle =
                            nodeList[i].SelectSingleNode("title").InnerText.Trim();
                        string newlyReleaseDownloadUrl =
                            nodeList[i].SelectSingleNode("enclosure").Attributes["url"].Value;

                        Logger.Log.Info($"Get the release title is {newlyReleaseTitle}, time is {dt.ToString("G")}.");

                        if (isSimpleFile)
                        {
                            FileTools.AddText(fs, $"{newlyReleaseDownloadUrl}\n");
                        }
                        else
                        {
                            string fileExtension = ".mp3";
                            if (newlyReleaseDownloadUrl.Contains(".m4a"))
                            {
                                fileExtension = ".m4a";
                            }

                            string fileName = GetValidName($"{title} - {newlyReleasePubDate} - {newlyReleaseTitle}{fileExtension}");
                            if (downloadProgram == DownloadTools.Aria2Name)
                            {
                                FileTools.AddText(fs, $"{newlyReleaseDownloadUrl}\n");
                                FileTools.AddText(fs, $"\tdir={downloadDirectory}\n");
                                FileTools.AddText(fs, $"\tout={fileName}\n");
                            }
                            else if (downloadProgram == DownloadTools.IdmName)
                            {
                                FileTools.AddText(fs, $"/a /d \"{newlyReleaseDownloadUrl}\" /p \"{downloadDirectory}\" /f \"{fileName}\"\n");
                            }

                            string author = nodeList[i].SelectSingleNode("author") != null
                                ? nodeList[i].SelectSingleNode("author").InnerText
                                : nodeList[i].SelectSingleNode("itunes:author", nsmgr).InnerText;

                            string imageUrl = nodeList[i].SelectSingleNode("itunes:image", nsmgr).Attributes["href"].Value;

                            string description = RemoveStripHtml(nodeList[i].SelectSingleNode("description").InnerText);

                            string metadataFilePath = ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath + Path.DirectorySeparatorChar +
                                                      fileName + ".metadata";
                            AudioMetadata.CreateAudioMetadata(metadataFilePath, title, newlyReleaseTitle, author, imageUrl, description,
                                                              dt);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void GetPodcastNewlyRelease(ref IOutput output, ref int updateCount)
        {
            //Download new xml
            Logger.Log.Info($"Download the new file of {Name}.");

            using var client = new WebClient();
            client.DownloadFile(this.Url, $"{FileName}.tmp");

            Logger.Log.Info($"Finish download the new file of {Name}.");

            //get last update time
            DateTime lastUpdateDateTime = DateTime.Now;

            if (File.Exists(FileName))
            {
                lastUpdateDateTime = File.GetLastWriteTimeUtc(FileName);
                File.Delete($"{FileName}");
            }
            Logger.Log.Info($"Get the {Name} last update time is {lastUpdateDateTime.ToString("G")}.");

            File.Copy($"{FileName}.tmp", FileName, true);
            File.Delete($"{FileName}.tmp");

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(FileName);

            var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd");

            var root = xmlDoc.DocumentElement;

            if (root == null)
            {
                output.WriteLine("The xml file don't have 'root'.");
                return;
            }

            XmlNode channel = root.SelectSingleNode("channel");

            if (channel == null)
            {
                output.WriteLine("The xml file don't have 'channel'.");
                return;
            }

            XmlNode titleNode = channel.SelectSingleNode("title");

            if (titleNode == null)
            {
                output.WriteLine("The xml file don't have 'title'.");
                return;
            }

            string title = titleNode.InnerText;

            XmlNodeList nodeList = channel.ChildNodes;

            for (int i = 0; i < nodeList.Count; i++)
            {
                if (nodeList[i].Name == "item")
                {
                    string   newlyReleasePubDate = nodeList[i].SelectSingleNode("pubDate").InnerText;
                    DateTime dt = DateTime.Parse(newlyReleasePubDate).ToUniversalTime();
                    if (dt > lastUpdateDateTime)
                    {
                        string newlyReleaseTitle =
                            nodeList[i].SelectSingleNode("title").InnerText.Trim();

                        Logger.Log.Info($"Get the newly release title is {newlyReleaseTitle}, time is {dt.ToString("G")}.");

                        newlyReleasePubDate = dt.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);

                        string showString = $"* {this.Name} - {newlyReleaseTitle} - {newlyReleasePubDate}";

                        output.WriteLine(showString);
                        updateCount++;

                        newlyReleasePubDate = dt.ToString("yyyy_MM_dd", DateTimeFormatInfo.InvariantInfo);

                        string newlyReleaseDownloadUrl =
                            nodeList[i].SelectSingleNode("enclosure").Attributes["url"].Value;

                        string fileExtension = ".mp3";
                        if (newlyReleaseDownloadUrl.Contains(".m4a"))
                        {
                            fileExtension = ".m4a";
                        }

                        string fileName = GetValidName($"{title} - {newlyReleasePubDate} - {newlyReleaseTitle}{fileExtension}");

                        FileStream fs = File.Open(ProgramConfiguration.PodcastNewlyReleaseInfo, FileMode.Append);

                        if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.Aria2Name)
                        {
                            FileTools.AddText(fs, $"{newlyReleaseDownloadUrl}\n");
                            FileTools.AddText(fs, $"\tdir={ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath}\n");
                            FileTools.AddText(fs, $"\tout={fileName}\n");
                        }
                        else if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.IdmName)
                        {
                            FileTools.AddText(fs, $"/a /d \"{newlyReleaseDownloadUrl}\" /p \"{ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath}\" /f \"{fileName}\"\n");
                        }

                        fs.Close();

                        string author = title;
                        if (nodeList[i].SelectSingleNode("author") != null)
                        {
                            author = nodeList[i].SelectSingleNode("author").InnerText;
                        }
                        else if (nodeList[i].SelectSingleNode("itunes:author", nsmgr) != null)
                        {
                            author = nodeList[i].SelectSingleNode("itunes:author", nsmgr).InnerText;
                        }

                        string imageUrl = "null";
                        if (nodeList[i].SelectSingleNode("itunes:image", nsmgr) != null)
                        {
                            imageUrl = nodeList[i].SelectSingleNode("itunes:image", nsmgr).Attributes["href"].Value;
                        }

                        string description = "null";
                        if (nodeList[i].SelectSingleNode("description") != null)
                        {
                            description = RemoveStripHtml(nodeList[i].SelectSingleNode("description").InnerText);
                        }

                        string metadataFilePath = ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath + Path.DirectorySeparatorChar +
                                                  fileName + ".metadata";
                        AudioMetadata.CreateAudioMetadata(metadataFilePath, title, newlyReleaseTitle, author, imageUrl, description,
                                                          dt);
                    }
                }
            }
        }