public Upnp.upnpObject GetUpnpMusicTrack(OptionPageSetup aUserOptionsSetup, HelperKinskyJukebox aHelper) { Upnp.upnpObject upnpMusicTrack = null; if (DiscCount > 0) { upnpMusicTrack = new Upnp.musicTrack(); } else { upnpMusicTrack = new Upnp.musicTrack(); } upnpMusicTrack.Id = FilePath; upnpMusicTrack.Title = Title; ((Upnp.musicTrack)upnpMusicTrack).Album.Add(Album); ((Upnp.musicTrack)upnpMusicTrack).Genre.Add(Genre); ((Upnp.musicTrack)upnpMusicTrack).OriginalTrackNumber = (int)Track; if (upnpMusicTrack is Upnp.musicTrack) { ((Upnp.musicTrack)upnpMusicTrack).OriginalDiscNumber = (int)Disc; ((Upnp.musicTrack)upnpMusicTrack).OriginalDiscCount = (int)DiscCount; } ((Upnp.musicTrack)upnpMusicTrack).Date = Year; Upnp.artist performer = new Upnp.artist(); performer.Artist = Artist; performer.Role = "Performer"; ((Upnp.musicTrack)upnpMusicTrack).Artist.Add(performer); Upnp.artist composer = new Upnp.artist(); composer.Role = "Composer"; composer.Artist = Composer; ((Upnp.musicTrack)upnpMusicTrack).Artist.Add(composer); Upnp.artist albumArtist = new Upnp.artist(); albumArtist.Artist = AlbumArtist; albumArtist.Role = "AlbumArtist"; ((Upnp.musicTrack)upnpMusicTrack).Artist.Add(albumArtist); Upnp.artist conductor = new Upnp.artist(); conductor.Artist = Conductor; conductor.Role = "Conductor"; ((Upnp.musicTrack)upnpMusicTrack).Artist.Add(conductor); Upnp.resource resource = new Upnp.resource(); resource.Duration = Duration; resource.Uri = GetUri(FilePath, aHelper); resource.ProtocolInfo = "http-get:*:" + MimeType + ":*"; upnpMusicTrack.Res.Add(resource); try { string art = GetUri(AlbumArtPath, aHelper); upnpMusicTrack.AlbumArtUri.Add(art); upnpMusicTrack.ArtworkUri.Add(art); } catch (Exception) { // if AlbumArtPath is invalid, just don't add artwork } return(upnpMusicTrack); }
private void CreateLocalRadio() { string geoLocation = "Unknown"; List <string> links = new List <string>(); XmlTextReader reader = null; TreeNode nodeLocalRadio = new TreeNode(); try { iProgressChanged(0, "Adding: Local Radio", Progress.State.eInProgress); // generate list of local locations and links based on geoId (from server IP) reader = new XmlTextReader(GetHttpResponse(kTuneInLocalQuery).GetResponseStream()); reader.WhitespaceHandling = WhitespaceHandling.None; reader.MoveToContent(); while (reader.Read()) { if (reader.Name == "outline" && reader.IsStartElement()) { if (reader.GetAttribute("type") == "link") { links.Add(reader.GetAttribute("URL")); } else if (reader.GetAttribute("type") == "audio") { links.Add(kTuneInLocalQuery); // no links - just local stations (will generate 1 preset only) break; } } else if (reader.Name == "title" && reader.IsStartElement()) // geoId location { reader.Read(); geoLocation = reader.Value; } else if (reader.Name == "body" && !reader.IsStartElement()) // end tag { break; } } // create single bookmark node for local radio nodeLocalRadio.Text = "Local Radio (" + geoLocation + ") Powered by TuneIn Radio"; nodeLocalRadio.Name = "1"; nodeLocalRadio.ImageIndex = 0; nodeLocalRadio.SelectedImageIndex = 0; int i = 0; // generate list of stations based on location based links foreach (string link in links) { iProgressChanged(i++ *100 / links.Count, "Adding: Local Radio", Progress.State.eInProgress); reader = new XmlTextReader(GetHttpResponse(link).GetResponseStream()); reader.WhitespaceHandling = WhitespaceHandling.None; reader.MoveToContent(); TreeNode nodeAllStations = new TreeNode(); while (reader.Read()) { if (reader.Name == "outline" && reader.IsStartElement()) { if (reader.GetAttribute("type") == "audio") { Upnp.musicTrack upnpTrack = new Upnp.musicTrack(); upnpTrack.Title = reader.GetAttribute("text"); Upnp.artist artist = new Upnp.artist(); artist.Artist = "Powered by TuneIn Radio"; upnpTrack.Artist.Add(artist); string info = reader.GetAttribute("subtext") + " (Bitrate: " + reader.GetAttribute("bitrate") + "kbps, Reliability: " + reader.GetAttribute("reliability") + "%)"; upnpTrack.Album.Add(info); Upnp.resource res = new Upnp.resource(); res.Uri = reader.GetAttribute("URL"); upnpTrack.Res.Add(res); upnpTrack.ArtworkUri.Add(reader.GetAttribute("image")); upnpTrack.AlbumArtUri.Add(reader.GetAttribute("image")); TrackMetadata data = new TrackMetadata(upnpTrack); TreeNode item = new TreeNode(data.Title); item.Tag = data; item.ToolTipText = data.ToString(); item.ImageIndex = 2; item.SelectedImageIndex = 2; nodeAllStations.Nodes.Add(item); } } else if (reader.Name == "title" && reader.IsStartElement()) // geoId location { reader.Read(); geoLocation = reader.Value; } else if (reader.Name == "body" && !reader.IsStartElement()) // end tag { break; } } // create region preset node and add all stations TreeNode subnodeRegion = new TreeNode(geoLocation); subnodeRegion.Name = "1"; subnodeRegion.ImageIndex = 1; subnodeRegion.SelectedImageIndex = 1; foreach (TreeNode node in nodeAllStations.Nodes) { subnodeRegion.Nodes.Add((TreeNode)node.Clone()); } subnodeRegion.ToolTipText = "Count: " + subnodeRegion.Nodes.Count; nodeLocalRadio.Nodes.Add(subnodeRegion); } nodeLocalRadio.ToolTipText = "Count: " + nodeLocalRadio.Nodes.Count; iNodeCreated(nodeLocalRadio); } catch (Exception e) { UserLog.WriteLine("CreateLocalRadio Error: " + e); } finally { if (reader != null) { reader.Close(); } } }