Exemplo n.º 1
0
        private void podcast()
        {
            string[]      args = { "",                  //slozka
                                   textBox1.Text,       //jmeno podcastu - knihy
                                   textBox2.Text,       //popisek
                                   "podcast.png",       //obrazek
                                   "144",               //vyska obrazku drzet na 144
                                   "144",               //sirka drzet tez na 144
                                   textBox3.Text,       // autor
                                   "podcast.xml",       //vystup podcast feed
                                   "itunes_podcast.png" //obrazek do itunes:image tagu
            };
            DirectoryInfo di = new DirectoryInfo(path);

            FileInfo[] fi = null;



            switch (comboBox1.Text)
            {
            case "":     //if the combobox is empty use mp3
                fi = di.GetFiles("*.mp3");
                break;

            case "all":     //do all files
                fi = di.GetFiles();
                break;

            default:
            {
                fi = di.GetFiles("*." + comboBox1.Text);
                break;
            }
            }


            Array.Sort <FileInfo>(fi, new Comparison <FileInfo>(delegate(FileInfo d1, FileInfo d2)
            {
                return(string.Compare(d1.Name, d2.Name));
            }));

            //  FileInfo[] fi = di.GetFiles();
            StreamWriter podcast = new StreamWriter(path + "\\" + args[7]);

            podcast.WriteLine("<?xml version=\"1.0\"?>");
            podcast.WriteLine("<rss xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\" version=\"2.0\"  xmlns:atom=\"http://www.w3.org/2005/Atom\">");
            podcast.WriteLine();
            podcast.WriteLine("  <channel>");
            podcast.WriteLine("   <title>" + args[1] + "</title>");
            podcast.WriteLine("   <link>" + adresa + aport + "/" + args[7] + "</link>");
            podcast.WriteLine("   <atom:link href=\"" + adresa + aport + "/" + args[7] + "\" rel=\"self\" type=\"application/rss+xml\" />");
            podcast.WriteLine("   <description>" + args[2] + "</description>");
            podcast.WriteLine("   <webMaster>AudioBook2Podcast</webMaster>");
            podcast.WriteLine("   <managingEditor>AudioBook2Podcast</managingEditor>");
            podcast.WriteLine("   <pubDate>" + date.ToString("r", new CultureInfo("en-GB")).Substring(0, date.ToString("r", new CultureInfo("en-GB")).Length - 3) + "+0100" + "</pubDate>");
            podcast.WriteLine();
            podcast.WriteLine("   <image>");
            podcast.WriteLine("     <url>" + adresa + aport + "/" + args[3] + "</url>");
            podcast.WriteLine("     <width>" + args[4] + "</width>");
            podcast.WriteLine("     <height>" + args[5] + "</height>");
            podcast.WriteLine("     <link>" + adresa + aport + "/" + args[7] + "</link>");
            podcast.WriteLine("     <title>" + args[1] + "</title>");
            podcast.WriteLine("   </image>");
            podcast.WriteLine();

            podcast.WriteLine("   <itunes:image href=\"" + adresa + aport + "/" + args[8] + "\" />");

            podcast.WriteLine();
            podcast.WriteLine("   <copyright>AudioBook2Podcast</copyright>");
            podcast.WriteLine("   <language>en-GB</language>");
            podcast.WriteLine("   <docs>http://blogs.law.harvard.edu/tech/rss</docs>");
            podcast.WriteLine("   <generator>AudioBook2Podcast</generator>");
            //podcast.WriteLine("   <itunes:image href=\"" + adresa + aport + "/" + args[3] + "\"/>");
            podcast.WriteLine();
            podcast.WriteLine();

            int cislo = 1;

            foreach (FileInfo f in fi)
            {
                string jmeno   = f.ToString();
                string titulek = jmeno.Substring(0, jmeno.Length - 4);

                date = date.AddHours(1.0);
                string gooddate = date.ToString("r", new CultureInfo("en-GB"));
                gooddate = gooddate.Substring(0, gooddate.Length - 3) + "+0100";


                podcast.WriteLine();
                podcast.WriteLine("   <item>");
                podcast.WriteLine("    <title>" + titulek + "</title>");
                podcast.WriteLine("    <link>" + adresa + aport + "/" + Uri.EscapeDataString(f.ToString()) + "</link>");
                podcast.WriteLine("    <comments>http://www.aidik.com/</comments>");
                podcast.WriteLine("    <description>" + cislo.ToString() + ". part of book " + args[1] + " by " + args[6] + ".</description>");
                podcast.WriteLine("    <pubDate>" + gooddate + "</pubDate>");
                podcast.WriteLine("    <guid>" + adresa + aport + "/" + Uri.EscapeDataString(f.ToString()) + "</guid>");
                podcast.WriteLine("   <author>" + args[6] + "</author>");
                podcast.WriteLine("   <enclosure url=\"" + adresa + aport + "/" + Uri.EscapeDataString(f.ToString()) + "\" " + "length=\"" + f.Length + "\"  type=\"" + MIMEAssistant.GetMIMEType(f.ToString()) + "\" />");
                podcast.WriteLine("   </item>");
                cislo++;
            }

            podcast.WriteLine("  </channel>");
            podcast.WriteLine("</rss>");

            podcast.Close();
        }
Exemplo n.º 2
0
 private string GetContentType(string path)
 {
     return(MIMEAssistant.GetMIMEType(Path.GetFileName(path), DefaultMimeType));
 }