From: <eda...@us...> - 2015-05-25 21:21:35
|
Revision: 4956 http://sourceforge.net/p/mp-plugins/code/4956 Author: edalex86 Date: 2015-05-25 21:21:32 +0000 (Mon, 25 May 2015) Log Message: ----------- New features: - AudioAddict API added (di.fm, jazz radio etc) - Async directory loading Fixes: - Project reverted to .Net 3.5 to restore compatibility with MP below 1.7.0 - Recording temporally disabled to eliminate Bass dependency - Visualizations disabled (not present in MediaPortal anymore) Modified Paths: -------------- trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/GUIRadio.cs trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/MyStreamRadio.csproj trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/Parser.cs trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/Properties/Resources.Designer.cs Added Paths: ----------- trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/AudioAddict/ trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/AudioAddict/AudioAddictAPI.cs Removed Paths: ------------- trunk/plugins/MyStreamradioV2/Source/External/ Added: trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/AudioAddict/AudioAddictAPI.cs =================================================================== --- trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/AudioAddict/AudioAddictAPI.cs (rev 0) +++ trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/AudioAddict/AudioAddictAPI.cs 2015-05-25 21:21:32 UTC (rev 4956) @@ -0,0 +1,352 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MediaPortal.Configuration; +using MediaPortal.Util; +using MediaPortal.GUI.Library; +using System.Web.Script.Serialization; +using System.Net; +using System.IO; +using System.ComponentModel; + +namespace MediaPortal.GUI.MyStreamRadio +{ + public class AudioAddictAPI + { + // some info taken from http://difm.eu/dox/ , the rest - personal experimenting + private const string NetworksURL = @"http://api.audioaddict.com/v1/networks"; + public static string APIBaseUrl = @"http://api.audioaddict.com/"; + public static JavaScriptSerializer js = new JavaScriptSerializer(); + const string PluginSubfolder = "MyStreamRadio\\"; + //public static string StreamBaseUrl = "http://listen.di.fm/"; + //string Config.GetSubFolder(Config.Dir.Thumbs, PluginSubfolder + @"sources\tv\"); + + public static void LoadInternalStations() + { + BackgroundWorker AADownloader = new BackgroundWorker(); + AADownloader.DoWork += new DoWorkEventHandler(ad_DoWork); + AADownloader.RunWorkerAsync(); + AADownloader.Dispose(); + + } + private static void ad_DoWork(object sender, DoWorkEventArgs e) + { + var networkList = new List<AANetwork>(); + networkList.AddRange(js.Deserialize<AANetwork[]>(GetResponse(NetworksURL))); + Log.Debug("Server response contains {0} networks.", networkList.Count); + + foreach (var network in networkList) + { + var nw = new RadioNetwork { ListenURL = network.listen_url, Key = network.key, Name = network.name }; + ProcessNetwork(nw); + } + } + + + public static List<AANetwork> GetNetworks() + { + return js.Deserialize<AANetwork[]>(GetResponse(NetworksURL)).ToList(); + } + + public static List<AAChannel> GetChannels(string networkName) + { + var wc = new WebClient(); + var channelList = new List<AAChannel>(); + AANetwork selNet = GetNetworks().First(n => n.name == networkName); + var nw = new RadioNetwork { ListenURL = selNet.listen_url, Key = selNet.key, Name = selNet.name }; + channelList.AddRange(js.Deserialize<AAChannel[]>(GetResponse(nw.ChannelListURL))); + channelList.Sort(AAChannel.Compare); + return channelList; + } + public static AAChannelInfo GetChannelInfo(AAChannel ch, RadioNetwork network) + { + var response = GetResponse(network.ChannelURL + ch.id); + if (string.IsNullOrEmpty(response)) + { + Log.Debug(" Channel info not found for channel ID {0}", ch.id); + return null; + } + AAChannelInfo info = js.Deserialize<AAChannelInfo>(response); + info.ParentNetwork = network; + return info; + } + + public static void ProcessNetwork(RadioNetwork network) + { + var wc = new WebClient(); + var channelList = new List<AAChannel>(); + + Log.Debug("MyStreamRadio: Getting info for network {0}", network.Name); + + if (!Directory.Exists(network.MainFolder)) + Directory.CreateDirectory(Path.GetDirectoryName(network.MainFolder)); + if (!Directory.Exists(network.ImageFolder)) + Directory.CreateDirectory(Path.GetDirectoryName(network.ImageFolder)); + if (!Directory.Exists(network.BannerFolder)) + Directory.CreateDirectory(Path.GetDirectoryName(network.BannerFolder)); + + channelList.AddRange(js.Deserialize<AAChannel[]>(GetResponse(network.ChannelListURL))); + channelList.Sort(AAChannel.Compare); + foreach (var channel in channelList) + { + Log.Debug("\n Name: "); + Log.Debug(channel.name); + Log.Debug(", ID: {0}", channel.id); + AAChannelInfo info = GetChannelInfo(channel, network); + var localAssetFileName = network.ImageFolder + network.Prefix + channel.name + Path.GetExtension(info.asset_url); + if (!File.Exists(localAssetFileName) || (File.GetLastWriteTime(localAssetFileName) < info.updated_at)) + { + try + { + wc.DownloadFile(@"http:" + info.asset_url, localAssetFileName); + Log.Debug(" logo updated"); + } + catch (Exception e) + { + Log.Debug(" couldn't download image with id {0}: {1}", channel.id, e.Message); + } + } + else + { + Log.Debug(" skipped old existing logo"); + } + var localBannerFileName =network.BannerFolder + network.Prefix + channel.name + Path.GetExtension(info.banner_url); + if (!File.Exists(localBannerFileName) || (File.GetLastWriteTime(localBannerFileName) < info.updated_at)) + { + if (info.banner_url == null) + { + Log.Debug(" banner not defined"); + } + else try + { + wc.DownloadFile(@"http:" + info.banner_url, localBannerFileName); + Log.Debug(" banner updated"); + } + catch (Exception e) + { + Log.Debug(" couldn't download banner with id {0}: {1}", channel.id, e.Message); + } + } + } + Log.Debug("\nCompleted list with {0} channels.", channelList.Count); + } + + + static string GetResponse(string request) + { + var wc = new WebClient(); + wc.Headers.Add("Content-type: application/json"); + wc.Headers.Add("Accept: application/json"); + string response = string.Empty; + try + { + response = wc.DownloadString(request); + } + catch (Exception e) + { + Log.Debug("Error retrieving data from server: {0}", e.Message); + } + wc.Dispose(); + return response; + } + + + + + + public class AANetwork + { + public DateTime created_at; + public string description; + public int id; + public string key; + public string name; + public DateTime updated_at; + public string url; + public string listen_url; + public string service_key; + /*{"created_at":"2010-03-16T18:02:42-04:00" + "description":null + "id":1 + "key":"di" + "name":"Digitally Imported" + "updated_at":"2014-03-13T19:36:19-04:00" + "url":"http:\/\/www.di.fm" + "listen_url":"http:\/\/listen.di.fm" + "service_key":"di-premium" + }*/ + } + + public class RadioNetwork + { + public string Name; + public string Key; + public string ListenURL; + public string ChannelListURL { get { return ListenURL + @"/public3"; } } + public string ChannelURL { get { return string.Format(@"http://api.audioaddict.com/v1/{0}/channels/", Key); } } + public string MainFolder { get { return Config.GetSubFolder(Config.Dir.Thumbs, PluginSubfolder) + Name + @"\"; } } + public string ImageFolder { get { return Path.Combine(MainFolder, @"Images\"); } } + public string BannerFolder { get { return Path.Combine(MainFolder, @"Banners\"); } } + public string Prefix + { // abbreviation for network name as prefix for images + get + { + string result; + switch (Key) + { + case "radiotunes": + result = "rt"; + break; + case "jazzradio": + result = "jr"; + break; + case "rockradio": + result = "rr"; + break; + case "frescaradio": + result = "fr"; + break; + default: + result = Key; + break; + } + return result + " "; + } + } + } + + public enum StreamType + { + android_low, //40kbps aac + android, //64kbps aac + android_high, //96kbps mp3 + android_premium_low, //40kbps aac + android_premium_medium, //64kbps aac + android_premium, //128kbps aac + android_premium_high, //256kbps mp3 + public1, //64kbps aac + public2, //40kbps aac + public3, //96kbps mp3 + premium_low, //40kbps aac + premium_medium, //64kbps aac + premium, //128kbps aac + premium_high //256kbps mp3 + } + public class Stream + { + public int id { get; set; } + public string key { get; set; } + public string name { get; set; } + public string playlist { get; set; } + + } + public class PLaylist + { + } + public class AAChannel + { + public int id { get; set; } + public string key { get; set; } + public string name { get; set; } + public string playlist { get; set; } + //} + /* + {"id":348, + "key":"dub", + "name":"Dub", + "playlist":"http:\/\/listen.di.fm\/[streamlist]\/dub.pls" + } + */ + + public static int Compare(AAChannel ch1, AAChannel ch2) + { + return ch1.id - ch2.id; + } + } + + public class AAChannelInfo + { + public string ad_channels { get; set; } + public string channel_director { get; set; } + public DateTime created_at { get; set; } + public string description_long { get; set; } + public string description_short { get; set; } + public int? forum_id { get; set; } + public int id { get; set; } + public string key { get; set; } + public string name { get; set; } + public int? network_id { get; set; } + public int? old_id { get; set; } + public int? premium_id { get; set; } + public int? tracklist_server_id { get; set; } + public DateTime updated_at { get; set; } + public int? asset_id { get; set; } + public string asset_url { get; set; } + public string banner_url { get; set; } + public string description { get; set; } + public AASimilarChannels[] similar_channels { get; set; } + public AAImages images { get; set; } + public string LocalImage + { + get { return (string.IsNullOrEmpty(asset_url) ? "" : ParentNetwork.ImageFolder + ParentNetwork.Prefix + name + Path.GetExtension(asset_url)); } + + } + public RadioNetwork ParentNetwork { get; set; } + } + + public class AASimilarChannels + { + public int id { get; set; } + public int similar_channel_id { get; set; } + } + + public class AAImages + { + private string def; + + public string Default + { + get { return def; } + set { def = (value == null) ? null : value.Replace("{?size,height,width,quality}", ""); } + } + + private string hor_b; + + public string horizontal_banner + { + get { return hor_b; } + set { hor_b = (value == null) ? null : value.Replace("{?size,height,width,quality}", ""); } + } + + /* + {"ad_channels":"8554477917, electronic_music, 8614582190", + "channel_director":"Entranced", + "created_at":"2010-03-16T18:02:42-04:00", + "description_long":"", + "description_short":"Emotive high energy dance music which embraces melodies, vocals and a true journey of dance music songwriting.", + "forum_id":5, + "id":1, + "key":"trance", + "name":"Trance", + "network_id":1, + "old_id":1, + "premium_id":0, + "tracklist_server_id":25623, + "updated_at":"2015-02-17T14:56:41-05:00", + "asset_id":1, + "asset_url":"\/\/static.audioaddict.com\/befc1043f0a216128f8570d3664856f7.png", + "banner_url":"\/\/static.audioaddict.com\/7\/7\/9\/6\/8\/6\/7796862185adb0e0447d31d01c02c2c1.jpg", + "description":"Emotive high energy dance music which embraces melodies, vocals and a true journey of dance music songwriting.", + "similar_channels":[{"id":159,"similar_channel_id":2}, + {"id":160,"similar_channel_id":90}, + {"id":186,"similar_channel_id":175}], + "images":{ "default":"\/\/api.audioaddict.com\/v1\/assets\/image\/befc1043f0a216128f8570d3664856f7.png{?size,height,width,quality}", + "horizontal_banner":"\/\/api.audioaddict.com\/v1\/assets\/image\/7796862185adb0e0447d31d01c02c2c1.jpg{?size,height,width,quality}"} + } + } + */ + } + + } +} \ No newline at end of file Modified: trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/GUIRadio.cs =================================================================== --- trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/GUIRadio.cs 2015-02-21 11:13:37 UTC (rev 4955) +++ trunk/plugins/MyStreamradioV2/Source/MyStreamRadio/GUIRadio.cs 2015-05-25 21:21:32 UTC (rev 4956) @@ -41,18 +41,21 @@ //using MediaPortal.Radio.Database; using MediaPortal.Music.Database; -using MediaPortal.Visualization; +//using MediaPortal.Visualization; //Bass classes -using Un4seen.Bass; -using Un4seen.Bass.Misc; +//using Un4seen.Bass; +//using Un4seen.Bass.Misc; //using for token processing using System.IO; using System.Text; +using System.Linq; using Action = MediaPortal.GUI.Library.Action; +using System.ComponentModel; + namespace MediaPortal.GUI.MyStreamRadio { [PluginIcons("MyStreamRadio.StreamRadio.png", "MyStreamRadio.StreamRadioDisabled.png")] @@ -89,7 +92,7 @@ string currentFolder = string.Empty; - string currentRadioFolder = string.Empty; + string RootRadioFolder = string.Empty; string recordFolder = string.Empty; string currentFile = string.Empty; @@ -118,7 +121,7 @@ private int displayTime = 1; private int actDisplayTime = 0; - private EncoderLAME lame; + //private EncoderLAME lame; private bool useIcecast = false; private bool useShoutcast = false; @@ -126,6 +129,8 @@ private string engine = string.Empty; private int filter = 0; + public List<AudioAddictAPI.AANetwork> networks = new List<AudioAddictAPI.AANetwork>(); + #endregion #region SkinControls @@ -160,13 +165,13 @@ using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { #region path settings - currentRadioFolder = xmlreader.GetValueAsString("mystreamradio", "Radiopath", Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config) + "\\Radio"); + RootRadioFolder = xmlreader.GetValueAsString("mystreamradio", "Radiopath", Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config) + "\\Radio"); recordFolder = xmlreader.GetValueAsString("mystreamradio", "Record", Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config) + "\\Record"); - Log.Debug("MyStreamRadio: radio folder = " + currentRadioFolder); + Log.Debug("MyStreamRadio: radio folder = " + RootRadioFolder); Log.Debug("MyStreamRadio: record folder = " + recordFolder); - if (!Directory.Exists(currentRadioFolder)) + if (!Directory.Exists(RootRadioFolder)) { Log.Error("MyStreamRadio: radio path is not existing"); } @@ -325,6 +330,8 @@ { ServicePointManager.DefaultConnectionLimit = 10; currentFolder = string.Empty; + networks = AudioAddictAPI.GetNetworks(); + AudioAddictAPI.LoadInternalStations(); return (Load(GUIGraphicsContext.Skin + @"\mystreamradio.xml")); } @@ -368,7 +375,7 @@ #endregion virtualDirectory = new VirtualDirectory(); - Share share = new Share("default", currentRadioFolder); + Share share = new Share("default", RootRadioFolder); share.Default = true; virtualDirectory.Add(share); virtualDirectory.AddExtension(".xml"); @@ -400,24 +407,24 @@ else _Autostart.Start(); #endregion - if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null) - { - if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"] == null) - { - Log.Debug("Streamradio: Creating new label on Visualization screen"); - crtDisplay lb = new crtDisplay(); - lb.Name = "Display"; - lb.Visible = false; - MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls.Add(lb); - } + //if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null) + //{ + // if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"] == null) + // { + // Log.Debug("Streamradio: Creating new label on Visualization screen"); + // crtDisplay lb = new crtDisplay(); + // lb.Name = "Display"; + // lb.Visible = false; + // MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls.Add(lb); + // } - if (!isInit) - { - isInit = true; - MediaPortal.Visualization.VisualizationBase.VisualizationWindow.SizeChanged += new EventHandler(VisualizationWindow_SizeChanged); - } + // if (!isInit) + // { + // isInit = true; + // MediaPortal.Visualization.VisualizationBase.VisualizationWindow.SizeChanged += new EventHandler(VisualizationWindow_SizeChanged); + // } - } + //} Log.Info("Streamradio: Player engine is " + engine); if (!engine.Contains("BASS")) @@ -500,7 +507,7 @@ if (control == btnRecord) { - OnRecord(); + //OnRecord(); } if (control == btnRecordings) @@ -657,7 +664,7 @@ { if (action.wID == Action.ActionType.ACTION_RECORD) { - OnRecord(); + //OnRecord(); } if (action.wID == Action.ActionType.ACTION_STOP) @@ -714,11 +721,11 @@ _Update.Enabled = false; _Update.Stop(); - if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null) - { - crtDisplay mLabel = (crtDisplay)MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"]; - if (mLabel != null) mLabel.Visible = false; - } + //if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null) + //{ + // crtDisplay mLabel = (crtDisplay)MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"]; + // if (mLabel != null) mLabel.Visible = false; + //} GUIPropertyManager.SetProperty("#Play.Current.Title", ""); GUIPropertyManager.SetProperty("#Play.Current.Artist", ""); @@ -726,42 +733,42 @@ } } - private void VisualizationWindow_SizeChanged(object sender, EventArgs e) - { - if (_Update.Enabled) - { - if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow == null) return; + //private void VisualizationWindow_SizeChanged(object sender, EventArgs e) + //{ + // if (_Update.Enabled) + // { + // if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow == null) return; - crtDisplay mLabel = (crtDisplay)MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"]; - if (mLabel == null) return; + // crtDisplay mLabel = (crtDisplay)MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"]; + // if (mLabel == null) return; - if (currentFile == g_Player.CurrentFile) - { - if (g_Player.FullScreen) - { - int x = MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Width; - int y = MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Height; + // if (currentFile == g_Player.CurrentFile) + // { + // if (g_Player.FullScreen) + // { + // int x = MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Width; + // int y = MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Height; - mLabel.Size = new Size(x, y / 8); - mLabel.Location = new Point(0, y / 10 * 8); + // mLabel.Size = new Size(x, y / 8); + // mLabel.Location = new Point(0, y / 10 * 8); - // set visible depending on mode - if ((displayMode == 1) || ((displayMode == 2) && (actDisplayTime > 0))) - mLabel.Visible = true; - } - else - { - mLabel.Visible = false; - } - } - else - mLabel.Visible = false; - } - else - { - // not enabled - } - } + // // set visible depending on mode + // if ((displayMode == 1) || ((displayMode == 2) && (actDisplayTime > 0))) + // mLabel.Visible = true; + // } + // else + // { + // mLabel.Visible = false; + // } + // } + // else + // mLabel.Visible = false; + // } + // else + // { + // // not enabled + // } + //} private void _Update_Tick(Object obj, EventArgs e) { @@ -774,19 +781,19 @@ { crtDisplay mLabel = null; - if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null) - { - mLabel = (crtDisplay)MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"]; + //if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null) + //{ + // mLabel = (crtDisplay)MediaPortal.Visualization.VisualizationBase.VisualizationWindow.Controls["Display"]; - // set visible depending on mode - if (mLabel != null) - { - if ((displayMode == 1) || ((displayMode == 2) && (actDisplayTime > 0))) - mLabel.Visible = true; - else - mLabel.Visible = false; - } - } + // // set visible depending on mode + // if (mLabel != null) + // { + // if ((displayMode == 1) || ((displayMode == 2) && (actDisplayTime > 0))) + // mLabel.Visible = true; + // else + // mLabel.Visible = false; + // } + //} if (parser != null) { @@ -815,39 +822,39 @@ Log.Info("StreamRadio: Current track: {0} [{1}] - {2}", parser.Artist.Trim(), actualStation, parser.Title.Trim()); } } - if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null && mLabel != null) - { - if (actualStation != null) - { - string[] now = actualStation.Split('|'); - if (now.Length != 3) return; + //if (MediaPortal.Visualization.VisualizationBase.VisualizationWindow != null && mLabel != null) + //{ + // if (actualStation != null) + // { + // string[] now = actualStation.Split('|'); + // if (now.Length != 3) return; - string name = now[0]; - string url = now[1]; - string file = now[2]; + // string name = now[0]; + // string url = now[1]; + // string file = now[2]; - if (file.ToLower().Contains("xml")) - { - Station station = new Station(file); + // if (file.ToLower().Contains("xml")) + // { + // Station station = new Station(file); - int _stream = (int)MediaPortal.Visualization.VisualizationBase.Bass.CurrentAudioStream; + // int _stream = (int)MediaPortal.Visualization.VisualizationBase.Bass.CurrentAudioStream; - if (_stream != 0) - { - mLabel.Artist = parser.Artist; - mLabel.Title = parser.Title; + // if (_stream != 0) + // { + // mLabel.Artist = parser.Artist; + // mLabel.Title = parser.Title; - mLabel.Station = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs) + "\\Radio\\" + station.Logo; - mLabel.Country = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs) + "\\Radio\\" + station.Country + ".png"; - mLabel.Desciption = station.Description; - if (EncodeActive()) mLabel.Desciption = "RECORD"; + // mLabel.Station = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs) + "\\Radio\\" + station.Logo; + // mLabel.Country = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs) + "\\Radio\\" + station.Country + ".png"; + // mLabel.Desciption = station.Description; + // if (EncodeActive()) mLabel.Desciption = "RECORD"; - mLabel.BringToFront(); - } - } - } - } + // mLabel.BringToFront(); + // } + // } + // } + //} } } } @@ -1047,6 +1054,19 @@ private void LoadDirectory() { + + BackgroundWorker ListAdder = new BackgroundWorker(); + ListAdder.DoWork += new DoWorkEventHandler(ListAdder_DoWork); + ListAdder.RunWorkerAsync(); + } + + private void ListAdder_DoWork(object sender, DoWorkEventArgs e) + { + LoadDirectoryAsync(); + } + + private void LoadDirectoryAsync() + { GUIWaitCursor.Show(); GUIControl.ClearControl(GetID, facadeView.GetID); @@ -1055,318 +1075,369 @@ GUIListItem aItem = null; - if (currentRadioFolder.Length != 0) + if (RootRadioFolder.Length != 0) { - #region special folder - string folderName = currentFolder; + #region special folder + string folderName = currentFolder; - if (folderName.Length == 0) folderName = currentRadioFolder; + if (folderName.Length == 0) folderName = RootRadioFolder; - // icecast folder - if (folderName == currentRadioFolder) - { - if (useIcecast) + // icecast folder + if (folderName == RootRadioFolder) { - aItem = new GUIListItem(); - aItem.Label = "Icecast"; - aItem.Path = "Icecast"; - aItem.IsFolder = true; - aItem.MusicTag = null; - aItem.IconImageBig = "icecastBig.png"; - aItem.IconImage = "icecast.png"; + #region add AudioAddict networks + foreach (AudioAddictAPI.AANetwork net in networks) + { + GUIListItem aaItem = new GUIListItem(); + aaItem.Label = net.name; + aaItem.Path = net.name; + aaItem.IsFolder = true; + aaItem.MusicTag = net; + Util.Utils.SetDefaultIcons(aaItem); + facadeView.Add(aaItem); + totalItems++; + aaItem.Dispose(); + } + #endregion - facadeView.Add(aItem); - totalItems++; + if (useIcecast) + { + aItem = new GUIListItem(); + aItem.Label = "Icecast"; + aItem.Path = "Icecast"; + aItem.IsFolder = true; + aItem.MusicTag = null; + aItem.IconImageBig = "icecastBig.png"; + aItem.IconImage = "icecast.png"; + + facadeView.Add(aItem); + totalItems++; + } + if (useShoutcast) + { + aItem = new GUIListItem(); + aItem.Label = "Shoutcast"; + aItem.Path = "Shoutcast"; + aItem.IsFolder = true; + aItem.MusicTag = null; + aItem.IconImageBig = "shoutBig.png"; + aItem.IconImage = "shout.png"; + + facadeView.Add(aItem); + totalItems++; + } } - if (useShoutcast) + #endregion + + if (folderName.Contains(RootRadioFolder)) { - aItem = new GUIListItem(); - aItem.Label = "Shoutcast"; - aItem.Path = "Shoutcast"; - aItem.IsFolder = true; - aItem.MusicTag = null; - aItem.IconImageBig = "shoutBig.png"; - aItem.IconImage = "shout.png"; - facadeView.Add(aItem); - totalItems++; - } - } - #endregion + #region fill normal folder + List<GUIListItem> items = new List<GUIListItem>(); + items = virtualDirectory.GetDirectoryExt(folderName); - if (!folderName.Contains("Shoutcast") && (!folderName.Contains("Icecast"))) - { - #region fill normal folder - List<GUIListItem> items = new List<GUIListItem>(); - items = virtualDirectory.GetDirectoryExt(folderName); + Log.Debug("Streamradio: loading directory with " + items.Count + " items"); - Log.Debug("Streamradio: loading directory with " + items.Count + " items"); + foreach (GUIListItem item in items) + { + int i = 0; + if (!item.IsFolder) + { + item.MusicTag = null; - foreach (GUIListItem item in items) - { - int i = 0; - if (!item.IsFolder) - { - item.MusicTag = null; + item.IconImageBig = "DefaultMyradioStreamBig.png"; + item.IconImage = "DefaultMyradioStream.png"; - item.IconImageBig = "DefaultMyradioStreamBig.png"; - item.IconImage = "DefaultMyradioStream.png"; + if (item.Path.Contains("xml")) + { + RadioStation radio = new RadioStation(); - if (item.Path.Contains("xml")) - { - RadioStation radio = new RadioStation(); + try + { + XmlDocument doc = new XmlDocument(); + doc.Load(item.Path); - try - { - XmlDocument doc = new XmlDocument(); - doc.Load(item.Path); + string path = Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config); + path += "\\Thumbs\\Radio\\"; - string path = Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config); - path += "\\Thumbs\\Radio\\"; + string img = path + doc.SelectSingleNode("/profile/station/logo").InnerText; - string img = path + doc.SelectSingleNode("/profile/station/logo").InnerText; + item.IconImageBig = img; + item.IconImage = img; + item.ThumbnailImage = img; - item.IconImageBig = img; - item.IconImage = img; - item.ThumbnailImage = img; + radio.URL = doc.SelectSingleNode("/profile/stream/url").InnerText; + radio.Name = doc.SelectSingleNode("/profile/station/name").InnerText.ToLower(); + radio.Sort = i; - radio.URL = doc.SelectSingleNode("/profile/stream/url").InnerText; - radio.Name = doc.SelectSingleNode("/profile/station/name").InnerText.ToLower(); - radio.Sort = i; + radio.Genre = doc.SelectSingleNode("/profile/station/category").InnerText.ToLower(); + radio.Language = doc.SelectSingleNode("/profile/station/language").InnerText.ToLower(); - radio.Genre = doc.SelectSingleNode("/profile/station/category").InnerText.ToLower(); - radio.Language = doc.SelectSingleNode("/profile/station/language").InnerText.ToLower(); + item.MusicTag = radio; - item.MusicTag = radio; + // make sure to use the name from the xml + item.Label = doc.SelectSingleNode("/profile/station/name").InnerText; - // make sure to use the name from the xml - item.Label = doc.SelectSingleNode("/profile/station/name").InnerText; + facadeView.Add(item); + totalItems++; + i++; + } + catch (Exception ex) + { + Log.Error("Streamradio: Error reading xml " + item.Path); + Log.Error("Streamradio: Reason : " + ex.Message); + } + } - facadeView.Add(item); - totalItems++; - i++; - } - catch (Exception ex) - { - Log.Error("Streamradio: Error reading xml " + item.Path); - Log.Error("Streamradio: Reason : " + ex.Message); - } - } + } + else + { + // add folder + if (item.Label.Equals("..")) + { // not on top folder + if (folderName == RootRadioFolder) continue; + } + facadeView.Add(item); + totalItems++; + } - } - else - { - // add folder - if (item.Label.Equals("..")) - { // not on top folder - if (folderName == currentRadioFolder) continue; } - facadeView.Add(item); - totalItems++; - } - + #endregion } - #endregion - } - else - { - if (folderName == "Shoutcast") + else { - #region shoutcast genre - aItem = new GUIListItem(); - aItem.Label = ".."; - aItem.Path = currentRadioFolder; - aItem.IsFolder = true; - aItem.MusicTag = null; - aItem.IconImageBig = "defaultFolderBackBig.png"; - aItem.IconImage = "defaultFolderBack.png"; + if (networks.Select(n => n.name).Contains(folderName)) + { + aItem = new GUIListItem(); + aItem.Label = ".."; + aItem.Path = RootRadioFolder; - facadeView.Add(aItem); - totalItems++; + aItem.IsFolder = true; + aItem.MusicTag = null; + aItem.IconImageBig = "defaultFolderBackBig.png"; + aItem.IconImage = "defaultFolderBack.png"; - try - { - XmlDocument doc = new XmlDocument(); - doc.Load("http://yp.shoutcast.com/sbin/newxml.phtml"); - XmlNodeList list = doc.GetElementsByTagName("genre"); + facadeView.Add(aItem); + totalItems++; - for (int i = 0; i < list.Count; i++) - { - string s = list[i].Attributes[0].Value; + List<AudioAddictAPI.AAChannel> aaChannels = AudioAddictAPI.GetChannels(folderName); + foreach (AudioAddictAPI.AAChannel aaCh in aaChannels) + { + AudioAddictAPI.AANetwork network = networks.First(n => n.name == folderName); + AudioAddictAPI.RadioNetwork nw = new AudioAddictAPI.RadioNetwork { ListenURL = network.listen_url, Key = network.key, Name = network.name }; + AudioAddictAPI.AAChannelInfo ai = AudioAddictAPI.GetChannelInfo(aaCh, nw); + GUIListItem aaItem = new GUIListItem(); + aaItem.Label = aaCh.name; + aaItem.MusicTag = aaCh; + aaItem.IconImageBig = ai.LocalImage; + aaItem.IconImage = ai.LocalImage; + facadeView.Add(aaItem); + totalItems++; + //aaItem.Dispose(); - aItem = new GUIListItem(); - aItem.Label = s; - aItem.Path = "Shoutcast/" + s; - aItem.IsFolder = true; + } - aItem.MusicTag = null; - aItem.IconImageBig = "defaultFolderBig.png"; - aItem.IconImage = "defaultFolder.png"; - facadeView.Add(aItem); - totalItems++; - } - } - catch - { - } - #endregion - } - if ((folderName != "Shoutcast") && folderName.Contains("Shoutcast")) - { - #region shoutcast channels - if (folderName.Length > 10) - { - aItem = new GUIListItem(); - aItem.Label = ".."; - aItem.Path = "Shoutcast"; + if (folderName == "Shoutcast") + { + #region shoutcast genre + aItem = new GUIListItem(); + aItem.Label = ".."; + aItem.Path = RootRadioFolder; - aItem.IsFolder = true; - aItem.MusicTag = null; - aItem.IconImageBig = "defaultFolderBackBig.png"; - aItem.IconImage = "defaultFolderBack.png"; + aItem.IsFolder = true; + aItem.MusicTag = null; + aItem.IconImageBig = "defaultFolderBackBig.png"; + aItem.IconImage = "defaultFolderBack.png"; - facadeView.Add(aItem); - totalItems++; + facadeView.Add(aItem); + totalItems++; - string section = folderName.Substring(10, folderName.Length - 10); + try + { + XmlDocument doc = new XmlDocument(); + doc.Load("http://yp.shoutcast.com/sbin/newxml.phtml"); + XmlNodeList list = doc.GetElementsByTagName("genre"); - try - { - XmlDocument doc = new XmlDocument(); - doc.Load("http://yp.shoutcast.com/sbin/newxml.phtml?genre=" + section); - XmlNodeList list = doc.GetElementsByTagName("station"); + for (int i = 0; i < list.Count; i++) + { + string s = list[i].Attributes[0].Value; - for (int i = 0; i < list.Count; i++) - { - string name = list[i].Attributes["name"].Value.ToString(); - string mt = list[i].Attributes["mt"].Value.ToString(); - string id = list[i].Attributes["id"].Value.ToString(); - string br = list[i].Attributes["br"].Value.ToString(); - string genre = list[i].Attributes["genre"].Value.ToString(); + aItem = new GUIListItem(); + aItem.Label = s; + aItem.Path = "Shoutcast/" + s; + aItem.IsFolder = true; - // get bitrate - int bitrate = 0; - try + aItem.MusicTag = null; + aItem.IconImageBig = "defaultFolderBig.png"; + aItem.IconImage = "defaultFolder.png"; + + facadeView.Add(aItem); + totalItems++; + + } + } + catch { - bitrate = Convert.ToInt32(br); + } - catch { } - - if (bitrate >= filter) + #endregion + } + if ((folderName != "Shoutcast") && folderName.Contains("Shoutcast")) + { + #region shoutcast channels + if (folderName.Length > 10) { - aItem = new GUIListItem(); + aItem = new GUIListItem(); + aItem.Label = ".."; + aItem.Path = "Shoutcast"; - aItem.Label = name; - aItem.Path = "http://yp.shoutcast.com/sbin/tunein-station.pls?id=" + id; - aItem.IsFolder = false; + aItem.IsFolder = true; + aItem.MusicTag = null; + aItem.IconImageBig = "defaultFolderBackBig.png"; + aItem.IconImage = "defaultFolderBack.png"; - RadioStation radio = new RadioStation(); - radio.BitRate = bitrate; - radio.Genre = genre; - radio.ID = Convert.ToInt32(id); - radio.Name = name; - radio.URL = aItem.Path; - radio.Sort = i; + facadeView.Add(aItem); + totalItems++; - aItem.MusicTag = radio; - aItem.IconImageBig = "DefaultMyradioStreamBig.png"; - aItem.IconImage = "DefaultMyradioStream.png"; + string section = folderName.Substring(10, folderName.Length - 10); - facadeView.Add(aItem); - totalItems++; + try + { + XmlDocument doc = new XmlDocument(); + doc.Load("http://yp.shoutcast.com/sbin/newxml.phtml?genre=" + section); + XmlNodeList list = doc.GetElementsByTagName("station"); + + for (int i = 0; i < list.Count; i++) + { + string name = list[i].Attributes["name"].Value.ToString(); + string mt = list[i].Attributes["mt"].Value.ToString(); + string id = list[i].Attributes["id"].Value.ToString(); + string br = list[i].Attributes["br"].Value.ToString(); + string genre = list[i].Attributes["genre"].Value.ToString(); + + // get bitrate + int bitrate = 0; + try + { + bitrate = Convert.ToInt32(br); + } + catch { } + + if (bitrate >= filter) + { + aItem = new GUIListItem(); + + aItem.Label = name; + aItem.Path = "http://yp.shoutcast.com/sbin/tunein-station.pls?id=" + id; + aItem.IsFolder = false; + + RadioStation radio = new RadioStation(); + radio.BitRate = bitrate; + radio.Genre = genre; + radio.ID = Convert.ToInt32(id); + radio.Name = name; + radio.URL = aItem.Path; + radio.Sort = i; + + aItem.MusicTag = radio; + aItem.IconImageBig = "DefaultMyradioStreamBig.png"; + aItem.IconImage = "DefaultMyradioStream.png"; + + facadeView.Add(aItem); + totalItems++; + } + } + } + catch + { + // doc not loaded ? + } } - } + #endregion } - catch + if (folderName.Contains("Icecast")) { - // doc not loaded ? - } - } - #endregion - } - if (folderName.Contains("Icecast")) - { - #region icecast channels + #region icecast channels - aItem = new GUIListItem(); - aItem.Label = ".."; - aItem.Path = currentRadioFolder; + aItem = new GUIListItem(); + aItem.Label = ".."; + aItem.Path = RootRadioFolder; - aItem.IsFolder = true; - aItem.MusicTag = null; - aItem.IconImageBig = "defaultFolderBackBig.png"; - aItem.IconImage = "defaultFolderBack.png"; + aItem.IsFolder = true; + aItem.MusicTag = null; + aItem.IconImageBig = "defaultFolderBackBig.png"; + aItem.IconImage = "defaultFolderBack.png"; - facadeView.Add(aItem); - totalItems++; + facadeView.Add(aItem); + totalItems++; - try - { - XmlDocument doc = new XmlDocument(); - doc.Load("http://dir.xiph.org/yp.xml"); - XmlNodeList list = doc.GetElementsByTagName("entry"); + try + { + XmlDocument doc = new XmlDocument(); + doc.Load("http://dir.xiph.org/yp.xml"); + XmlNodeList list = doc.GetElementsByTagName("entry"); - for (int i = 0; i < list.Count; i++) - { - string name = string.Empty; - string br = string.Empty; - string url = string.Empty; - string genre = string.Empty; + for (int i = 0; i < list.Count; i++) + { + string name = string.Empty; + string br = string.Empty; + string url = string.Empty; + string genre = string.Empty; - XmlNode node = list[i]; - foreach (XmlNode child in node) - { - if (child.Name == "server_name") name = child.InnerText; - if (child.Name == "bitrate") br = child.InnerText; - if (child.Name == "genre") genre = child.InnerText; - if (child.Name == "listen_url") url = child.InnerText; - } + XmlNode node = list[i]; + foreach (XmlNode child in node) + { + if (child.Name == "server_name") name = child.InnerText; + if (child.Name == "bitrate") br = child.InnerText; + if (child.Name == "genre") genre = child.InnerText; + if (child.Name == "listen_url") url = child.InnerText; + } - // get bitrate - int bitrate = 0; - try - { - bitrate = Convert.ToInt32(br); - } - catch { } + // get bitrate + int bitrate = 0; + try + { + bitrate = Convert.ToInt32(br); + } + catch { } - if (bitrate >= filter) - { - aItem = new GUIListItem(); + if (bitrate >= filter) + { + aItem = new GUIListItem(); - aItem.Label = name; - aItem.Path = url; - aItem.IsFolder = false; + aItem.Label = name; + aItem.Path = url; + aItem.IsFolder = false; - RadioStation radio = new RadioStation(); + RadioStation radio = new RadioStation(); - radio.BitRate = bitrate; - radio.Genre = genre; - radio.ID = i; - radio.Name = name; - radio.URL = aItem.Path; - radio.Sort = i; + radio.BitRate = bitrate; + radio.Genre = genre; + radio.ID = i; + radio.Name = name; + radio.URL = aItem.Path; + radio.Sort = i; - aItem.MusicTag = radio; - aItem.IconImageBig = "DefaultMyradioStreamBig.png"; - aItem.IconImage = "DefaultMyradioStream.png"; + aItem.MusicTag = radio; + aItem.IconImageBig = "DefaultMyradioStreamBig.png"; + aItem.IconImage = "DefaultMyradioStream.png"; - facadeView.Add(aItem); - totalItems++; - } + facadeView.Add(aItem); + totalItems++; + } + } + } + catch + { + // doc not loaded ? + } } - } - catch - { - // doc not loaded ? - } + #endregion } - #endregion - } } SwitchView(); @@ -1507,104 +1578,104 @@ #endregion } - private void OnRecord() - { - if (StreamradioIsPlaying()) - { - if (!engine.Contains("BASS")) - { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); - dlg.SetHeading("BASS engine is not active !"); - dlg.SetLine(1, "Recording is not possible !"); - dlg.SetLine(2, "Activate BASS engine under Music /"); - dlg.SetLine(3, "Player Settings."); - dlg.DoModal(GUIWindowManager.ActiveWindow); - } - else - { - if ((g_Player.Playing) && (!g_Player.CurrentFile.StartsWith(Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config)))) - { - int _stream = (int)MediaPortal.Visualization.VisualizationBase.Bass.CurrentAudioStream; + //private void OnRecord() + //{ + // if (StreamradioIsPlaying()) + // { + // if (!engine.Contains("BASS")) + // { + // GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); + // dlg.SetHeading("BASS engine is not active !"); + // dlg.SetLine(1, "Recording is not possible !"); + // dlg.SetLine(2, "Activate BASS engine under Music /"); + // dlg.SetLine(3, "Player Settings."); + // dlg.DoModal(GUIWindowManager.ActiveWindow); + // } + // else + // { + // if ((g_Player.Playing) && (!g_Player.CurrentFile.StartsWith(Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Config)))) + // { + // int _stream = (int)MediaPortal.Visualization.VisualizationBase.Bass.CurrentAudioStream; - if (_stream != 0) - { - if (!EncodeActive()) - { - Log.Debug("MyStreamRadio | start recording"); + // if (_stream != 0) + // { + // if (!EncodeActive()) + // { + // Log.Debug("MyStreamRadio | start recording"); - #region build file name - string[] now = actualStation.Split('|'); - if (now.Length != 3) return; + // #region build file name + // string[] now = actualStation.Split('|'); + // if (now.Length != 3) return; - string fName = now[0]; - string url = now[1]; - string file = now[2]; + // string fName = now[0]; + // string url = now[1]; + // string file = now[2]; - Regex regex = new Regex(@"[\\/:*?<>|\b]"); - fName = regex.Replace(fName, "_"); - fName = fName.Replace(' ', '_'); - fName = fName.Replace('.', '_'); - fName = fName.Replace('!', '_'); - fName = fName.Replace('"', '_'); - fName = fName.Replace('\'', '_'); - fName = fName.Replace('*', '_'); + // Regex regex = new Regex(@"[\\/:*?<>|\b]"); + // fName = regex.Replace(fName, "_"); + // fName = fName.Replace(' ', '_'); + // fName = fName.Replace('.', '_'); + // fName = fName.Replace('!', '_'); + // fName = fName.Replace('"', '_'); + // fName = fName.Replace('\'', '_'); + // fName = fName.Replace('*', '_'); - if (!recordFolder.EndsWith("\\")) - recordFolder = recordFolder + "\\"; + // if (!recordFolder.EndsWith("\\")) + // recordFolder = recordFolder + "\\"; - string name = fName + "_"; + // string name = fName + "_"; - name += DateTime.Now.Year.ToString() + "_"; - name += string.Format("{0:00}", DateTime.Now.Month) + "_"; - name += string.Format("{0:00}", DateTime.Now.Day) + "_"; + // name += DateTime.Now.Year.ToString() + "_"; + // name += string.Format("{0:00}", DateTime.Now.Month) + "_"; + // name += string.Format("{0:00}", DateTime.Now.Day) + "_"; - name += string.Format("{0:00}", DateTime.Now.Hour); - name += string.Format("{0:00}", DateTime.Now.Minute); + // name += string.Format("{0:00}", DateTime.Now.Hour); + // name += string.Format("{0:00}", DateTime.Now.Minute); - name = name.Replace('.', '_'); - name = name.Replace(':', '_'); + // name = name.Replace('.', '_'); + // name = name.Replace(':', '_'); - #endregion + // #endregion - string recordFile = recordFolder + name + ".mp3"; - Log.Debug("MyStreamRadio | record file : " + recordFile); + // string recordFile = recordFolder + name + ".mp3"; + // Log.Debug("MyStreamRadio | record file : " + recordFile); - lame = new EncoderLAME(_stream); - lame.InputFile = null; - lame.OutputFile = recordFile; - lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192; - lame.LAME_Mode = EncoderLAME.LAMEMode.Default; - lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100; - lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality; + // lame = new EncoderLAME(_stream); + // lame.InputFile = null; + // lame.OutputFile = recordFile; + // lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192; + // lame.LAME_Mode = EncoderLAME.LAMEMode.Default; + // lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100; + // lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality; - bool result = lame.Start(null, IntPtr.Zero, false); + // bool result = lame.Start(null, IntPtr.Zero, false); - if (result == true) - { - Log.Debug("MyStreamRadio | recording works"); - } - else - { - Log.Debug("MyStreamRadio | recording did NOT work"); - lame.Stop(); - } - } - else - { - Log.Debug("MyStreamRadio | stop recording"); - lame.Stop(); - } - } - else - { - Log.Debug("MyStreamRadio | no stream found !"); - // no stream - } - } - } - } - btnRecord.Selected = EncodeActive(); - } + // if (result == true) + // { + // Log.Debug("MyStreamRadio | recording works"); + ... [truncated message content] |