"now playing" to .txt-file

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

loket
Posts: 4
Joined: Wed Sep 22, 2004 6:14 pm

"now playing" to .txt-file

Post by loket »

i have been using a mirc-script in winamp to create a .txt-file which consists of only one line:

Code: Select all

 <artist> - "<title>"
whenever a new song is played, the .txt-file is updated with the current artist and song. i can then use this file to integrate in other programs, without necessarily "speaking" with mediamonkey.
is this possible to do with only mm? i'm experiencing some bugs with mm and winamp together, and i want to use mm as the only application.

anyone?
Lowlander
Posts: 57353
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Post by Lowlander »

What's the purpose of this list? You might be able to generate it out of the DB directly.

I'm not sure if MM can write info to script on song change, which would be needed in your case.
parkint
Posts: 16
Joined: Sat Oct 09, 2004 1:54 am

Post by parkint »

This should be possible, and in fact pretty easy.

You just need to set ScriptType=2 in Scripts.ini for the script to be called at song change time.

I'll write the script for you if you can wait until tomorrow evening (GMT).
parkint
Posts: 16
Joined: Sat Oct 09, 2004 1:54 am

Post by parkint »

OK, I think this should do what you want.

Save the following in your mediamonkey scripts directory:

Code: Select all

' OutputTextFile.vbs
' Write the current playing track and artist to a text file
option explicit

sub OutputTextFile

	dim objFSO, objTextFile, strTextFilePath, strTrack, strArtist

	'SET THIS TO LOCATION OF FILE
	strTextFilePath = "d:\scratch\mm_output.txt"


	'Get the artist/track
	strTrack = SDB.Player.CurrentSong.Title
	strArtist = SDB.Player.CurrentSong.Artist.Name

	'Open the file & write
	Set objFSO = CreateObject("Scripting.FileSystemObject") 
	Set objTextFile = objFSO.OpenTextFile(strTextFilePath,2)

	objTextFile.WriteLine strArtist & " - " & chr(34) & strTrack & chr(34)		

	'close the file	
	objTextFile.Close

end sub
And add the following to Scripts.ini in the same directory:

Code: Select all


[OutputTextFile]
FileName=OutputTextFile.vbs
ProcName=OutputTextFile
Language=VBScript
ScriptType=2
One gotcha is that I haven't included any check for the existence of the output file so you will have to create that first or the script will fall over.
Euther
Posts: 1
Joined: Sat Feb 28, 2015 1:06 pm

Re: "now playing" to .txt-file

Post by Euther »

Hi,
this is exactily what I am looking for too... :D
I want to add the Album info and did the following... But it errors out with an error on Line 15: Column:3
"Object doesn't support this property of method"

Can someone please assist?
thx
E

Code: Select all

' OutputTextFile.vbs
' Write the current playing track and artist to a text file option explicit

sub OutputTextFile

   dim objFSO, objTextFile, strTextFilePath, strTrack, strArtist, strAlbum

   'SET THIS TO LOCATION OF FILE
   strTextFilePath = "O:\OSB Addons\Now Playing\mm_output.txt"


   'Get the artist/track/album
   strTrack = SDB.Player.CurrentSong.Title
   strArtist = SDB.Player.CurrentSong.Artist.Name
   strAlbum = SDB.Player.CurrentSong.Album

   'Open the file & write
   Set objFSO = CreateObject("Scripting.FileSystemObject") 
   Set objTextFile = objFSO.OpenTextFile(strTextFilePath,2)

   'objTextFile.WriteLine strArtist & " - " & chr(34) & strTrack & chr(34) & " - " & chr(34) & strAlbum & chr(34)

   'close the file   
   objTextFile.Close

end sub
kireev20000
Posts: 1
Joined: Sun Mar 06, 2016 8:44 am

Re: "now playing" to .txt-file

Post by kireev20000 »

replace code in OutputTextFile.vbs

Version for OBS txt plug-in (no unicode support)

Code: Select all

    ' OutputTextFile.vbs
    ' Write the current playing track and artist to a text file
    option explicit

    sub OutputTextFile

       dim objFSO, objTextFile, strTextFilePath, strTrack, strArtist, strAlbum

       'SET THIS TO LOCATION OF FILE
	   strTextFilePath = "e:\Soft\_MediaMonkey\obs_song.txt"


       'Get the artist/track
       strTrack = SDB.Player.CurrentSong.Title
       strArtist = SDB.Player.CurrentSong.Artist.Name
       strAlbum = SDB.Player.CurrentSong.AlbumName

       'Open the file & write
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      If (objfso.FileExists(strTextFilePath)) Then
	   	  Set objTextFile = objFSO.OpenTextFile(strTextFilePath,2)
      Else
	      Set objTextFile = objFSO.CreateTextFile(strTextFilePath,2)
      End If

	  On Error Resume Next
      
	  If strArtist = "" Then  
      objTextFile.WriteLine "Music: " & strTrack & " /" & strAlbum & "/" 
	  Else 
	  objTextFile.WriteLine "Music: " & strArtist & " - " & strTrack & " /" & strAlbum & "/"
      End If
      
	  If Err.Number <> 0 Then
      objTextFile.WriteLine "Error: Unicode Text"
      Err.Clear
      End If
        
	  
       'close the file   
       objTextFile.Close
       

    end sub

With Unicode Support

Code: Select all

    ' OutputTextFile.vbs
    ' Write the current playing track and artist to a text file
    option explicit

    sub OutputTextFile

       dim objFSO, objTextFile, strTextFilePath, strTrack, strArtist, strAlbum

       'SET THIS TO LOCATION OF FILE
	   strTextFilePath = "e:\Soft\_MediaMonkey\obs_song.txt"


       'Get the artist/track
       strTrack = SDB.Player.CurrentSong.Title
       strArtist = SDB.Player.CurrentSong.Artist.Name
       strAlbum = SDB.Player.CurrentSong.AlbumName

       'Open the file & write
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objTextFile = objFSO.CreateTextFile(strTextFilePath,2,-2)
      
	  On Error Resume Next
      
	  If strArtist = "" Then  
      objTextFile.WriteLine "Music: " & strTrack & " /" & strAlbum & "/" 
	  Else 
	  objTextFile.WriteLine "Music: " & strArtist & " - " & strTrack & " /" & strAlbum & "/"
      End If
      
	  If Err.Number <> 0 Then
      objTextFile.WriteLine "Error"
      Err.Clear
      End If
        
	  
       'close the file   
       objTextFile.Close
       

    end sub

The_Testy_Ferrets

Re: "now playing" to .txt-file

Post by The_Testy_Ferrets »

I know this is an old thread but Bump, Doing some streaming and people ask who is playing, this simple script solved all of that so quickly.

It would be a good idea to get this added as a streamer option.
Peke
Posts: 17797
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: "now playing" to .txt-file

Post by Peke »

Hi,
Can you please give us more details what you use and how you solved it?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Gehis514
Posts: 1
Joined: Sun Nov 29, 2020 9:15 am

Re: "now playing" to .txt-file

Post by Gehis514 »

Currently using this when I stream to twitch from obs and it's great for showing the songs i play. Since I know nothing about scripting myself, what would it look like if I wanted to output two text files, one for the track name and another for the artist name? It would allow me to do more creative and visually interesting things if they were in two separate files
Coincident
Posts: 21
Joined: Mon Dec 09, 2019 4:47 pm

Re: "now playing" to .txt-file

Post by Coincident »

--> How can I setup a script to run when MediaMonkey exists?

The scripts in this thread are great! Thank you! I will use them while livestreaming on Twitch!

However, there's an improvement that I'm not sure how to get working...
My goal is to not keep showing the last played track on a livestream after closing down MM and not playing any audio.
I wrote a script to blank out the text file once MediaMonkey exists:

Code: Select all

    ' NowPlayingClearFile.vbs
    ' Clear the file that had current playing track and artist on exit
    option explicit

    sub NowPlayingClearFile

       dim objFSO, objTextFile, strTextFilePath

       'SET THIS TO LOCATION OF FILE
	   strTextFilePath = "C:\OBS Resources\nowplaying.txt"

       'Open the file & write
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objTextFile = objFSO.CreateTextFile(strTextFilePath,2,-2)
      
	  On Error Resume Next
      
	  'Write nothing to leave the file empty
      
	  If Err.Number <> 0 Then
      objTextFile.WriteLine "Error"
      Err.Clear
      End If
	  
       'close the file   
       objTextFile.Close

    end sub
However, I don't know how to specify Scripts.ini in such a way that the script only runs on exit.
Is there an easy way to do this?

Thanks in advance.
Post Reply