Пример #1
0
        private static bool importM3U(List <Track> Tracks, string relativePath, System.IO.StreamReader sr)
        {
            while (!sr.EndOfStream)
            {
                string s = sr.ReadLine();

                if (s.Contains("#"))
                {
                    s = s.Substring(0, s.IndexOf('#'));
                }

                if (File.Exists(s) && Track.IsValidExtension(Path.GetExtension(s)))
                {
                    if (!Path.IsPathRooted(s))
                    {
                        s = Path.Combine(relativePath, s);
                    }

                    if (File.Exists(s))
                    {
                        Track t = Track.Load(s);
                        if (t != null)
                        {
                            Tracks.Add(t);
                        }
                    }
                }
            }
            return(false);
        }
Пример #2
0
        private static bool importPLS(List <Track> Tracks, System.IO.StreamReader sr, bool MaxOneURL)
        {
            bool urlsFound = false;

            List <string> lines = new List <string>();

            while (!sr.EndOfStream)
            {
                lines.Add(sr.ReadLine());
            }

            string noe = lines.FirstOrDefault(l => l.StartsWith("numberofentries=", StringComparison.OrdinalIgnoreCase));

            if (noe != null)
            {
                int numLines;
                if (Int32.TryParse(noe.Substring("numberofentries=".Length), out numLines))
                {
                    for (int i = 1; i <= numLines; i++)
                    {
                        string prefix = "file" + i.ToString() + "=";
                        string line   = lines.FirstOrDefault(l => l.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
                        if (line == null)
                        {
                            return(urlsFound);
                        }

                        line = line.Substring(prefix.Length).Trim();

                        if (line.StartsWith("http://"))
                        {
                            if (!urlsFound || !MaxOneURL)
                            {
                                string prefix2 = "title" + i.ToString() + "=";
                                string line2   = lines.FirstOrDefault(l => l.StartsWith(prefix2, StringComparison.OrdinalIgnoreCase));
                                if (line2 != null)
                                {
                                    Radio.AddStation(line, line2.Substring(prefix2.Length), MaxOneURL);
                                }
                                else
                                {
                                    Radio.AddStation(line, String.Empty, MaxOneURL);
                                }
                                urlsFound = true;
                            }
                        }
                        else if (File.Exists(line) && Track.IsValidExtension(Path.GetExtension(line)))
                        {
                            Track t = Track.Load(line);
                            if (t != null)
                            {
                                Tracks.Add(t);
                            }
                        }
                    }
                }
            }
            return(urlsFound);
        }
Пример #3
0
        private static void addItems()
        {
            try
            {
                running = true;
                cancel  = false;
                int itemsLeft;
                lock (addItemLock)
                {
                    itemsLeft = itemsToAdd.Count;
                }

                while (!cancel && itemsLeft > 0)
                {
                    ItemToAdd ita;
                    lock (addItemLock)
                    {
                        ita = itemsToAdd[0];
                        itemsToAdd.RemoveAt(0);
                    }
                    if (Directory.Exists(ita.FilePath))
                    {
                        List <ItemToAdd> newItems = new List <ItemToAdd>();
                        DirectoryInfo    di       = new DirectoryInfo(ita.FilePath);
                        foreach (FileInfo fi in di.GetFiles())
                        {
                            newItems.Add(new ItemToAdd(fi.FullName, ita.PlaylistTarget, ita.AllowDuplicates));
                        }
                        foreach (DirectoryInfo ddi in di.GetDirectories())
                        {
                            newItems.Add(new ItemToAdd(ddi.FullName, ita.PlaylistTarget, ita.AllowDuplicates));
                        }

                        lock (addItemLock)
                        {
                            itemsToAdd = itemsToAdd.Union(newItems).ToList();
                        }
                    }
                    else
                    {
                        if (Track.IsValidExtension(Path.GetExtension(ita.FilePath)))
                        {
                            Track tt = Track.Load(ita.FilePath);
                            if (tt != null)
                            {
                                Database.AddLibraryResult alr = Database.AddToLibrary(tt, ita.AllowDuplicates, true);

                                TrackWriter.AddToUnsavedTracks(tt);

                                if (ita.PlaylistTarget.Length > 0)
                                {
                                    Database.AddToPlaylist(ita.PlaylistTarget, tt);
                                }

                                switch (alr)
                                {
                                case Database.AddLibraryResult.OK:
                                    Controller.ShowMessage("Loading: " + (++addCount).ToString() + " - " + tt.ToString());
                                    break;

                                case Database.AddLibraryResult.UpdateOnly:
                                    Controller.ShowMessage("Updating: " + (++addCount).ToString() + " - " + tt.ToString());
                                    break;
                                }
                                if (((addCount < 200) && ((addCount % 10) == 0)) || (addCount % 200 == 0))
                                {
                                    tryCallback();
                                }
                            }
                        }
                    }

                    lock (addItemLock)
                    {
                        itemsLeft = itemsToAdd.Count;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            running = false;
            lock (addItemLock)
            {
                if (cancel)
                {
                    itemsToAdd.Clear();
                }
            }
            tryCallback();
            TrackWriter.Start();
        }
Пример #4
0
        public void UpdateEpisodeInfo()
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(URL);

                XmlNode baseNode = doc.SelectSingleNode("rss").FirstChild;

                if (baseNode != null)
                {
                    if (this.Name == UNKNOWN_TITLE || Keyboard.Shift)
                    {
                        this.Name = getXMLField(baseNode, "title");
                    }

                    this.ReferenceURL = getXMLField(baseNode, "link");

                    CultureInfo ci = CultureInfo.InvariantCulture;

                    foreach (XmlNode xn in doc.SelectNodes("//item"))
                    {
                        try
                        {
                            string url            = xn.SelectSingleNode("enclosure").Attributes["url"].Value;
                            string date           = String.Empty;
                            string guid           = String.Empty;
                            string title          = String.Empty;
                            string description    = String.Empty;
                            string durationString = String.Empty;
                            int    duration       = 0;

                            if (url.Length > 0 && Track.IsValidExtension(Path.GetExtension(url)))
                            {
                                foreach (XmlNode n in xn.ChildNodes)
                                {
                                    switch (n.Name.ToLowerInvariant())
                                    {
                                    case "pubdate":
                                        date = n.InnerText;
                                        break;

                                    case "guid":
                                        guid = n.InnerText;
                                        break;

                                    case "title":
                                        title = n.InnerText;
                                        break;

                                    case "description":
                                        if (description.Length == 0)
                                        {
                                            description = n.InnerText;
                                        }
                                        break;

                                    case "itunes:duration":
                                        durationString = n.InnerText;
                                        break;

                                    case "itunes:summary":
                                        description = n.InnerText;
                                        break;

                                    default:
                                        System.Diagnostics.Debug.WriteLine(n.Name.ToLowerInvariant());
                                        break;
                                    }
                                }
                                DateTime dt;
                                if (!DateTime.TryParse(date, out dt))
                                {
                                    if (!DateTime.TryParseExact(date, dateParseFormats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dt))
                                    {
                                        dt = extractDate(date);
                                    }
                                }

                                if (guid.Length == 0)
                                {
                                    guid = url;
                                }

                                if (durationString.Length > 0)
                                {
                                    duration = durationFromString(durationString);
                                }

                                PodcastEpisode pe = new PodcastEpisode(title,
                                                                       guid,
                                                                       clean(description),
                                                                       url,
                                                                       dt,
                                                                       duration,
                                                                       DateTime.MinValue,
                                                                       PodcastDownloadStatus.NotDownloaded,
                                                                       null,
                                                                       this);
                                addEpisode(pe);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
                        }
                    }
                    updateValues();
                    if (DataChanged != null)
                    {
                        DataChanged(this);
                    }
                    Controller.ShowMessage("Refreshed " + this.Name);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Controller.ShowMessage("Failed to find podcast updates.");
            }
        }