コード例 #1
0
ファイル: Manager.cs プロジェクト: leetreveil/zuse
        public ZuneManager(Scrobbler scrobbler)
        {
            _currentTrack = new ZuneTrack();
            _trackWatcher = new TrackWatcher();
            var scrobbleManager = new ScrobbleManager(scrobbler);

            _trackWatcher.TrackIsReadyToBeScrobbled += scrobbleManager.Scrobble;
            _trackWatcher.TrackHasStartedPlaying += scrobbleManager.SubmitNowPlaying;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: leetreveil/zuse
        public Program()
        {
            /* Build the context menu for the system tray icon */
            contextMenuStrip = new ContextMenuStrip();

            /* About Zuse system tray menu option */
            var itemAbout = new ToolStripMenuItem("About");
            itemAbout.Click += delegate { new FrmAbout().ShowDialog(); };
            contextMenuStrip.Items.Add(itemAbout);

            contextMenuStrip.Items.Add(new ToolStripSeparator());

            var itemExit = new ToolStripMenuItem("Exit");
            itemExit.Click += delegate {
                manager.CloseZune();
                Application.Exit();
            };
            contextMenuStrip.Items.Add(itemExit);

            // Retrieve the stream of the system tray icon embedded in Zuse.exe
            Assembly asm = Assembly.GetExecutingAssembly();
            Icon icon = Icon.ExtractAssociatedIcon(asm.Location);

            // Create the system tray icon and attach events
            notifyIcon = new NotifyIcon();
            notifyIcon.Icon = icon;
            notifyIcon.Visible = true;
            notifyIcon.Text = "Zuse";
            notifyIcon.ContextMenuStrip = contextMenuStrip;

            string ApiKey = "28c09ec38e4b2fc3d0d9685702065295";
            string ApiSecret = "394e61d41eb59981ca4b4d275073c1d1";
            var scrobbler = new Scrobbler(ApiKey, ApiSecret, Settings.Default.SessionKey);

            if (String.IsNullOrEmpty(Settings.Default.SessionKey))
            {
                MessageBox.Show("Welcome to Zuse! Because this is the first time you have used Zuse " +
                    "we need to authorize the application with last.fm. " +
                    "Please follow the instructions in your web browser. Thank you.",
                    "Zuse", MessageBoxButtons.OK, MessageBoxIcon.Information);

                // get a url to authenticate this application
                string url = scrobbler.GetAuthorisationUri();

                // open the URL in the default browser
                Process.Start(url);
            }

            // Initialize main manager
            manager = new ZuneManager(scrobbler);
            manager.LaunchZune();
        }
コード例 #3
0
        /// <summary>
        /// Instantiates an instance of a <see cref="QueuingScrobbler"/>
        /// </summary>
        /// <param name="apiKey">Required. An API Key from Last.fm. See http://www.last.fm/api/account </param>
        /// <param name="apiSecret">Required. An API Secret from Last.fm. See http://www.last.fm/api/account </param>
        /// <param name="sessionKey">Required. An authorized Last.fm Session Key. See <see cref="Scrobbler.GetSession"/></param>
        /// <exception cref="ArgumentNullException"/>
        public QueuingScrobbler(string apiKey, string apiSecret, string sessionKey)
        {
            if (string.IsNullOrEmpty(apiKey)) throw new ArgumentNullException("apiKey");
            if (string.IsNullOrEmpty(apiSecret)) throw new ArgumentNullException("apiSecret");
            //if (string.IsNullOrEmpty(sessionKey)) throw new ArgumentNullException("sessionKey");

            ApiKey = apiKey;
            ApiSecret = apiSecret;
            SessionKey = sessionKey;
            NowPlayingQueue = new ConcurrentQueue<Track>();
            ScrobbleQueue = new ConcurrentQueue<Track>();
            RatingQueue = new ConcurrentQueue<RatingObject>();

            _scrobbler = new Scrobbler(ApiKey, ApiSecret, SessionKey);
        }
コード例 #4
0
        private static string GetSessionKey()
        {
            const string sessionKeyRegistryKeyName = "LastFmSessionKey";

            // try get the session key from the registry
            string sessionKey = GetRegistrySetting(sessionKeyRegistryKeyName, null);

            if (string.IsNullOrEmpty(sessionKey))
            {
                // instantiate a new scrobbler
                var scrobbler = new Scrobbler(ApiKey, ApiSecret);

                //NOTE: This is demo code. You would not normally do this in a production application
                while (string.IsNullOrEmpty(sessionKey))
                {
                    // Try get session key from Last.fm
                    try
                    {
                        sessionKey = scrobbler.GetSession();

                        // successfully got a key. Save it to the registry for next time
                        SetRegistrySetting(sessionKeyRegistryKeyName, sessionKey);
                    }
                    catch (LastFmApiException exception)
                    {
                        // get session key from Last.fm failed
                        MessageBox.Show(exception.Message);

                        // get a url to authenticate this application
                        string url = scrobbler.GetAuthorisationUri();

                        // open the URL in the default browser
                        Process.Start(url);

                        // Block this application while the user authenticates
                        MessageBox.Show("Click OK when Application authenticated");
                    }
                }
            }

            return sessionKey;
        }
コード例 #5
0
        /// <summary>
        /// Instantiates an instance of a <see cref="QueuingScrobbler"/>
        /// </summary>
        /// <param name="apiKey">Required. An API Key from Last.fm. See http://www.last.fm/api/account </param>
        /// <param name="apiSecret">Required. An API Secret from Last.fm. See http://www.last.fm/api/account </param>
        /// <param name="sessionKey">Required. An authorized Last.fm Session Key. See <see cref="Scrobbler.GetSession"/></param>
        /// <exception cref="ArgumentNullException"/>
        public QueuingScrobbler(string apiKey, string apiSecret, string sessionKey)
        {
            if (string.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentNullException("apiKey");
            }
            if (string.IsNullOrEmpty(apiSecret))
            {
                throw new ArgumentNullException("apiSecret");
            }
            //if (string.IsNullOrEmpty(sessionKey)) throw new ArgumentNullException("sessionKey");

            ApiKey          = apiKey;
            ApiSecret       = apiSecret;
            SessionKey      = sessionKey;
            NowPlayingQueue = new ConcurrentQueue <Track>();
            ScrobbleQueue   = new ConcurrentQueue <Track>();
            RatingQueue     = new ConcurrentQueue <RatingObject>();

            _scrobbler = new Scrobbler(ApiKey, ApiSecret, SessionKey);
        }
コード例 #6
0
ファイル: Scrobble.cs プロジェクト: ozok/TRadioPlayer
        public Scrobble(string trackData)
        {
            List<string> trackDataList = trackData.Split('-').ToList();
            if (trackDataList.Count > 0)
            {
                string artist = trackDataList[0];
                string title = string.Empty;
                for (int i = 1; i < trackDataList.Count; i++)
                {
                    title += trackDataList[i];
                }

                Scrobbler scrobbler = new Scrobbler("0a5674077da2782718075412eab00800", "56668ad9e4293be48def8f5ab1a6c658");
                Track track = new Track {ArtistName = artist, TrackName = title};
                ScrobbleResponse response = scrobbler.Scrobble(track);
                ErrorMessage = response.Exception.Message + " " + response.ErrorCode.ToString();
            }
            else
            {
                ErrorMessage = trackDataList.Count.ToString();
            }
        }
コード例 #7
0
ファイル: Scrobbler.cs プロジェクト: GeorgeHahn/SOVND
 public Scrobbler(ISettingsProvider settingsProvider)
 {
     _settings  = settingsProvider.GetSettings();
     _scrobbler = new Lpfm.LastFmScrobbler.Scrobbler("3f372a470689b8a50d83ce8c40a1a01d", "7e7c030e4b1f6670965ea8d518dcce04", _settings.LastfmSession);
 }
コード例 #8
0
ファイル: ScrobbleManager.cs プロジェクト: leetreveil/zuse
 public ScrobbleManager(Scrobbler scrobbler)
 {
     _scrobbler = scrobbler;
 }