Play Music Suggestion Cli



  1. https://productforums.google.com/d/msg/play/kuEFZy2QoR0/biUjgWhaAAAJ
  2.  
  3. IMPORTANT NOTES: BE VERY CAREFUL WHEN RUNNING THIS CODE.  RUNNING THIS CODE IS AT YOUR OWN RISK.
  4. I accept no liability for the faulty usage/running of this code.
  5. This is Powershell code, Powershell is a powerful scripting utility included in Windows 7 and later Operating Systems (Sorry Mac users, THIS ISN'T FOR YOU)
  6. This code is set to run at: 2560 x 1440 screen resolution <- if you are not sure which resolution your computer is at or you are operating at a different resolution DO NOT RUN THIS CODE.  It will need to be edited to work properly at other resolutions.
  7. If you have your taskbar set to auto-hide unset that for the running of this code.
  8. If you have your taskbar located anywhere other than the default bottom of the screen DO NOT RUN THIS CODE.  It will need to be edited to work properly on your setup.
  9. The script is set up so that Google Play Music and the Powershell window are 50/50 split screen side by side, with Music on the left side.
  10. Depending on your internet speed, browser speed, and computer performance, some of the 'sleep' times in the script will need to be increased to allow for the Music page elements (like the Edit song window) to load fully before executing the next action of the code.
  11.  
  12. If you are unfamiliar with scripting in general... It would be pretty wise to get someone who is familiar with computer scripts to help you with the running of this code.
  13.  
  14. What this code does:
  15. It moves the mouse cursor, and clicks the buttons for you to select the songs in your library, tells it to use all the suggestions and then saves the song details.  Rinse repeat.
  16. IMPORTANT NOTE: you'll not be able to do other things on your computer while this code is running, as it'll continually be jumping the mouse around the screen (as that's literally what it's coded to do).  Because of this, I would recommend running it in batches of songs.  Each song takes approximately 3.5 seconds to edit, depending on your internet speed, browser speed, and computer performance.
  17. If you desperately need the script to stop, hitting [Alt]+[F4] a few times should close out the Music page and the Powershell window, ending the code's running.
  18.  
  19. How you run it:
  20. Load up Google Play Music in Chrome (preferrably)  and move it to the Left half of your screen.  Go to your music library, and go to the Songs tab (assuming you want to do this to all the songs in your library.  You can do this to playlists as well, though they'll need to be sufficiently long for the running of this script)
  21. Open up Powershell and move it to the Right half of your screen.
  22. Copy Paste the script in.
  23. Run the command: EditSongs #  <- where # is the number of tracks you would like to edit in a batch.  At this point it will start running through your track list making these changes for the # of songs you told it to do.
  24.  
  25. And without any further ado THE CODE:
  26.  
  27. Add-Type -AssemblyName System.Windows.Forms
  28.  
  29. #This signature line pulls in the windows code needed to simulate mouse clicks.
  30. $signature=@'
  31.         [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
  32.         public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
  33. '@
  34. #This line creates our fake mouse.
  35. $SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru
  36. #This line creates an object to move the cursor on the screen.
  37. $Cursor=[Windows.Forms.Cursor]
  38. #These are the parameters which would need to be changed for different resolutions and different taskbar locations.
  39. #You can determine where you need to change the locations to by using the command: $Cursor::Position
  40. #if you hover over the section of the Music page you need to click on and run that command, it will display to you
  41. #you current cursor position.
  42. $TrackSelect="260,1285"
  43. $UseSuggestion="430,1015"
  44. $SaveSong="880,1015"
  45.  
  46. #This function moves the cursor to the given coordinates.
  47. function MoveCursor{
  48.         param([string]$Coords)
  49.         $Cursor::Position=("$Coords")
  50. }
  51. #This function simulates the pressing of the down arrow.
  52. function MoveDown{
  53.         [System.Windows.Forms.SendKeys]::SendWait("{DOWN}")
  54. }
  55. #This function simulates the pressing of the 'e' key which is the Music hotkey for opening up the edit menu.
  56. function Edit{
  57.         [System.Windows.Forms.SendKeys]::SendWait("e")
  58. }
  59. #This function simulates the depression and subsequent release (the click) of the left mouse button.
  60. function Click-MouseButton{
  61.         $SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0);
  62.         $SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);
  63. }
  64. #This is the Main function.  It performs the tasks necessary to edit 'Quantity' songs.
  65. #Each sleep point pauses the script for a short while so that necessary page elements can load.
  66. #Depending on your internet speed, computer performance, etc. these numbers may need to be increased.
  67. Function EditSongs{
  68.         param([int]$Quantity)
  69.         $i=0
  70.         while($i -lt $Quantity){
  71.                 #Move cursor to the bottom most track on the screen and select it.
  72.                 MoveCursor $TrackSelect
  73.                 Click-MouseButton
  74.                 sleep -Milliseconds 100
  75.                 #Trigger editing for the song
  76.                 Edit
  77.                 sleep -Milliseconds 750
  78.                 #As the edit window opens, move the cursor to the Use Suggestions button location.
  79.                 MoveCursor $UseSuggestion
  80.                 sleep -Milliseconds 750
  81.                 #By this time the form should be loaded. Click the button.
  82.                 Click-MouseButton
  83.                 sleep -Milliseconds 125
  84.                 #move the cursor to the Save button.
  85.                 MoveCursor $SaveSong
  86.                 sleep -Milliseconds 375
  87.                 #Click the button.
  88.                 Click-MouseButton
  89.                 sleep -Milliseconds 500
  90.                 #Move the cursor back to the bottom most song.
  91.                 MoveCursor $TrackSelect
  92.                 sleep -Milliseconds 500
  93.                 #Select again the bottom most song.
  94.                 Click-MouseButton
  95.                 #Arrow down one to select the next song in the queue.
  96.                 MoveDown
  97.                 #pause for a moment so that it doesn't trigger a 'double click'
  98.                 sleep -Milliseconds 400
  99.                 $i++
  100.         }
  101. }

Posted by GT at 28 Nov 2018, 17:35:54 CET
Language: text