Google Chrome Now Playing v1.2

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Google Chrome Now Playing v1.2

Re: Google Chrome Now Playing v1.2

by fizzjob » Tue Nov 24, 2009 10:24 am

aidan_cage wrote:so do we need to install an extension in chrome AND a script in MM? Your download link for the MM script is broken
Yes, you have to install both - the MM script generates the text file that gets read by the Chrome plugin. I fixed the link to the MM script, thanks for bringing that to my attention.

Re: Google Chrome Now Playing v1.2

by aidan_cage » Sun Nov 22, 2009 1:10 pm

so do we need to install an extension in chrome AND a script in MM? Your download link for the MM script is broken

Re: Google Chrome Now Playing v1.2

by fizzjob » Tue Nov 17, 2009 10:00 am

Version 1.2 is now out, with a clickable icon at the top of the browser instead of a toolstrip. Not really my thing, but Chrome is getting rid of the toolstrip, so it's a clickable icon or nothing, apparently.

Image

Re: Google Chrome Now Playing v1.1

by fizzjob » Wed Oct 07, 2009 8:20 am

Benn wrote:Nice script fizzjob. I'll ask as you're working on Chrome... when I try to install the Chrome extension a box appears "Extensions are not enabled". I can't seem to find the option to change this. Using 3.0.195.25 (Chrome that is).

Thank you,

Ben
You could try adding the "--enable-extensions" to the shortcut(s) you're using to launch Chrome. There's also a registry tweak which will catch it if, say, a link in your email opens Chrome:

XP:
HKEY_CLASSES_ROOT\http\shell\open\command
HKEY_CLASSES_ROOT\https\shell\open\command
HKEY_CLASSES_ROOT\ftp\shell\open\command (this one is optional - if you have a dedicated FTP client, you probably shouldn't touch this one)

Vista/7:
HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command

The (Default) value will look something like this:

Code: Select all

"C:\Documents and Settings\eriqj\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" -- "%1"
Change it to...

Code: Select all

"C:\Documents and Settings\eriqj\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" --enable-extensions "%1"
...from what I've read, the registry settings will reset when Chrome updates itself, however.

Like I said, I'm running the Dev channel, in which extensions are enabled by default. They may also be enabled in the Beta channel, but I'm not sure. You can change your channel here: http://dev.chromium.org/getting-involved/dev-channel

Re: Google Chrome Now Playing v1.1

by Benn » Wed Oct 07, 2009 3:06 am

Nice script fizzjob. I'll ask as you're working on Chrome... when I try to install the Chrome extension a box appears "Extensions are not enabled". I can't seem to find the option to change this. Using 3.0.195.25 (Chrome that is).

Thank you,

Ben

Re: Get now playing song info in web page

by fizzjob » Tue Oct 06, 2009 9:50 am

It works! Good gravy, it works!

If any of you are using Google Chrome, here are the bits you're gonna need:

Install the following MM script: http://eriqjaffe.50webs.com/chromeoutput.mmip.

Then install the following Chrome extension: http://eriqjaffe.50webs.com/testext.crx. Initially, the toolstrip won't have any song information until a new track is played. Once you play a new track, it'll start picking up on it.

I'm not 100% sure if Chrome generates the same folder name on different machines when you install an extension, so you may need to edit lines 39 and 40 of the .vbs script to reflect where Chrome installs the extension.

Here's the basics of how it works - MM writes the artist and name of the song to a text file (or a status message if it's stopped or closed). The Chrome extension just reads that text file and inserts it into an HTML file that gets displayed in the toolstrip at the bottom of the page:

Image

Clicking on it will bring up the cover art of the currently playing track (or a big ol' question mark if the art can't be retrieved).

I left code in the .vbs script to pull more information about the current song that is being displayed. If you want to change what's displayed in the toolstrip, you can edit line 119 to your heart's content.

Also, please note that I am currently running the Development Branch of Google Chrome, your results with the stable/release version may vary.

Thanks to trixmoto for letting me recycle his "Now Playing FTP" script, which was used as the base (well, the vast majority) of the MM script.

And, in case you're wondering, here's the code:

Code: Select all

'' MediaMonkey Script
'
' NAME: Chrome Output 1.1
'
' AUTHOR: eriqjaffe, although 95% of this script is taken verbatim from "Now Playing FTP" by trixmoto (http://trixmoto.net)
' DATE : 21/12/2008

Option Explicit

Sub OnStartup  
  Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
  Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
  Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
  Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
End Sub

Sub Event_OnPlay()
    Call SendInfo(0)
End Sub

Sub Event_OnStop()
    Call SendInfo(1)
End Sub

Sub Event_OnShutdown()
    Call SendInfo(2)
End Sub

Sub Event_OnPause()
    Call SendInfo(3)
End Sub

Sub SendInfo(mode)
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim wsh : Set wsh = CreateObject("WScript.Shell")
  'Dim loc : loc = "c:\testext\mm_output.txt"
  Dim loc : loc = wsh.ExpandEnvironmentStrings("%USERPROFILE%")&"\local settings\application data\Google\Chrome\User Data\Default\Extensions\npafjnbpbkpgdfkafnabghkdgmbhinhe\1.1\mm_output.txt"
  Dim art : art = wsh.ExpandEnvironmentStrings("%USERPROFILE%")&"\local settings\application data\Google\Chrome\User Data\Default\Extensions\npafjnbpbkpgdfkafnabghkdgmbhinhe\1.1\cover.html"
  Dim tmp : Set tmp = fso.CreateTextFile(loc,True)
  If mode = 1 Then
      Call tmp.WriteLine("<img src=""mm.png""> MediaMonkey is idle.")
      tmp.Close
  ElseIf mode = 2 Then
      Call tmp.WriteLine("<img src=""mm.png""> MediaMonkey is not running.")
      tmp.Close
  Else
      'get current song
      Dim cur : Set cur = SDB.Player.CurrentSong
      If cur Is Nothing Then
        Exit Sub
      End If
      
      'get settings
      Dim site : site = ""
      Dim user : user = ""
      Dim pass : pass = ""
      Dim path : path = ""
      Dim arti : arti = ""
      Dim albu : albu = ""
      Dim year : year = ""
      Dim name : name = ""
      Dim secs : secs = ""
      Dim genr : genr = ""
      Dim dnum : dnum = ""
      Dim tnum : tnum = ""
      Dim artw : artw = ""
      Dim recs : recs = ""
      Dim aart : aart = ""
      Dim rati : rati = ""
      Dim temp : temp = ""
      Dim arr
      Dim tmp2 : tmp2 = ""

      'check songlength
      Dim msec : msec = 0
      If IsNumeric(secs) Then
        msec = secs*1000
      End If
      If cur.SongLength < msec Then
        Exit Sub
      End If
    
      'create file
      If Not (cur Is Nothing) Then
        name = cur.Title
        arti = cur.ArtistName
        albu = cur.AlbumName
        year = cur.Year
        genr = cur.Genre
        dnum = cur.DiscNumberStr
        tnum = cur.TrackOrderStr
        aart = cur.AlbumArtistName
        rati = cur.Rating
        path = cur.Path
        artw = GetAlbumArt(cur,0)
         If HtmlEncode(Mid(artw,InStrRev(artw,"\")+1)) = "np.jpg" Then
            temp = "embedded"
            artw = wsh.ExpandEnvironmentStrings("%TEMP%")&"\np.jpg"
         Else
            arr = Split(HtmlEncode(path),"\")
            temp = "linked"
            dim y : y = Ubound(arr) - 1
            dim x : for x = 0 to y
                tmp2 = tmp2 + arr(x) + "\"
            next
            artw = tmp2&Mid(artw,InStrRev(artw,"\")+1)
         End If
         If fso.FileExists(artw) Then
            fso.CopyFile artw,wsh.ExpandEnvironmentStrings("%USERPROFILE%")&"\local settings\application data\Google\Chrome\User Data\Default\Extensions\npafjnbpbkpgdfkafnabghkdgmbhinhe\1.1\cover.jpg"
         Else
            fso.CopyFile wsh.ExpandEnvironmentStrings("%USERPROFILE%")&"\local settings\application data\Google\Chrome\User Data\Default\Extensions\npafjnbpbkpgdfkafnabghkdgmbhinhe\1.1\nocover.jpg",wsh.ExpandEnvironmentStrings("%USERPROFILE%")&"\local settings\application data\Google\Chrome\User Data\Default\Extensions\npafjnbpbkpgdfkafnabghkdgmbhinhe\1.1\cover.jpg"
         End If
      End If
'        If mode = 3 Then
'           Call tmp.WriteLine(HtmlEncode(arti) & " - " & HtmlEncode(name) & " (Paused)")
'        Else
         Call tmp.WriteLine("<img src=""mm.png""> " & HtmlEncode(arti) & " - " & HtmlEncode(name))
         'Call tmp.WriteLine("  $image = "&temp)
         'Call tmp.WriteLine(artw)
'        End If
      tmp.Close
    end if
End Sub

Function GetAlbumArt(track,num)
  GetAlbumArt = Replace(Script.ScriptPath,"chromeoutput.vbs","default.jpg")
  Dim fso : Set fso = SDB.Tools.FileSystem
  Dim wsh : Set wsh = CreateObject("WScript.Shell")
  Dim str : str = "\np.jpg"
  If num > 0 Then
    str = "\np"&num&".jpg"
  End If
  Dim temp : temp = wsh.ExpandEnvironmentStrings("%TEMP%")&str  
  Dim pics : Set pics = track.AlbumArt
  If Not (pics Is Nothing) Then      
    Dim i : i = 0
    For i = 0 To pics.Count-1 
      If (pics.Item(i).ItemStorage = 0) Or (num > 0) Then
        Dim img : Set img = pics.Item(i).Image
        If Not (img Is Nothing) Then
          Dim outimg : Set outimg = fso.CreateTextFile(temp,True)
          If Not (outimg Is Nothing) Then
            Call outimg.WriteData(img.ImageData,img.ImageDataLen)
            outimg.Close
            GetAlbumArt = temp
            Exit Function
          End If
        End If
      Else
        GetAlbumArt = pics.Item(i).PicturePath
        Exit Function
      End If
    Next
  End If
End Function
Function HtmlEncode(str)
  HtmlEncode = SDB.toAscii(str)
  HtmlEncode = Replace(HtmlEncode,"&","&")
  HtmlEncode = Replace(HtmlEncode,"""",""")
  HtmlEncode = Replace(HtmlEncode,"<","<")
  HtmlEncode = Replace(HtmlEncode,">",">")
End Function

Re: Get now playing song info in web page

by fizzjob » Mon Oct 05, 2009 11:26 am

Actually, I remembered the "Now Playing FTP" script, and have modified it to the point where I'm outputting the HTML file I want.

Now the issue becomes getting Google Chrome to refresh the toolstrip, which I can't seem to make work. But that's not a MM scripting issue, that's a Chrome issue.

Thanks for the help!

Re: Get now playing song info in web page

by trixmoto » Mon Oct 05, 2009 3:37 am

I wrote my "Now Playing FTP" script to do this, except for a public website. It uploads a file (via FTP) holding all the details of the current playing track in a format ready for PHP to utilise. This may be a bit OTT for what you require though, and does require a little PHP knowledge to build the page, although I have provided a very simplistic xeample.

In terms of connecting with MM you can do everything in Javascript that you can do in VBScript, it's just a case of porting the code.

Re: Get now playing song info in web page

by Jay OBrien » Sat Oct 03, 2009 11:26 pm

I also would like to be able to have a display accessible from all computers on my home LAN that would show the current title, album and the playlist selection number. Other details would be nice, but these are the fields that are the most useful to me. Is there someone out there who could do this for us?

Jay O'Brien
Folsom, CA USA

Re: Get now playing song info in web page

by DazB » Fri Oct 02, 2009 2:23 pm

Hi,

1. As you want use something other than IE you will need to use something like PHP to connect to MM via AJAX.
2. Maybe a script fired on by the appropriate MM event to write the required info to an XML file and load that via AJAX.

Daz

Re: Get now playing song info in web page

by fizzjob » Fri Oct 02, 2009 1:21 pm

holterpolter wrote:Maybe start with looking at the SongInformation Panel or MonkeyRock.
They build a html page and show them on a panel inside Media Monkey
http://www.mediamonkey.com/forum/viewto ... =2&t=41882
Strip down all the unnecessary stuff and you could get a simple html info page.
Unfortunately, those rely on VBScript, which doesn't help.

Re: Get now playing song info in web page

by holterpolter » Fri Oct 02, 2009 12:38 pm

Maybe start with looking at the SongInformation Panel or MonkeyRock.
They build a html page and show them on a panel inside Media Monkey
http://www.mediamonkey.com/forum/viewto ... =2&t=41882
Strip down all the unnecessary stuff and you could get a simple html info page.

Google Chrome Now Playing v1.2

by fizzjob » Fri Oct 02, 2009 11:32 am

As the title says,I'm trying to build a super-simple HTML page that will display info about the currently playing song in a simple HTML page.

The gotcha is that I'm trying to build this into a small plugin for Google Chrome, so it can't rely on ActiveX or VBScript. Can this be done through Javascript? I don't want to control the player, or write to the database, or even read from the database, just interface with the API.

Can anybody give me any pointers on how to proceed with this?

edit: The script and Chrome extension have been updated in accordance with the recent announcement that Chrome will no longer support the "Toolstrip". :(

The MM script is here, and the Chrome extension is here.

Changes in v1.1
Clicking on the toolstrip button now shows album art in a popup window.

Changes in v1.2
The Chrome extension now supports the "Browser Action" method instead of the going-away-soon "Toolstrip" method.

Top