Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrobbling is not always working after newest update #9

Closed
djolep111 opened this issue Apr 28, 2023 · 5 comments
Closed

Scrobbling is not always working after newest update #9

djolep111 opened this issue Apr 28, 2023 · 5 comments

Comments

@djolep111
Copy link

After i updated Apple Music Preview, scrobbling sometimes work and sometimes does not work. I tried restarting the app and issue isnt fixed, but after some time it start working again

@spedinfargo
Copy link
Contributor

Looks like the update changed something that the scraper is relying on:

Exception Info: System.NullReferenceException: Object reference not set to an instance of an object.
   at AMWin_RichPresence.AppleMusicScraper.GetAppleMusicInfo(AutomationElement amWindow)
   at AMWin_RichPresence.AppleMusicScraper.Refresh(Object source, ElapsedEventArgs e)
   at AMWin_RichPresence.AppleMusicScraper..ctor(Int32 refreshPeriodInSec, RefreshHandler refreshHandler)
   at AMWin_RichPresence.App..ctor()
   at AMWin_RichPresence.App.Main()

I'm seeing that in Windows Event Viewer...

@spedinfargo
Copy link
Contributor

Here's what's going on, but I'm not sure what the fix is yet as I don't really understand the scraping of elements from the window. Vincent can hopefully weight in.

It appears that the new version of the app kind of "hides" the time elapsed and time remaining elements when a new song plays. If you hover over them once, the values appear and things are good for the remainder of that song. But when the scraper can't see the element, it fails on this:

            var currentTimeElement = amWinChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "CurrentTime"));
            var remainingDurationElement = amWinChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "Duration"));
            
            var currentTime = ParseTimeString(currentTimeElement.Current.Name);
            var remainingDuration = ParseTimeString(remainingDurationElement.Current.Name);

When those are null, things are not happy. I suppose there should at least be a try/catch around that to avoid the exception, but I don't know if the scraping completely breaks if it can't find the true times since the timer may depend on that (the thing that detects when there is a new song).

@spedinfargo
Copy link
Contributor

This should at least get past the null reference exception:


            var currentTime = ParseTimeString(currentTimeElement?.Current.Name ?? "0:00");
            var remainingDuration = ParseTimeString(remainingDurationElement?.Current.Name ?? "0:00");

But once again, I'm not sure what that does to the scraping and timer side of things. I'll play around with it some more and see if things keep scrobbling with that change.

@PKBeam
Copy link
Owner

PKBeam commented Apr 29, 2023

I don't know if the scraping completely breaks if it can't find the true times since the timer may depend on that (the thing that detects when there is a new song).

The timestamps are only used for Discord's Rich Presence - they aren't used in the scraping logic.
I'll update the code to deal with the null case.

@djolep111
Copy link
Author

thanks for your hard work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants