Ejemplo n.º 1
0
 protected void ClearInternalVariables()
 {
     _currentFileName = string.Empty;
     _currentItem     = null;
     _nowPlaying      = null;
     _station         = null;
 }
Ejemplo n.º 2
0
 public string GetStationLogoFileName(RadioTimeOutline radioItem)
 {
     if (string.IsNullOrEmpty(radioItem.Image))
     {
         return(string.Empty);
     }
     return(Utils.GetCoverArtName(Thumbs.Radio, radioItem.Text));
 }
Ejemplo n.º 3
0
        private void DoListSelection()
        {
            ShowWaitCursor();
            try
            {
                GUIListItem selectedItem = listControl.SelectedListItem;
                if (selectedItem != null)
                {
                    if (selectedItem.Label != "..")
                    {
                        RadioTimeOutline radioItem = ((RadioTimeOutline)selectedItem.MusicTag);
                        switch (radioItem.Type)
                        {
                        case RadioTimeOutline.OutlineType.link:
                            if (string.IsNullOrEmpty(radioItem.Url) && !string.IsNullOrEmpty(radioItem.GuidId))
                            {
                                grabber.GetData(string.Format("http://opml.radiotime.com/Browse.ashx?id={0}&{1}", radioItem.GuidId,
                                                              grabber.Settings.GetParamString()), selectedItem.Label);
                            }
                            else if (!string.IsNullOrEmpty(radioItem.Url))
                            {
                                grabber.GetData(radioItem.Url, selectedItem.Label);
                            }
                            UpdateList();
                            break;

                        case RadioTimeOutline.OutlineType.audio:
                            DoPlay(radioItem);
                            break;

                        default:
                            if (string.IsNullOrEmpty(radioItem.Url) && !string.IsNullOrEmpty(radioItem.GuidId))
                            {
                                grabber.GetData(string.Format("http://opml.radiotime.com/Browse.ashx?id={0}&{1}", radioItem.GuidId,
                                                              grabber.Settings.GetParamString()), selectedItem.Label);
                                UpdateList();
                            }
                            else if (!string.IsNullOrEmpty(radioItem.Url))
                            {
                                grabber.GetData(radioItem.Url, selectedItem.Label);
                                UpdateList();
                            }
                            break;
                        }
                    }
                    else
                    {
                        DoBack();
                        //grabber.Prev();
                        //UpdateList();
                    }
                }
            }
            finally
            {
                HideWaitCursor();
            }
        }
Ejemplo n.º 4
0
        public void UpdateGui()
        {
            GUIListItem selectedItem = listControl.SelectedListItem;

            if (selectedItem != null)
            {
                if (selectedItem.MusicTag != null)
                {
                    RadioTimeOutline radioItem = ((RadioTimeOutline)selectedItem.MusicTag);
                    SetProperty("#selectedthumb", " ");
                    logoImage.SetFileName("");
                    Process();
                    SetProperty("#selectedthumb", selectedItem.IconImageBig);
                    logoImage.SetFileName(DownloadStationLogo(radioItem));

                    UpdateSelectedLabels(radioItem);
                }
                else
                {
                    logoImage.SetFileName(string.Empty);
                    GUIPropertyManager.SetProperty("#RadioTime.Selected.NowPlaying", " ");
                    GUIPropertyManager.SetProperty("#RadioTime.Selected.Subtext", " ");
                    GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", " ");
                    GUIPropertyManager.SetProperty("#RadioTime.Selected.Reliability", "0");
                }
            }

            string textLine = string.Empty;
            View   view     = (View)mapSettings.ViewAs;
            bool   sortAsc  = mapSettings.SortAscending;

            switch (view)
            {
            case View.List:
                textLine = GUILocalizeStrings.Get(101);
                break;

            case View.Icons:
                textLine = GUILocalizeStrings.Get(100);
                break;

            case View.BigIcons:
                textLine = GUILocalizeStrings.Get(417);
                break;

            case View.Albums:
                textLine = GUILocalizeStrings.Get(529);
                break;

            case View.Filmstrip:
                textLine = GUILocalizeStrings.Get(733);
                break;
            }

            GUIControl.SetControlLabel(GetID, btnSwitchView.GetID, textLine);
        }
Ejemplo n.º 5
0
        private string DownloadFile(RadioTimeOutline radioItem)
        {
            string localFile = GetLocalImageFileName(radioItem.Image.Replace("q.png", ".png"));

            if (!File.Exists(localFile) && !string.IsNullOrEmpty(radioItem.Image))
            {
                downloaQueue.Enqueue(new DownloadFileObject(localFile, radioItem.Image.Replace("q.png", ".png")));
            }
            return(localFile);
        }
Ejemplo n.º 6
0
        public string DownloadStationLogo(RadioTimeOutline radioItem)
        {
            var localFile = GetStationLogoFileName(radioItem);

            if (!File.Exists(localFile) && !string.IsNullOrEmpty(radioItem.Image))
            {
                downloaQueue.Enqueue(new DownloadFileObject(localFile, radioItem.Image.Replace("q.png", ".png")));
            }
            return(localFile);
        }
Ejemplo n.º 7
0
        void item_OnRetrieveArt(GUIListItem item)
        {
            RadioTimeOutline tag = item.MusicTag as RadioTimeOutline;

            if (tag != null)
            {
                string file = GetLocalImageFileName(tag.Image.Replace("q.png", ".png"));
                if (File.Exists(file))
                {
                    item.IconImageBig = file;
                    item.IconImage    = file;
                }
            }
        }
Ejemplo n.º 8
0
        public void UpdateSelectedLabels(RadioTimeOutline radioItem)
        {
            GUIPropertyManager.SetProperty("#RadioTime.Selected.NowPlaying", radioItem.CurrentTrack);
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Subtext", radioItem.Subtext);
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Reliability", (radioItem.ReliabilityIdAsInt / 10).ToString());

            GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", " ");
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", DownloadStationLogo(radioItem));

            if (_setting.FormatNames.ContainsKey(radioItem.Formats))
            {
                GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", _setting.FormatNames[radioItem.Formats]);
            }
            else
            {
                GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", " ");
            }
            Process();
        }
Ejemplo n.º 9
0
        protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
        {
            if (control == facadeSimilar)
            {
                GUIListItem selectedItem = facadeSimilar.SelectedListItem;
                ShowWaitCursor();
                try
                {
                    if (selectedItem != null)
                    {
                        RadioTimeOutline radioItem = ((RadioTimeOutline)selectedItem.MusicTag);
                        if (radioItem != null)
                        {
                            DoPlay(radioItem);
                            Refresh();
                        }
                    }
                }
                finally
                {
                    HideWaitCursor();
                }
            }

            if (control == facadeGenres)
            {
                GUIListItem selectedItem = facadeGenres.SelectedListItem;
                if (selectedItem != null)
                {
                    RadioTimeOutline radioItem = ((RadioTimeOutline)selectedItem.MusicTag);
                    if (radioItem != null)
                    {
                        Settings.GuideId            = radioItem.GuidId;
                        Settings.GuideIdDescription = Translation.Genres + ": " + selectedItem.Label;
                        GUIWindowManager.ActivateWindow(25650);
                    }
                }
            }
            base.OnClicked(controlId, control, actionType);
        }
Ejemplo n.º 10
0
        public void UpdateSelectedLabels(RadioTimeOutline radioItem)
        {
            GUIPropertyManager.SetProperty("#RadioTime.Selected.NowPlaying", radioItem.CurrentTrack);
            string subtext = radioItem.Subtext;

            if (GUIPropertyManager.GetProperty("#RadioTime.Play.HasSong").Equals("true"))
            {
                PlayGuidId = (string.IsNullOrEmpty(PlayGuidId)) ? GUIPropertyManager.GetProperty("#RadioTime.Play.GuidId") : PlayGuidId;
                if (!string.IsNullOrEmpty(PlayGuidId) && radioItem.GuidId.Equals(PlayGuidId))
                {
                    string artist = GUIPropertyManager.GetProperty("#Play.Current.Artist");
                    // string album = GUIPropertyManager.GetProperty("#Play.Current.Album");
                    string track = GUIPropertyManager.GetProperty("#Play.Current.Title");
                    if (!string.IsNullOrEmpty(artist))
                    {
                        // subtext = string.Empty + artist + (!string.IsNullOrEmpty(album) ? " - " : "") + album + (!string.IsNullOrEmpty(track) ? " - " : "") + track; // FH not compatible with Artist - Album - Track
                        subtext = string.Empty + artist + (!string.IsNullOrEmpty(track) ? " - " : "") + track;
                    }
                }
            }
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Subtext", subtext);
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Reliability", (radioItem.ReliabilityIdAsInt / 10).ToString());

            GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", string.Empty);
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", DownloadStationLogo(radioItem));

            if (_setting.FormatNames.ContainsKey(radioItem.Formats))
            {
                GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", _setting.FormatNames[radioItem.Formats]);
            }
            else
            {
                GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", string.Empty);
            }
            Process();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Does the play.
        /// </summary>
        /// <param name="item">The item.</param>
        public void DoPlay(RadioTimeOutline item)
        {
            ShowWaitCursor();
            try
            {
                _station     = null;
                _nowPlaying  = null;
                _show        = null;
                _currentItem = null;

                if (item == null || string.IsNullOrEmpty(item.GuidId))
                {
                    ErrMessage(Translation.StationNotAvaiable);
                    return;
                }
                PlayGuidId   = item.GuidId;
                _currentItem = item.Clone();

                //RadioTimeStation station = Settings.NowPlayingStation;
                _station         = new RadioTimeStation();
                _station.Grabber = grabber;
                _station.Get(PlayGuidId);

                if (_station.IsAvailable)
                {
                    //var nowPlaying = Settings.NowPlaying;
                    _nowPlaying         = new RadioTimeNowPlaying();
                    _nowPlaying.Grabber = grabber;
                    _nowPlaying.Get(PlayGuidId, _station.HasSong);

                    if (_nowPlaying.IsShow && !string.IsNullOrEmpty(_nowPlaying.ShowGuidId))
                    {
                        _show         = new RadioTimeShow();
                        _show.Grabber = grabber;
                        _show.Get(_nowPlaying.ShowGuidId);
                    }

                    var playerType = PlayerType.Video;
                    if (_setting.FormatPlayer.ContainsKey(item.Formats))
                    {
                        playerType = _setting.FormatPlayer[item.Formats];
                    }

                    try
                    {
                        var playList = new PlayList();
                        //if (item.Url.ToLower().Contains(".pls") || item.Url.ToLower().Contains(".m3u") || item.Url.ToLower().Contains(".asx"))
                        {
                            var TargetFile = Path.GetTempFileName();
                            var client     = new WebClient();
                            try
                            {
                                if (item.Url.ToLower().Contains(".pls"))
                                {
                                    client.DownloadFile(item.Url, TargetFile);
                                    IPlayListIO loader = new PlayListPLSEIO();
                                    loader.Load(playList, TargetFile);
                                }
                                else if (item.Url.ToLower().Contains(".asx"))
                                {
                                    client.DownloadFile(item.Url, TargetFile);
                                    IPlayListIO loader = new PlayListASXIO();
                                    loader.Load(playList, TargetFile);
                                }
                                else
                                {
                                    client.DownloadFile(item.Url, TargetFile);
                                    IPlayListIO loader = new PlayListM3uIO();
                                    loader.Load(playList, TargetFile);
                                }
                            }
                            finally
                            {
                                client.Dispose();
                                File.Delete(TargetFile);
                            }

                            //if (playList.Count > 0 && playList[0].FileName.ToLower().StartsWith("http") && playList[0].FileName.ToLower().Contains(".m3u"))
                            //{
                            //  client.DownloadFile(playList[0].FileName, TargetFile);
                            //  IPlayListIO loader1 = new PlayListM3uIO();
                            //  loader1.Load(playList, TargetFile);
                            //  File.Delete(TargetFile);
                            //}

                            TargetFile = Path.GetTempFileName();
                            client     = new WebClient();
                            try
                            {
                                if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".pls"))
                                {
                                    client.DownloadFile(playList[0].FileName, TargetFile);
                                    IPlayListIO loader1 = new PlayListPLSEIO();
                                    loader1.Load(playList, TargetFile);
                                }

                                if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".asx"))
                                {
                                    client.DownloadFile(playList[0].FileName, TargetFile);
                                    IPlayListIO loader1 = new PlayListASXIO();
                                    loader1.Load(playList, TargetFile);
                                }

                                if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".m3u"))
                                {
                                    client.DownloadFile(playList[0].FileName, TargetFile);
                                    IPlayListIO loader1 = new PlayListM3uIO();
                                    loader1.Load(playList, TargetFile);
                                    if (playList.Count == 0)
                                    {
                                        IPlayListIO loader2 = new PlayListPLSEIO();
                                        loader2.Load(playList, TargetFile);
                                    }
                                }
                            }
                            finally
                            {
                                client.Dispose();
                                File.Delete(TargetFile);
                            }
                        }

                        if (playList.Count > 0)
                        {
                            _currentFileName = playList[0].FileName;
                        }
                        else
                        {
                            _currentFileName = item.Url;
                        }

                        switch (playerType)
                        {
                        case PlayerType.Audio:
                            ClearPlayProps();
                            g_Player.PlayAudioStream(_currentFileName);
                            return;

                        case PlayerType.Video:
                            // test if the station have tv group
                            ClearPlayProps();
                            if (item.GenreId == "g260" || item.GenreId == "g83" || item.GenreId == "g374" ||
                                item.GenreId == "g2769")
                            {
                                g_Player.PlayVideoStream(_currentFileName);
                            }
                            else
                            {
                                g_Player.Play(_currentFileName, g_Player.MediaType.Unknown);
                            }
                            return;

                        case PlayerType.Unknow:
                            return;

                        default:
                            return;
                        }
                        // moved to PLAYBACKSTARTED EVENT
                        //if  (isPlaying && g_Player.CurrentFile == playList[0].FileName)
                    }
                    catch (Exception exception)
                    {
                        _currentItem = null;
                        ErrMessage(string.Format(Translation.PlayError, exception.Message));
                        return;
                    }
                }
            }
            finally
            {
                HideWaitCursor();
            }
            ErrMessage(Translation.StationNotAvaiable);
            return;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds to favorites.
        /// </summary>
        /// <param name="p">The station id.</param>
        private void AddToFavorites(string presetid)
        {
            List <RadioTimeOutline> tempresets = new List <RadioTimeOutline>();

            string    folderid    = "";
            string    selectedID  = "";
            RadioTime tempGrabber = new RadioTime();

            tempGrabber.Settings = _setting;
            tempGrabber.GetData(_setting.PresetsUrl, false, false, Translation.Presets);

            int folderCount = 0;

            foreach (RadioTimeOutline body in tempGrabber.Body)
            {
                if (body.Type == RadioTimeOutline.OutlineType.link)
                {
                    folderCount++;
                }
            }

            if (folderCount == 0) // only one preset folder (main) - plugin chooses first empty space to put preset
            {
                // first i have to fill the list with taken preset numbers
                List <int> takenPresets = new List <int>();
                foreach (RadioTimeOutline body in tempGrabber.Body)
                {
                    if (!string.IsNullOrEmpty(body.PresetNumber))
                    {
                        takenPresets.Add(body.PresetNumberAsInt);
                    }
                }

                int i = 1;
                while (takenPresets.Contains(i)) // find empty space
                {
                    i++;
                }

                selectedID = i.ToString();
            }
            else // more folders - ask user
            {
                var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
                if (dlg == null)
                {
                    return;
                }
                dlg.Reset();
                dlg.SetHeading(Translation.SelectPresetFolder);

                foreach (RadioTimeOutline body in tempGrabber.Body)
                {
                    if (body.Type == RadioTimeOutline.OutlineType.link)
                    {
                        dlg.Add(body.Text);
                    }
                }

                dlg.DoModal(GetID);
                if (dlg.SelectedId == -1)
                {
                    return;
                }
                folderid = tempGrabber.Body[dlg.SelectedId - 1].GuidId;

                tempGrabber.GetData(tempGrabber.Body[dlg.SelectedId - 1].Url, false, false);

                // first i have to find out the largest preset number
                int biggestPresetNumber = 0;
                foreach (RadioTimeOutline body in tempGrabber.Body)
                {
                    if (!string.IsNullOrEmpty(body.PresetNumber) && body.PresetNumberAsInt > biggestPresetNumber)
                    {
                        biggestPresetNumber = body.PresetNumberAsInt;
                    }
                }

                // then i fill x number of presets
                for (int i = 0; i < (biggestPresetNumber + Settings.LOCAL_PRESETS_NUMBER); i++)
                {
                    tempresets.Add(new RadioTimeOutline());
                }

                // then i fill the list with existing presets from the folder
                foreach (RadioTimeOutline body in tempGrabber.Body)
                {
                    if (!string.IsNullOrEmpty(body.PresetNumber) && body.PresetNumberAsInt - 1 < tempresets.Count)
                    {
                        tempresets[body.PresetNumberAsInt - 1] = body;
                    }
                }

                dlg.Reset();
                dlg.SetHeading(Translation.SelectPresetNumber);

                for (int i = 0; i < tempresets.Count; i++)
                {
                    RadioTimeOutline outline = tempresets[i];
                    if (string.IsNullOrEmpty(outline.Text))
                    {
                        dlg.Add(string.Format("<{0}>", Translation.Empty));
                    }
                    else
                    {
                        dlg.Add(outline.Text);
                    }
                }

                dlg.DoModal(GetID);

                if (dlg.SelectedId == -1)
                {
                    return;
                }

                selectedID = dlg.SelectedId.ToString();
            }

            try
            {
                grabber.AddPreset(presetid, folderid, selectedID);
                //UpdateList();
            }
            catch (Exception)
            {
                ErrMessage(Translation.ComunicationError);
            }
        }
Ejemplo n.º 13
0
        public void UpdateList()
        {
            int grabberIndex = 0;

            updateStationLogoTimer.Enabled = false;
            downloaQueue.Clear();
            GUIControl.ClearControl(GetID, listControl.GetID);
            if (grabber.Parent != null && grabber.Parent.Body.Count > 0)
            {
                GUIListItem item = new GUIListItem();
                // and add station name & bitrate
                item.Label           = "..";
                item.Label2          = "(" + grabber.Parent.Body.Count.ToString() + ")";
                item.OnItemSelected += item_OnItemSelected;
                item.IsFolder        = true;
                item.IconImage       = "defaultFolderBack.png";
                item.IconImageBig    = "DefaultFolderBackBig.png";
                item.MusicTag        = null;
                listControl.Add(item);
            }
            RadioTimeOutline selected = null;

            foreach (RadioTimeOutline body in grabber.Body)
            {
                if (null != grabber.Selected && null != body && null == selected &&
                    (
                        (null != body.Url && body.Url.Equals((string)grabber.Selected, StringComparison.InvariantCultureIgnoreCase)) ||
                        (!string.IsNullOrEmpty(body.GuidId) && ((string)grabber.Selected).ToUpperInvariant().Contains(body.GuidId.ToUpperInvariant()))
                    )
                    )
                {
                    selected = body;
                }
                GUIListItem item = new GUIListItem();
                // and add station name & bitrate
                item.Label           = body.Text;
                item.Label2          = body.Bitrate;
                item.ThumbnailImage  = GetStationLogoFileName(body);
                item.IconImage       = GetStationLogoFileName(body);
                item.IsFolder        = false;
                item.OnItemSelected += item_OnItemSelected;
                item.MusicTag        = body;
                listControl.Add(item);
                DownloadStationLogo(body);
                switch (body.Type)
                {
                case RadioTimeOutline.OutlineType.audio:
                    if (string.IsNullOrEmpty(item.IconImage))
                    {
                        item.IconImage    = "defaultMyRadio.png";
                        item.IconImageBig = "defaultMyRadioBig.png";
                    }
                    item.IsFolder = false;
                    item.Year     = ++grabberIndex;
                    break;

                case RadioTimeOutline.OutlineType.link:
                    if (string.IsNullOrEmpty(item.IconImage))
                    {
                        item.IconImage    = "defaultFolder.png";
                        item.IconImageBig = "defaultFolderBig.png";
                    }
                    item.IsFolder = true;
                    item.Year     = ++grabberIndex;
                    break;

                case RadioTimeOutline.OutlineType.unknow:
                {
                    item.IconImage    = "defaultFolder.png";
                    item.IconImageBig = "defaultFolderBig.png";
                }
                    item.IsFolder = true;
                    item.Year     = ++grabberIndex;
                    break;

                default:
                    break;
                }
            }

            updateStationLogoTimer.Enabled = true;
            //if (curSorting != StationSort.SortMethod.none)
            listControl.Sort(new StationSort(curSorting, mapSettings.SortAscending));

            int i = 0;

            foreach (GUIListItem item in listControl.ListLayout.ListItems)
            {
                if (item.MusicTag == selected)
                {
                    break;
                }
                i++;
            }
            listControl.SelectedListItemIndex = i;

            GUIPropertyManager.SetProperty("#itemcount", grabber.Body.Count + " " + Translation.Objects);
            //GUIPropertyManager.SetProperty("#header.label", grabber.Head.Title);
            GUIPropertyManager.SetProperty("#header.label", grabber.NavigationTitle);

            if (grabber.CurentUrl.Contains("id="))
            {
                randomButton.Disabled = false;
            }
            else
            {
                randomButton.Disabled = true;
            }

            ShowPanel();
        }