Exemple #1
0
        private string BuildPostData(TrackInfo track, LastfmAccount account)
        {
            StringBuilder data = new StringBuilder();

            data.AppendFormat("artist={0}", EscapeUri(track.ArtistName));
            data.AppendFormat("&duration={0}", (int)track.Duration.TotalSeconds);

            string[] slashedUri = track.Uri.LocalPath.Split('/', '\\');
            data.AppendFormat("&filename={0}", EscapeUri(slashedUri [slashedUri.Length - 1]));
            data.AppendFormat("&fpversion={0}", EscapeUri(GetlfmpVersion()));
            data.AppendFormat("&genre={0}", EscapeUri(track.Genre));
            data.AppendFormat("&samplerate={0}", track.SampleRate);

            SHA256Managed cr = new  SHA256Managed();

            byte[] hash = cr.ComputeHash(File.ReadAllBytes(track.Uri.AbsolutePath));
            data.AppendFormat("&sha256={0}", ToHex(hash));
            data.AppendFormat("&track={0}", EscapeUri(track.TrackTitle));

            if (!string.IsNullOrEmpty(track.AlbumTitle))
            {
                data.AppendFormat("&album={0}", EscapeUri(track.AlbumTitle));
            }

            if (track.TrackNumber > 0)
            {
                data.AppendFormat("&tracknum={0}", track.TrackNumber);
            }

            if (track.Year > 0)
            {
                data.AppendFormat("&year={0}", track.Year);
            }
            // TODO change account here
            if (account == null || String.IsNullOrEmpty(account.UserName))
            {
                // anonymous seems to stuck in 3 requests
                // TODO add a wait system when anon
                data.AppendFormat("&username={0}", EscapeUri("fp client 1.6"));
            }
            else
            {
                string time = (DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds.ToString();
                data.AppendFormat("time={0}", time); //seconds since 1er janvier 1970
                data.AppendFormat("&username={0}", account.UserName);
                data.AppendFormat("&auth={0}", ConvertToMd5(account.Password + time));
                data.AppendFormat("&authlower={0}", ConvertToMd5(account.Password.ToLower() + time));
            }

            if (!string.IsNullOrEmpty(track.MusicBrainzId))
            {
                data.AppendFormat("&mbid={0}", EscapeUri(track.MusicBrainzId));
            }

            return(data.ToString());
        }
Exemple #2
0
        public LoginDialog(LastfmAccount account, bool addCloseButton) : base()
        {
            Title        = Catalog.GetString("Log in to Last.fm");
            HasSeparator = false;

            IconName = "gtk-dialog-authentication";

            HBox hbox = new HBox(false, 12);
            VBox vbox = new VBox(false, 0);

            hbox.BorderWidth = 5;
            vbox.Spacing     = 5;

            Image image = new Image();

            image.Yalign   = 0.0f;
            image.IconName = "gtk-dialog-authentication";
            image.IconSize = (int)IconSize.Dialog;

            hbox.PackStart(image, false, false, 0);
            hbox.PackStart(vbox, true, true, 0);

            Label header = new Label();

            header.Xalign = 0.0f;
            header.Markup = String.Format("<big><b>{0}</b></big>", Catalog.GetString("Last.fm Account Login"));

            message        = new Label(Catalog.GetString("Please enter your Last.fm account credentials."));
            message.Xalign = 0.0f;

            vbox.PackStart(header, false, false, 0);
            vbox.PackStart(message, false, false, 0);

            login_form = new LoginForm(account);
            login_form.AddSignUpButton();
            login_form.AddAuthorizeButton();
            //TODO fix the verify user because always get bad pwd

            vbox.PackStart(login_form, true, true, 0);

            VBox.PackStart(hbox, true, true, 0);
            VBox.Spacing = 10;

            VBox.ShowAll();

            if (addCloseButton)
            {
                AddStockButton(Stock.Cancel, ResponseType.Cancel);
                var button = AddStockButton(Stock.Ok, ResponseType.Ok, true);
                button.Label = Catalog.GetString("Log In");
            }
        }
        public LoginDialog(LastfmAccount account, bool addCloseButton)
            : base()
        {
            Title = Catalog.GetString ("Log in to Last.fm");
            HasSeparator = false;

            IconName = "gtk-dialog-authentication";

            HBox hbox = new HBox (false, 12);
            VBox vbox = new VBox (false, 0);
            hbox.BorderWidth = 5;
            vbox.Spacing = 5;

            Image image = new Image ();
            image.Yalign = 0.0f;
            image.IconName = "gtk-dialog-authentication";
            image.IconSize = (int)IconSize.Dialog;

            hbox.PackStart (image, false, false, 0);
            hbox.PackStart (vbox, true, true, 0);

            Label header = new Label ();
            header.Xalign = 0.0f;
            header.Markup = String.Format ("<big><b>{0}</b></big>", Catalog.GetString ("Last.fm Account Login"));

            message = new Label (Catalog.GetString ("Please enter your Last.fm account credentials."));
            message.Xalign = 0.0f;

            vbox.PackStart (header, false, false, 0);
            vbox.PackStart (message, false, false, 0);

            login_form = new LoginForm (account);
            login_form.AddSignUpButton ();
            login_form.AddAuthorizeButton ();
            //TODO fix the verify user because always get bad pwd

            vbox.PackStart (login_form, true, true, 0);

            VBox.PackStart (hbox, true, true, 0);
            VBox.Spacing = 10;

            VBox.ShowAll ();

            if (addCloseButton) {
                AddStockButton (Stock.Cancel, ResponseType.Cancel);
                var button = AddStockButton (Stock.Ok, ResponseType.Ok, true);
                button.Label = Catalog.GetString ("Log In");
            }
        }
Exemple #4
0
        public LoginForm(LastfmAccount account) : base(2, 2, false)
        {
            this.account = account;

            BorderWidth   = 5;
            RowSpacing    = 5;
            ColumnSpacing = 5;

            Label username_label = new Label(Catalog.GetString("Username:"******"Password:"));

            password_label.Xalign = 1.0f;

            password_entry            = new Entry();
            password_entry.Visibility = false;

            Attach(username_label, 0, 1, 0, 1, AttachOptions.Fill,
                   AttachOptions.Shrink, 0, 0);

            Attach(username_entry, 1, 2, 0, 1, AttachOptions.Fill | AttachOptions.Expand,
                   AttachOptions.Shrink, 0, 0);

            Attach(password_label, 0, 1, 1, 2, AttachOptions.Fill,
                   AttachOptions.Shrink, 0, 0);

            Attach(password_entry, 1, 2, 1, 2, AttachOptions.Fill | AttachOptions.Expand,
                   AttachOptions.Shrink, 0, 0);

            username_entry.Text = account.UserName ?? String.Empty;

            ShowAll();
        }
        public LoginForm(LastfmAccount account)
            : base(2, 2, false)
        {
            this.account = account;

            BorderWidth = 5;
            RowSpacing = 5;
            ColumnSpacing = 5;

            Label username_label = new Label (Catalog.GetString ("Username:"******"Password:"));
            password_label.Xalign = 1.0f;

            password_entry = new Entry ();
            password_entry.Visibility = false;

            Attach (username_label, 0, 1, 0, 1, AttachOptions.Fill,
                AttachOptions.Shrink, 0, 0);

            Attach (username_entry, 1, 2, 0, 1, AttachOptions.Fill | AttachOptions.Expand,
                AttachOptions.Shrink, 0, 0);

            Attach (password_label, 0, 1, 1, 2, AttachOptions.Fill,
                AttachOptions.Shrink, 0, 0);

            Attach (password_entry, 1, 2, 1, 2, AttachOptions.Fill | AttachOptions.Expand,
                AttachOptions.Shrink, 0, 0);

            username_entry.Text = account.UserName ?? String.Empty;

            ShowAll ();
        }
        private void OnGetTagFromFingerprint(object sender, EventArgs args)
        {
            active = true;
            Source source = ServiceManager.SourceManager.ActiveSource;

            UserJob job = new UserJob (AddinManager.CurrentLocalizer.GetString ("Getting sound fingerprint"));
            job.SetResources (Resource.Cpu, Resource.Disk, Resource.Database);
            job.PriorityHints = PriorityHints.SpeedSensitive;
            job.Status = AddinManager.CurrentLocalizer.GetString ("Scanning...");
            job.IconNames = new string [] { "system-search", "gtk-find" };
            job.CanCancel = true;
            job.CancelRequested += HandleJobCancelRequested;
            job.Register ();

            if (account == null) {
                account = new LastfmAccount ();
                LoginDialog dialog = new LoginDialog (account, true);
                dialog.Run ();
                dialog.Destroy ();
            }

            //comment the timeout system for TOS because still have issue and not seems to be linked...
            //System.DateTime start = System.DateTime.MinValue;
            ThreadPool.QueueUserWorkItem (delegate {
                try {

                    var selection = ((ITrackModelSource)source).TrackModel.Selection;
                    int total = selection.Count;
                    int count = 0;

                    foreach (TrackInfo track in ((ITrackModelSource)source).TrackModel.SelectedItems) {
                        if (!active)
                            break;
                        ad = new AudioDecoder((int)track.Duration.TotalSeconds);
                        //respect last fm term of service :
                        //You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period
                        // 2 requests are done on each loop ==> time allowed by loop : 400ms
                        /*if (start != System.DateTime.MinValue) {
                            TimeSpan span = System.DateTime.Now - start;
                            if (lastFmTOSMinTimeout > span)
                                Thread.Sleep (lastFmTOSMinTimeout - span);
                        }
                        start = DateTime.Now;
                        */
                        byte[] fingerprint = ad.Decode (track.Uri.AbsolutePath);
                        FingerprintRequest request = new FingerprintRequest();
                        request.Send (track, fingerprint, account);

                        int fpid = request.GetFpId ();
                        //force GC to dispose
                        ad = null;

                        Log.DebugFormat ("Last.fm fingerprint id for {0} is {1}", track.TrackTitle, fpid);

                        if (fpid > 0) {
                            FetchMetadata (track, fpid);
                        } else {
                            Log.WarningFormat ("Could not find fingerprint id for the track {0} !", track.TrackTitle);
                        }

                        job.Progress = (double)++count / (double)total;
                    }

                } catch (Exception e) {
                    account = null;
                    Log.Exception (e);
                } finally {
                    job.Finish ();
                }
            });
        }
Exemple #7
0
 public void Send(TrackInfo track, byte[] fingerprint, LastfmAccount account)
 {
     response_stream = Post(API_ROOT, BuildPostData(track, account), fingerprint);
 }
 public LoginDialog(LastfmAccount account)
     : this(account, false)
 {
 }
Exemple #9
0
 public LoginDialog(LastfmAccount account) : this(account, false)
 {
 }
Exemple #10
0
        private string BuildPostData (TrackInfo track, LastfmAccount account)
        {
            StringBuilder data = new StringBuilder ();
            data.AppendFormat ("artist={0}", EscapeUri (track.ArtistName));
            data.AppendFormat ("&duration={0}", (int)track.Duration.TotalSeconds);

            string[] slashedUri = track.Uri.LocalPath.Split('/', '\\');
            data.AppendFormat ("&filename={0}", EscapeUri(slashedUri [slashedUri.Length - 1]));
            data.AppendFormat ("&fpversion={0}", EscapeUri (GetlfmpVersion ()));
            data.AppendFormat ("&genre={0}", EscapeUri (track.Genre));
            data.AppendFormat ("&samplerate={0}", track.SampleRate);

            SHA256Managed cr = new  SHA256Managed ();
            byte[] hash = cr.ComputeHash (File.ReadAllBytes (track.Uri.AbsolutePath));
            data.AppendFormat ("&sha256={0}", ToHex (hash));
            data.AppendFormat ("&track={0}", EscapeUri (track.TrackTitle));

            if (!string.IsNullOrEmpty(track.AlbumTitle))
                data.AppendFormat ("&album={0}", EscapeUri (track.AlbumTitle));

            if (track.TrackNumber > 0)
                data.AppendFormat ("&tracknum={0}", track.TrackNumber);

            if (track.Year > 0)
                data.AppendFormat ("&year={0}", track.Year);
            // TODO change account here
            if (account == null || String.IsNullOrEmpty (account.UserName)) {
                // anonymous seems to stuck in 3 requests
                // TODO add a wait system when anon
                data.AppendFormat ("&username={0}", EscapeUri ("fp client 1.6"));
            } else {
                string time = (DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds.ToString ();
                data.AppendFormat ("time={0}", time);//seconds since 1er janvier 1970
                data.AppendFormat ("&username={0}", account.UserName);
                data.AppendFormat ("&auth={0}", ConvertToMd5(account.Password + time));
                data.AppendFormat ("&authlower={0}", ConvertToMd5(account.Password.ToLower() + time));
            }

            if (!string.IsNullOrEmpty(track.MusicBrainzId))
                data.AppendFormat ("&mbid={0}", EscapeUri (track.MusicBrainzId));

            return data.ToString ();
        }
Exemple #11
0
 public void Send (TrackInfo track, byte[] fingerprint, LastfmAccount account)
 {
     response_stream = Post (API_ROOT, BuildPostData (track, account), fingerprint);
 }