Beispiel #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);
            }
        }
Beispiel #2
0
        private void browser_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
        {
            try
            {
                string urlText = HttpUtility.UrlDecode(e.uRL as string);

                Debug.WriteLine("browser_BeforeNavigate2: " + urlText);

                if (urlText.StartsWith("res://ieframe.dll/navcancl.htm"))
                {
                    textMessageCode = 1;
                    textMessageTimer.Start();
                    e.cancel = true;
                    return;
                }

                try
                {
                    if (!loaded && browserTimer != null)
                    {
                        Debug.WriteLine("Radio: timer");
                        browserTimer.Interval = 10000;
                        browserTimer.Start();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }

                if (PandoraTuner.IsTunerUrl(urlText))
                {
                    PandoraTuner tuner = new PandoraTuner(urlText);

                    if (tuner.ContainsCreateStation ||
                        tuner.ContainsDeleteStation ||
                        tuner.ContainsLogin ||
                        tuner.ContainsOpen ||
                        tuner.ContainsPause ||
                        tuner.ContainsSharedStation ||
                        tuner.ContainsSkip ||
                        tuner.ContainsStation)
                    {
                        continuesPlayCounter = 0;
                    }

                    if ((loginTime - DateTime.Now).TotalHours == 6)
                    {
                        loginTime = DateTime.Now;
                        Manager.Login(listenerID);
                    }

                    if (tuner.ContainsRegistration)
                    {
                        ResizeFromContent(radioSize);
                    }

                    if (tuner.ContainsLogin)
                    {
                        loaded = true;
                        loginTime = DateTime.Now;

                        if (pandora == null)
                        {
                            pandora = new Pandora(browser);
                        }

                        panelBrowser.BringToFront();
                    }

                    if (tuner.ContainsPlay)
                    {
                        /*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;*/
                    }
                    else if (tuner.ContainsPause)
                    {
                        /*playedLength += (int)(DateTime.Now - playedStartTime).TotalSeconds;
                        this.menuPlayerPlayPause.Text = "Play";

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

                        RefreshPlayer(false);

                        memoryTimer.Interval = MEMORYTIMER_PAUSE;
                        memoryTimer.Start();*/
                    }

                    if (tuner.ContainsLogout)
                    {
                        RestartPlayer();
                    }

                    if (tuner.ContainsUser)
                    {
                        authToken = tuner.AuthToken;
                        listenerID = tuner.ListenerID;

                        Manager.Login(listenerID);
                        LoadStations();
                        ResizeFromContent(new Size(radioSize.Width, radioSize.Height - 200));
                    }

                    if (tuner.ContainsCreateStation)
                    {
                        LoadStations();
                    }

                    if (!tuner.ContainsDeleteStation && deleteStation)
                    {
                        if (tuner.ContainsStation)
                        {
                            LoadStations();
                        }

                        deleteStation = false;
                    }

                    if (tuner.ContainsDeleteStation)
                    {
                        deleteStation = true;
                    }

                    if (!tuner.ContainsSharedStation && sharedStation)
                    {
                        if (tuner.ContainsStation)
                        {
                            LoadStations();
                        }

                        sharedStation = false;
                    }

                    if (tuner.ContainsSharedStation)
                    {
                        sharedStation = true;
                    }

                    if (tuner.ContainsAds)
                    {
                        if (isPayingUser != tuner.IsPayingUser)
                        {
                            isPayingUser = tuner.IsPayingUser;

                            configuration.PayingUser = tuner.IsPayingUser;
                            configuration.Save();
                        }
                    }

                    if (tuner.ContainsOpen)
                    {
                        lastBookmark = DateTime.Now;
                    }

                    if (tuner.ContainsSkip)
                    {
                        Debug.WriteLine("Skip");
                    }

                    if (configuration.PartyMode && continuesPlayCounter > 30)
                    {
                        Debug.WriteLine("Party !!!!!!!!!!!!!!!!!");
                        pandora.NextTrack();

                        continuesPlayCounter = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
        }