Пример #1
0
        private void browser2_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
        {
            string url = (string)e.uRL;

            Debug.WriteLine("browser2_BeforeNavigate2: " + url);

            try
            {
                if (url.StartsWith("javascript:"))
                {
                    string[] scripts = url.Split(';');

                    foreach (string script in scripts)
                    {
                        if (script.LastIndexOf("PandoraStarted") > 0)
                        {
                            //loaded = true;
                            //loginTime = DateTime.Now;

                            if (pandora == null)
                            {
                                pandora = new Pandora(browser);
                                browserTimer.Start();
                            }
                        }
                        else if (script.LastIndexOf("SongPlayed") > 0)
                        {
                            Debug.WriteLine("Play");

                            const string SONG_NAME_MARK = "songName:unescape";
                            const string ARTIST_NAME_MARK = "artistName:unescape";
                            const string SONG_URL_MARK = "songURL:unescape";
                            const string ART_URL_MARK = "artURL:unescape";
                            const string END_MARK = "}";

                            int songMark = script.IndexOf(SONG_NAME_MARK) + SONG_NAME_MARK.Length;
                            int songMarkLength = script.LastIndexOf(ARTIST_NAME_MARK) - songMark;
                            int artistMark = script.IndexOf(ARTIST_NAME_MARK) + ARTIST_NAME_MARK.Length;
                            int artistMarkLength = script.LastIndexOf(SONG_URL_MARK) - artistMark;
                            int songUrlMark = script.IndexOf(SONG_URL_MARK) + SONG_URL_MARK.Length;
                            int songUrlMarkLength = script.LastIndexOf(ART_URL_MARK) - songUrlMark;
                            int artUrlMark = script.IndexOf(ART_URL_MARK) + ART_URL_MARK.Length;
                            int artUrlMarkLength = script.LastIndexOf(END_MARK) - artUrlMark;

                            string songNamePart = script.Substring(songMark, songMarkLength);
                            string artistNamePart = script.Substring(artistMark, artistMarkLength);
                            string songUrlPart = script.Substring(songUrlMark, songUrlMarkLength);
                            string artUrlPart = script.Substring(artUrlMark, artUrlMarkLength);

                            string songName = songNamePart.Substring(songNamePart.IndexOf("'") + 1, songNamePart.LastIndexOf("'") - songNamePart.IndexOf("'") - 1);
                            string artistName = artistNamePart.Substring(artistNamePart.IndexOf("'") + 1, artistNamePart.LastIndexOf("'") - artistNamePart.IndexOf("'") - 1);
                            string songUrl = songUrlPart.Substring(songNamePart.IndexOf("'") + 1, songUrlPart.LastIndexOf("'") - songUrlPart.IndexOf("'") - 1);
                            string artUrl = artUrlPart.Substring(artUrlPart.IndexOf("'") + 1, artUrlPart.LastIndexOf("'") - artUrlPart.IndexOf("'") - 1);

                            songName = HttpUtility.UrlDecode(songName.Replace("%25%32%37", "%27").Replace("%22", "\"")).Replace("%22", "\"");
                            artistName = HttpUtility.UrlDecode(artistName.Replace("%25%32%37", "%27").Replace("%22", "\"")).Replace("%22", "\"");
                            songUrl = HttpUtility.UrlDecode(songUrl);
                            artUrl = HttpUtility.UrlDecode(artUrl);

                            refreshMessenger = !paused;
                            refreshXfire = !paused;
                            refreshSkype = !paused;
                            refreshG15 = !paused;
                            OnPlayStart();

                            ++continuesPlayCounter;

                            memoryTimer.Interval = MEMORYTIMER_DELAY;
                            memoryTimer.Start();

                            if (taskbarNotifier != null && taskbarNotifier.Visible)
                            {
                                taskbarNotifier.Hide();
                            }

                            if (!paused)
                            {
                                playedLength += (int)(DateTime.Now - playedStartTime).TotalSeconds;

                                SubmitSongToLastFM(song.Artist, song.Name, playedLength);

                                playedLength = 0;
                            }

                            playedStartTime = DateTime.Now;

                            paused = false;

                            song = new Song(string.Empty, songName, artistName, songUrl, artUrl);

                            Debug.WriteLine(song.Name + " ~by~ " + song.Artist);

                            submittedToLastFm = false;
                            menuLastFmSubmit.Enabled = true;

                            RefreshPlayer(true);
                        }
                        else if (script.LastIndexOf("SongPaused") > 0)
                        {
                            Debug.WriteLine("Pause");
                            playedLength += (int)(DateTime.Now - playedStartTime).TotalSeconds;
                            this.menuPlayerPlayPause.Text = "Play";

                            paused = true;
                            refreshMessenger = false;
                            refreshXfire = false;
                            refreshSkype = false;
                            refreshG15 = false;

                            RefreshPlayer(false);

                            memoryTimer.Interval = MEMORYTIMER_PAUSE;
                            memoryTimer.Start();
                        }
                        else if (script.LastIndexOf("StationPlayed") > 0)
                        {
                            const string STATION_NAME_MARK = "stationName:unescape";
                            const string STATION_ID_MARK = "stationId:unescape";
                            const string IS_SHARED_MARK = "isShared:";

                            int stationNameMark = script.IndexOf(STATION_NAME_MARK) + STATION_NAME_MARK.Length;
                            int stationNameMarkLength = script.LastIndexOf(STATION_ID_MARK) - stationNameMark;
                            int stationIdMark = script.IndexOf(STATION_ID_MARK) + STATION_ID_MARK.Length;
                            int stationIdMarkLength = script.LastIndexOf(IS_SHARED_MARK) - stationIdMark;

                            string stationNamePart = script.Substring(stationNameMark, stationNameMarkLength);
                            string stationIdPart = script.Substring(stationIdMark, stationIdMarkLength);

                            string stationName = stationNamePart.Substring(stationNamePart.IndexOf("'") + 1, stationNamePart.LastIndexOf("'") - stationNamePart.IndexOf("'") - 1);
                            string stationIdText = stationIdPart.Substring(stationIdPart.IndexOf("'") + 1, stationIdPart.LastIndexOf("'") - stationIdPart.IndexOf("'") - 1);

                            stationName = HttpUtility.UrlDecode(stationName.Replace("%25%32%37", "%27"));

                            if (currentStationCode != stationIdText)
                            {
                                Station currentStation = null;

                                foreach (Station station in stations)
                                {
                                    if (station.Code.Equals(stationIdText))
                                    {
                                        currentStation = station;
                                        break;
                                    }
                                }

                                if (currentStation != null)
                                {
                                    foreach (MenuItem menuItem in menuPlayerStations.MenuItems)
                                    {
                                        if (menuItem.Text.Equals(currentStation.Name))
                                        {
                                            title = "Playing ... " + currentStation.Name;
                                            ShowMessage(title);
                                            menuItem.Checked = true;
                                        }
                                        else
                                        {
                                            menuItem.Checked = false;
                                        }
                                    }
                                }

                                currentStationCode = stationIdText;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
        }
Пример #2
0
        private void browser2_StatusTextChange(object sender, DWebBrowserEvents2_StatusTextChangeEvent e)
        {
            if (e.text.StartsWith("Pandora222222222222222"))
            {
                IHTMLDocument2 document = (IHTMLDocument2)browser2.Document;

                IHTMLElement songNameElement = (IHTMLElement)document.all.item("songName", 0);
                IHTMLElement artistNameElement = (IHTMLElement)document.all.item("artistName", 0);
                IHTMLElement songURLElement = (IHTMLElement)document.all.item("songURL", 0);
                IHTMLElement artURLElement = (IHTMLElement)document.all.item("artURL", 0);

                IHTMLElement stationNameElement = (IHTMLElement)document.all.item("stationName", 0);
                IHTMLElement stationIdElement = (IHTMLElement)document.all.item("stationId", 0);
                IHTMLElement stationIsSharedElement = (IHTMLElement)document.all.item("stationIsShared", 0);
                IHTMLElement stationIsQuickMixElement = (IHTMLElement)document.all.item("stationIsQuickMix", 0);

                string songName = (songNameElement != null ? songNameElement.innerText : string.Empty);
                string artistName = (artistNameElement != null ? artistNameElement.innerText : string.Empty);
                string songURL = (songURLElement != null ? songURLElement.innerText : string.Empty);
                string artURL = (artURLElement != null ? artURLElement.innerText : string.Empty);

                string stationName = (stationNameElement != null ? stationNameElement.innerText : string.Empty);
                string stationId = (stationIdElement != null ? stationIdElement.innerText : string.Empty);
                string stationIsShared = (stationIsSharedElement != null ? stationIsSharedElement.innerText : string.Empty);
                string stationIsQuickMix = (stationIsQuickMixElement != null ? stationIsQuickMixElement.innerText : string.Empty);

                if (e.text.StartsWith("Pandora.SongPlayed"))
                {
                    if (song.Name == string.Empty)
                    {
                        song.Name = songName;
                        song.Artist = artistName;
                    }
                    else
                    {
                        nextSong = new Song(string.Empty, songName, artistName);
                    }
                }
                else if (e.text.StartsWith("Pandora.StationPlayed"))
                {
                    Debug.WriteLine("Changed station to " + stationName);

                    currentStationCode = stationId;

                    foreach (MenuItem menuItem in menuPlayerStations.MenuItems)
                    {
                        menuItem.Checked = false;
                    }

                    if (bool.Parse(stationIsQuickMix))
                    {
                        menuPlayerStationQuickmix.Checked = true;
                    }
                    else
                    {
                        Station currentStation = null;

                        foreach (Station station in stations)
                        {
                            if (station.Code.Equals(currentStationCode))
                            {
                                currentStation = station;
                                break;
                            }
                        }

                        if (currentStation != null)
                        {
                            foreach (MenuItem menuItem in menuPlayerStations.MenuItems)
                            {
                                if (menuItem.Text.Equals(currentStation.Name))
                                {
                                    menuItem.Checked = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private void RestartPlayer()
        {
            song = new Song(string.Empty, string.Empty, string.Empty);
            paused = false;
            refreshMessenger = true;
            refreshXfire = true;
            refreshSkype = true;
            refreshG15 = true;

            this.menuPlayerPlayPause.Enabled = false;
            this.menuPlayerSkip.Enabled = false;
            this.menuPlayerLike.Enabled = false;
            this.menuPlayerHate.Enabled = false;
            this.menuPlayerStations.Enabled = false;
            this.menuToolsCopyToClipboard.Enabled = false;

            RefreshPlayer(false);
        }