INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Sample Script Files  (Read 37530 times)

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Sample Script Files
« on: April 03, 2006, 12:14:41 pm »

This post contains sample script files that you can use with the .NET Script Plugin.
If you've created a useful script please post it here.

If you want to use one of the scripts just paste it
into the plugin, reading the instructions that came with the script.

You don't need to have an in depth knowledge of programming to use them ,
but just be warned that the scripting is powerful medicine,
and may have the potential to do irreperable damage to your Media
Center database, and or files.

It is highly recommended you make a backup of your database prior to using the scripts.
There will probably be people including myself around to help in using the scripts,
Just be warned that you use them at your own risk!

Please do not post comments here, start a new post, this thread is for scripts only

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #1 on: April 03, 2006, 12:25:51 pm »

Purpose:
This script reads in information from a text
file and places it in a specific field.
Where the text file is located in the same directory as the album.
The script operates on the current playing now list.

Example:
Say I was playing the Coldplay Album X&Y
and in the same directory as the Album was a textfile called
ExtraInfo.txt which contained information about the band coldplay,
and then ran the script in it's current form it would take the information
from ExtraInfo.txt and place it in the Comment field.
The script can be run on multiple albums at a time, each time
taking the textfile from the appropriate directory.

Configuration:
To change the name of the textfile from which the
data is read just change the following line
const string textFileName = "ExtraInfo.txt";     
As you can see the default Filename is ExtraInfo.txt

To change the field to which the data is written just change the following line
const string fieldToSet   = "Comment"; 
As you can see the default Field is Comment

Script:

using System;
using System.Windows.Forms;     
using System.IO;
//css_reference MediaCenter.dll;

class Script
{
   static public void Init(MediaJukebox.MJAutomation mediaCenterInterface, System.Windows.Forms.TextBox textBoxReference)
    {       
        const string textFileName = "ExtraInfo.txt";     
        const string fieldToSet   = "Comment"; 
       
        //Get the current playing now playlist
        MediaJukebox.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
       
        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
        {
            //Get the file from the current position in the playlist
            MediaJukebox.MJFileAutomation track = playlist.GetFile(counter);
           
            //Get the tracks filename
            string trackFileName=track.Filename;
           
            //Determine the location of the filename
            string trackLocationOnDisk = Path.GetDirectoryName(trackFileName);
           
            //Set the path to the textfile
            string pathToTextFile = trackLocationOnDisk + @"\" + textFileName;
           
            if (File.Exists(pathToTextFile))
            {
                //Create a stream reader to read the file
                System.IO.StreamReader streamRead = new System.IO.StreamReader( pathToTextFile );
               
                //Read the file to a string
                string textFromFile = streamRead.ReadToEnd();
               
                //Write the text back to the Track file
                track.Set(fieldToSet,textFromFile);
               
                //Close the stream reader
                streamRead.Close();
            }   
           
        }
    }
}

quirtep

  • Regular Member
  • Recent member
  • *
  • Posts: 44
  • I'm a llama!
Re: Sample Script Files
« Reply #2 on: June 23, 2006, 10:46:17 am »

Here is a little script I wrote to move the cover art that is embedded in the file to the file's directory as "folder.jpg" - KingSparta used to have a plugin by this name, but it was replaced by his Cover Art Finder plugin (which is a fine and nice plugin but more than I personally need).  This could easily be modified to do the same thing with cover art stored in a particular folder or whatever...

using System;
using System.Windows.Forms;
using System.IO;
//css_reference MediaCenter.dll;

class Script
{
    static public void Init(MediaJukebox.MJAutomation mediaCenterInterface, System.Windows.Forms.TextBox textBoxReference)
    {
        //Get the current playing now playlist
        MediaJukebox.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist();
        System.Windows.Forms.TextBox outputTextBox = (System.Windows.Forms.TextBox)textBoxReference;

        string PrevAlbum = "";

        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles(); ++counter)
        {
            //Get the file from the current position in the playlist
            MediaJukebox.MJFileAutomation track = playlist.GetFile(counter);

            //Get the track's filename
            string trackFileName = track.Filename;

            //Get the track's album name
            string Album = track.Album;

            if (PrevAlbum == "" || PrevAlbum != Album)
            {
                PrevAlbum = Album;
                string image = track.GetImageFile(MediaJukebox.MJImageFileFlags.IMAGEFILE_IN_FILE);

                //Determine the location of the filename
                string trackLocationOnDisk = Path.GetDirectoryName(trackFileName);
 
                try
                {
                    //Currently set to overwrite destination folder.jpg that already exists
                    File.Copy(image, trackLocationOnDisk + "/folder.jpg", true);
                }
                catch
                {
                }
                outputTextBox.AppendText("\r\n" + Album);
            }
        }
    }
}
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #3 on: July 02, 2006, 06:13:37 am »

Purpose:
This script inserts an X in the filenames of all files
in the playing now play list.  The X is inserted at a specified position ie so many characters.
A non edit mode is default so that you can check the output is as desired
before performing changes.
The changes to be made are output to the textbox in the script plugin.

Example:
Say you had video files with names as follows
Programme - ijj - episode name.avi
like
Lost - 101 - Pilot Episode.avi
Where I is the series ie Series 1
and J is the episode number ie Episode 18

When using the Fill properties from filename tool
MC can not easilly split the i and the j apart, because
it knows not that they are supposed to be split.

By Inserting an X inbetween them this is easily solved.
Programme - ixjj - episode name.avi
Lost - 1x01 - Pilot Episode.avi

Configuration:
There are 2 configurables.
A boolean saveChanges
This specifies whether the script actually makes the changes,
It's recommended that you don't set it to make changes
until you're 100% certain the X is going in the right place,
and you understand what the script is doing!


Integer positionToInsert
This is where the X is inserted.
If the script is run multiple times with changes made
then multiple x's will be inserted!

Damage Potential
Use this script incorrectly and your filenames will end up with
X's inserted where you don't want them.
MC will not be able to undo this.
You may be able to repair damage by using the Rename Files from Properties tool.
Be careful!


Script:
using System;
using System.Windows.Forms;
//css_reference MediaCenter.dll;

class Script
{
    const bool saveChanges=false;
    const int positionToInsert=10;
    static public void Init(MediaJukebox.MJAutomation mediaCenterInterface, System.Windows.Forms.TextBox textBoxReference)
    {           
        //Get the current playing now playlist
        MediaJukebox.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
       
        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
        {     
            //Get the file from the current position in the playlist
            MediaJukebox.MJFileAutomation track = playlist.GetFile(counter);

            //Get the tracks filename
            string trackFileName=track.Filename;
           
            //Insert the X and save it to filename
            trackFileName=trackFileName.Insert(positionToInsert,"x");
            textBoxReference.AppendText("\r\n" + trackFileName);   
            if (saveChanges==true)
            {
                track.Filename = trackFileName;
            }
        }


    }
}

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #4 on: February 16, 2007, 02:04:43 pm »

Purpose:
This is a Sample VB script.
It's purpose is to find the current playing track.
In MC12 this should not be necassery since you can use events,
however at this point in Time I've not got around to updating the
plugin templates so this is the old fashioned way of doing it.

Example:
The script uses Events/Delegates.
A class is created with a timer.  Everytime the timer expires the
Timer Elapsed event handler is called.  If the song has changed
then an event is raised with the new track.
The sample uses the output textbox to show the name
of the current track playing.

Damage Potential
Due to a flaw in the script plugin, once this script starts running,
it can't be properly terminated without closing Media Center,
 since it starts a second thread.
The script plugin only terminates the original thread it starts.
Hopefully this will be resolved in the next release.


' //css_reference MediaCenter.dll;
' //css_reference System.dll;
' //css_reference System.Windows.Forms.dll;
Imports System
Imports System.Windows.Forms 
Imports MediaJukebox                 
Imports System.Threading


Module Script 
    public globalTextBoxReference as Textbox   
        Sub Init( mediaCenterReference as MediaJukebox.MJAutomation, outputTextBox as Textbox)
               
        Dim QuickTest as New TrackFinder(mediaCenterReference)
        AddHandler QuickTest.TrackChange, AddressOf QuickTest_TrackChanged
       
        outputTextBox.Text = string.Empty
       
        globalTextBoxReference=outputTextBox           
       
        'Sleep for ever
        Thread.Sleep(99999999)
       
    End Sub
   
    Sub QuickTest_TrackChanged(track as IMJFileAutomation)
        globalTextBoxReference.Text = globalTextBoxReference.Text & track.Name & Environment.NewLine()
    End Sub
   
   
    Public Class TrackFinder
        #region "Attributes"
        'Create a timer which fires every 1/2 second
        private playingTimer as System.Timers.Timer = new System.Timers.Timer(500)
        'Used to Keep a tag on the current playing track
        private TrackWeBelieveIsPlaying as IMJFileAutomation
        private mediaCenterReference as MediaJukebox.MJAutomation       
        Public Delegate sub TrackChangeDelegate(track as IMJFileAutomation)
        Public Event TrackChange as TrackChangeDelegate
        #end region

        #region "Constructor"   
        public sub New ( ByVal mediaCenterReference as MediaJukebox.MJAutomation )
           
            'Set Media Center Reference
            me.MediaCenterReference = mediaCenterReference
           
            'Attach an Event Handler to the Elapsed event of the timer
            AddHandler playingTimer.Elapsed, AddressOf playingTimer_Elapsed
            me.playingTimer.Enabled = True
            me.TrackWeBelieveIsPlaying = nothing
        end sub
        #end region

        #region "Playing Timer Elapsed"         
       
        'This is our elapsed timer event handler.
        private sub playingTimer_Elapsed ( sender As Object, e As System.Timers.ElapsedEventArgs )
                   
            try
            'Disable the timer ensuring we can't come in here twice accidently
            playingTimer.Enabled = false
            'Get the Current PlayList
            Dim playback as IMJPlaybackAutomation  = me.mediaCenterReference.GetPlayback ( )
            Dim playlist as IMJCurPlaylistAutomation = me.mediaCenterReference.GetCurPlaylist ( )
           
            'Get the next file in the playing now playlist?
            Dim pos as long = playlist.GetNextFile()
            pos = playlist.Position
            'If Media Center is playing...
            if ( playback.State = MediaJukebox.MJPlaybackStates.PLAYSTATE_PLAYING ) then
            'Get The track that we've decided is playing...     
                Dim currentPlayingTrack as IMJFileAutomation = playlist.GetFile ( playlist.Position )               
               
                if (me.TrackWeBelieveIsPlaying is nothing) then
                      me.TrackWeBelieveIsPlaying = currentPlayingTrack
                      'Raise the track change event with the track name
                      RaiseEvent TrackChange(currentPlayingTrack)
                     
                elseif ( currentPlayingTrack.Get ( "Media Type", true ) = "Audio" AND _
                      ( me.TrackWeBelieveIsPlaying.Name <> currentPlayingTrack.Name)) then
                      'Update the Track We Believe is Playing
                      me.TrackWeBelieveIsPlaying = currentPlayingTrack
                     'Raise the track change event with the track name
                      RaiseEvent TrackChange(currentPlayingTrack)
                end if
           
            end if
            'Disable the timer ensuring we can't come in here twice accidently
            playingTimer.Enabled = True   
            'Catch any Exceptions!
            catch exceptionCaught as Exception
                globalTextBoxReference.Text = exceptionCaught.ToString()
            end try
        end sub                     
        #end Region
       
       
   
    End Class
End Module

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: Sample Script Files
« Reply #5 on: April 12, 2007, 06:27:31 am »

just made a small script in the scripting plugin from Mr Chriz.
it removes all video bookmarks except those from the dvd (files).
to remove the DVD bookmarks also, enable the RemoveDVDBookmarks in the script after you changed the path in DVDBM, pointing to the right place. you do this at your own risk.

please make a backup from your library first. i dont want to be held responsible for any damage caused by this script.


Imports System
Imports System.Windows.Forms
' //css_reference System.dll;
' //css_reference System.Windows.Forms.dll;
' //css_reference MediaCenter.dll;
Module Script   
    Sub Init( mediaCenterInterface as MediaCenter.MCAutomation, outputTextBox as Textbox)
        dim lijst as MediaCenter.IMJFilesAutomation 
        dim aantal,teller as integer
        Dim zoek as string   
             
            zoek="[Media Type]=[Video] -[Bookmark]=[],[0]"
            lijst=mediaCenterInterface.Search(zoek)
            aantal=lijst.GetNumberFiles()
              
            For teller=0 to aantal
                lijst.set(teller,"Bookmark","")
            next 
        
         'RemoveDVDBookmarks ()
         
    End Sub       
 
    sub RemoveDVDBookmarks()
        Dim DVDBM as string
        DVDBM="C:\Documents and Settings\[user name]\Application Data\J River\Media Center 12\Settings\DVD Bookmarks.dat"
        if My.Computer.FileSystem.FileExists(DVDBM)=true then
        My.Computer.FileSystem.DeleteFile(DVDBM)
        end if   
   end sub

End Module


EDIT: changed the script to something that should work better.
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #6 on: April 18, 2007, 06:05:20 pm »

Very Very Very Simple demonstation of events using VB.NET scripts.

Updated for later version of Script Plugin.

When an event is fired the event is show in the console window.
Stand alone Script Runner version attached

For some reason this script will not compile if the script runners MC reference is used.
For this reason it get's it's own reference out of proc....

____________________________________
Imports System
Imports System.Windows.Forms
' //css_reference System.dll;
' //css_reference System.Windows.Forms.dll;
' //css_reference Interop.MediaCenter.dll;
Class Script
    Inherits MarshalByRefObject    
    Sub Init( unusedRef as MediaCenter.MCAutomation)
        System.Console.WriteLine("Waiting on Events")    
       Dim mediaCenterInterface as MediaCenter.MCAutomation
       mediaCenterInterface = System.Runtime.InteropServices.Marshal.GetActiveObject("MediaJukebox Application")
        AddHandler mediaCenterInterface.FireMJEvent, AddressOf mediaCenter_FireMJEventHandler            
        System.Threading.Thread.Sleep(30000)
        
        System.Console.WriteLine("Stopped Waiting on Events")
        
    End Sub  
    
   Public Sub mediaCenter_FireMJEventHandler(ByVal bstrType As String, _
                                 ByVal bstrParam1 As String, _
                                 ByVal bstrParam2 As String) _
                                
        System.Console.WriteLine(bstrType + " " + bstrParam1 + " " + bstrParam2)      
        'MessageBox.Show(bstrType + " " + bstrParam1 + " " + bstrParam2)

    End Sub  
End Class                                          

______________________________________-

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #7 on: June 10, 2007, 06:21:32 pm »

Date Time Script
Fills Date time in from File Name
Script Runner version available from here:
http://uppit.com/d/9FXTI

___________________________________________________
using System;
using System.Windows.Forms;     
using System.IO;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
    public void Init(MediaCenter.MCAutomation mediaCenterInterface)
    {   
        //Save changes to file?
        const bool saveChanges=true;

        //Get the current playing now playlist
        MediaCenter.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
       
        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
        {     
            //Get the file from the current position in the playlist
            MediaCenter.IMJFileAutomation track = playlist.GetFile(counter);

            //Get the tracks filename
            string trackFileName=track.Filename;
           
            FileInfo currentFile = new FileInfo(trackFileName);
            //Get the Date Time string part of the filename                                             
            string dateTimeFromTrack = currentFile.Name.Substring(0,15); 
           
            //Insert extra characters
            dateTimeFromTrack = dateTimeFromTrack.Insert(4,"/");
            dateTimeFromTrack = dateTimeFromTrack.Insert(7,"/");
           
            dateTimeFromTrack = dateTimeFromTrack.Insert(13,":");
            dateTimeFromTrack = dateTimeFromTrack.Insert(16,":");
           
            dateTimeFromTrack = dateTimeFromTrack.Replace('-',' ');                       
           
            //Create Date Time
            DateTime trackDateTime = Convert.ToDateTime(dateTimeFromTrack);
           
            //Create Unix Time
            double unixSeconds = ConvertDateTimeToUnixSeconds(trackDateTime);
            unixSeconds = unixSeconds / 86400 + 25569;
            System.Console.WriteLine(dateTimeFromTrack + ":" +  unixSeconds.ToString());
           
           
            if (saveChanges==true)
            {
                track.Set("Date", unixSeconds.ToString());
            }
        }

    }
   
    private System.DateTime ConvertUnixSecondsToDateTime(double unixTime)
    {
        // First make a System.DateTime equivalent to the UNIX Epoch.
        System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

        // Add the number of seconds in UNIX timestamp to be converted.
        dateTime = dateTime.AddSeconds(unixTime).ToLocalTime();
       
        //Return Our DateTime
        return dateTime;
    } 
   
    private double ConvertDateTimeToUnixSeconds(System.DateTime date_time_convert)
    {     
        // First make a System.DateTime equivalent to the UNIX Epoch.
        DateTime date_time_base = new DateTime(1970,1,1,0,0,0,0);
       
        //Subtract seconds From Unix Epoch from our date, leaving us with just the number of seconds
        TimeSpan span = date_time_convert.ToUniversalTime() - date_time_base;

        // Return the number of seconds
        return (double)span.TotalSeconds;
    }

   

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #8 on: June 22, 2007, 05:41:50 pm »

Brings up Cover Art for tracks
that are in Playing Now, One Window at a time.
As one window is closed, it moves on to the next file.
______________________________________________________________-
using System;
using System.Windows.Forms;     
using System.IO; 
using System.Drawing;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
    public void Init(MediaCenter.MCAutomation mediaCenterInterface)
    {   
        //Get the current playing now playlist
        MediaCenter.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
       
        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
        {               
            //Get the file from the current position in the playlist
            MediaCenter.IMJFileAutomation track = playlist.GetFile(counter);

            //Get Image File, MC Will place it in a temp file, we will be returned the path
            string imageTempFilePath = track.GetImageFile(MediaCenter.MJImageFileFlags.IMAGEFILE_IN_FILE);
           
            if (File.Exists(imageTempFilePath))
            {
                //Create an Image resource and load our image into it from the file MC has given us.
                Image imageFile = Image.FromFile(imageTempFilePath);
           
                //Create a Form
                Form quickForm = new Form(); 
                                           
                //Set Form Background image to our retrieved image                                           
                quickForm.BackgroundImage = imageFile;
               
                //Layout Stretched
                quickForm.BackgroundImageLayout = ImageLayout.Stretch;
               
                //Show the Form
                Application.Run(quickForm);
               
                //Close the form.
                quickForm.Close();
            }
           
        }
    }
}

lOth

  • Citizen of the Universe
  • *****
  • Posts: 785
Re: Sample Script Files
« Reply #9 on: June 23, 2007, 07:41:23 am »

this got me thinking: would it possible to write a last.fm auto-DJ script? The goal would be to have something close to what amarok does with last.fm: get info from the currently playing track, look up similar artists on last.fm, cross the search result with what you have in your MC library, pick one random song from the crossed results, auto-queue that song at the end of the playing now list.

This is one of the best features in Amarok, it would be amazing to bring it to MC. Now, I'm ignorant about this scripting thing, no need to enter into too many details if this isn't doable.
Logged

eba

  • Galactic Citizen
  • ****
  • Posts: 351
Re: Sample Script Files
« Reply #10 on: December 08, 2007, 06:28:54 am »

Purpose:
A simple pair of scripts to allow mp3 players without compilation features to show (Multiple Artists) for the Artist and show the song artist as part of the song name.  Manually you would use the Copy Fields function to do this: (see below for field definitions)
Initial:
1. Copy [Artist] -> [Song Artist]
2. Copy [Name] -> [Song Name]
3. Copy [Song Name - Artist] -> [Name]
4. Copy [Album Artist (Auto)] -> [Artist]

*Sync handheld*

Reversal:
1. Copy [Song Artist (Auto)] -> [Artist]
2. Copy [Song Name (Auto)] -> [Name]

This means that for the sync you would have, for example:
Album: Shrek Original Soundtrack
Artist: (Multiple Artists)
Track Names:
Stay Home - Self
I'm a Believer - Smash Mouth
...


Configuration:
This script requires a few additional fields to store the extra data:
[Song Artist]: Standard Text Field

[Song Name]: Standard Text Field

[Song Artist (Auto)]: calculated field based on [Song Artist] or [Artist] if [Song Artist] is empty:
if(IsEmpty([Song Artist]),[Artist],[Song Artist])

[Song Name (Auto)]: calculated field based on [Song Name] or [Name] if [Song Name] is empty.
if(IsEmpty([Song Name]),[Name],[Song Name])

[Song Name - Artist]: calculated field to show the song name followed by the artist if the artist and the album artist are different.
if(IsEqual([Artist],[Album Artist (Auto)]),[Song Name (Auto)],[Song Name (Auto)] - [Artist])

Problem:
When doing this manually, it is almost instant, because you do the whole library at once, with just the tags taking a while to update.
The script uses a loop to do each file individually, which obviously takes a fair bit longer.
If anyone knows of any way to make the script do the whole lot in one go, please let me know!



Script for Before:
using System;

//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
   public void Init(MediaCenter.MCAutomation mediaCenterInterface)
   {
        //Search string checks artist against album artist to find all relevant files.  Once it has changed the artist to equal album
        //artist the file will no longer be found, making the script safe to run twice in a row.
        MediaCenter.IMJFilesAutomation files = mediaCenterInterface.Search("[Media Type]=Audio [=IsEqual([Artist], [Album Artist (Auto)])]=[0]");
       
        for (int counter = 0; counter < files.GetNumberFiles() ; ++counter)
        {
            files.Set(counter,"Song Artist",files.Get(counter,"Artist"));
            files.Set(counter,"Song Name",files.Get(counter,"Name"));
            files.Set(counter,"Name",files.Get(counter,"Song Name - Artist"));
            files.Set(counter,"Artist",files.Get(counter,"Album Artist (Auto)")); 
        }       
    }
   
}

Script for After:
using System;

//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
   public void Init(MediaCenter.MCAutomation mediaCenterInterface)
   {
        //Search string checks song artist against artist.  Should find nothing if the first script hasn't been run.
        MediaCenter.IMJFilesAutomation files = mediaCenterInterface.Search("[Media Type]=Audio [=IsEqual([Song Artist (Auto)], [Artist])]=[0]");
       
        for (int counter = 0; counter < files.GetNumberFiles() ; ++counter)
        {
            files.Set(counter,"Artist",files.Get(counter,"Song Artist (Auto)"));
            files.Set(counter,"Name",files.Get(counter,"Song Name (Auto)"));
        }
    }
}

EDIT: Have updated the scripts to remove some loops so that they go a bit faster...
EDIT2: Have changed the search strings so that only the relevant files are changed to make the scripts go a lot faster...this also gets rid of the problem of destroying your library if the script is run twice in a row, as the search doesn't find any files if this is the case :)

eba

  • Galactic Citizen
  • ****
  • Posts: 351
Re: Sample Script Files
« Reply #11 on: January 02, 2008, 10:00:41 am »

Purpose
To add some files to Playing Now, shuffling them into the remaining files to be played.
Change the search string at the start to change what is added.

EDIT: No longer of any use since 'Add (shuffle remaining)' has been added to MC's play options.

Script:
using System;

//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
   public void Init(MediaCenter.MCAutomation mediaCenterInterface)
   {
        const string searchString = "[Media Type]=audio playlists=\"Recently Imported\"";
       
        MediaCenter.IMJFilesAutomation newFiles = mediaCenterInterface.Search(searchString);
        MediaCenter.IMJCurPlaylistAutomation playingNow = mediaCenterInterface.GetCurPlaylist();
        MediaCenter.IMJFilesAutomation shuffleFiles = mediaCenterInterface.CreateFiles();;
       
        int next = playingNow.GetNextFile();
       
        //add all files after the currently playing track to a list and remove from playing now.
        while (next < playingNow.GetNumberFiles())
        {
            shuffleFiles.AddFile(playingNow.GetFile(next).GetAvailableFilename());
            playingNow.RemoveFile(next);
        }
       
        //add new files to list
        for(int counter = 0; counter < newFiles.GetNumberFiles(); ++counter)
        {
            shuffleFiles.AddFile(newFiles.GetFile(counter).GetAvailableFilename());
        }                         
       
        //shuffle list
        shuffleFiles.Shuffle();
       
        //add files in list to playing now
        for(int counter = 0; counter < shuffleFiles.GetNumberFiles(); ++counter)
        {
            playingNow.AddFile(shuffleFiles.GetFile(counter).GetAvailableFilename(),-1);
        }
    }
}

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #12 on: April 11, 2008, 04:07:06 pm »

Purpose
Gives a quick example of how to get the filenames for the files in a play list.
Uses the playing now playlist as an example.

Script:

using System;
using System.Windows.Forms;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
    public void Init(MediaCenter.MCAutomation mediaCenterInterface)
    {       
       //Get the current playing now playlist
        MediaCenter.IMJCurPlaylistAutomation  myPlaylist = mediaCenterInterface.GetCurPlaylist ( );


        for(int counter = 0; counter < myPlaylist.GetNumberFiles(); ++counter)
        {
            //Get Individual File From Playlist
            MediaCenter.IMJFileAutomation mediaFile = myPlaylist.GetFile(counter);
   
            //Get File Name
            string fileName = mediaFile.GetAvailableFilename();
   
            //Do your business with File...   
            Console.WriteLine(fileName);
        } 

    }
}

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #13 on: April 15, 2008, 04:03:11 am »

Leezer3 wrote the following script to 'mux any AVI files in Playing Now into MKV format with MKV Merge'
http://yabb.jriver.com/interact/index.php?topic=46118.0

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1588
Re: Sample Script Files
« Reply #14 on: July 03, 2008, 06:42:54 pm »

This is a slightly rehashed version of Mr ChriZ's date from filename script, which someone may find a use for :)

V.0.2
Added some very primitive error checking :) If a date isn't found in your filename, the script will log this, as opposed to erroring out.

Purpose-
Fills the datetime from the filename.
This version can process dates in these formats:
Code: [Select]
DD.MM.YYYY
MM.DD.YYYY
YYYY.MM.DD
To change the format of the processed date, edit the string highlighted in red (The case must be maintained)

Notes:
The date (Including separators) must form the first 10 characters of the filename. Anything else may produce unpredictable results.
Please ensure you have the correct format entered before choosing to modify your database; The wrong format may cause oddities :)
A separator must be present, acceptable forms are either a period or a dash ( . or - )
The script currently does not parse the time itself, only the date.

Quote
using System;
using System.Windows.Forms;     
using System.IO;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
    public void Init(MediaCenter.MCAutomation mediaCenterInterface)
    {   
        //Save changes to file?
        const bool saveChanges=false;
       
        //Get the current playing now playlist
        MediaCenter.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
       
        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
        {     
            //Get the file from the current position in the playlist
            MediaCenter.IMJFileAutomation track = playlist.GetFile(counter);

            //Get the tracks filename
            string trackFileName=track.Filename;
            try
            {
            FileInfo currentFile = new FileInfo(trackFileName);
            //Get the Date Time string part of the filename                                             
            string dateTimeFromTrack = currentFile.Name.Substring(0,10);
            dateTimeFromTrack = dateTimeFromTrack.Replace(".","");
            dateTimeFromTrack = dateTimeFromTrack.Replace("-","");
            DateTime dateTimeFromTrack1 = DateTime.ParseExact(dateTimeFromTrack, "ddMMyyyy", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);         
           
            //Create Unix Time
            double unixSeconds = ConvertDateTimeToUnixSeconds(dateTimeFromTrack1);
            unixSeconds = unixSeconds / 86400 + 25569;
            System.Console.WriteLine(dateTimeFromTrack1 + ":" +  unixSeconds.ToString());
           
            if (saveChanges==true)
            {
                track.Set("Date", unixSeconds.ToString());
            }
            }
            catch (Exception)
            {
            //String was not a valid DateTime
            System.Console.WriteLine(track.Filename);
            System.Console.WriteLine("No valid date was found in this filename. Please check the ddMMyyyy setting and your filename.");
            }
            }

    }
   
    private System.DateTime ConvertUnixSecondsToDateTime(double unixTime)
    {
        // First make a System.DateTime equivalent to the UNIX Epoch.
        System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

        // Add the number of seconds in UNIX timestamp to be converted.
        dateTime = dateTime.AddSeconds(unixTime).ToLocalTime();
       
        //Return Our DateTime
        return dateTime;
    }
   
    private double ConvertDateTimeToUnixSeconds(System.DateTime date_time_convert)
    {     
        // First make a System.DateTime equivalent to the UNIX Epoch.
        DateTime date_time_base = new DateTime(1970,1,1,0,0,0,0);
       
        //Subtract seconds From Unix Epoch from our date, leaving us with just the number of seconds
        TimeSpan span = date_time_convert.ToUniversalTime() - date_time_base;

        // Return the number of seconds
        return (double)span.TotalSeconds;
    }

   
}


Cheers

-Leezer-
Logged

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1588
Re: Sample Script Files
« Reply #15 on: January 22, 2009, 04:51:19 am »

Another minor script after a forum request:
Purpose:
This is a quick and dirty script to copy the notes field from the first file in Playing Now to all others:

Notes:
*This will only work for default fields (Change Track2.Notes & Track.Notes for your required field names). Not sure if this is an issue with the scripting plugin or MC's definitions, others will have to investigate further really.
WARNINGS:
*This will mangle line breaks. I can probably write a slightly more complex version which saves the field to a text file and then reads it back again, but this is more of an example than anything.
*This script alters tags. Be 110% sure before you hit the trigger, I'd advise using on a backup library!

Quote
using System;
using System.Windows.Forms;     
using System.IO;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
    public void Init(MediaCenter.MCAutomation mediaCenterInterface)
    {   
        //Save changes to file?
        const bool saveChanges=false;
       
        //Get the current playing now playlist
        MediaCenter.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
        {
        //Get the file from the first position in the playlist
        MediaCenter.IMJFileAutomation track2 = playlist.GetFile(0);
        //Save the Info field to a string
        string trackInfo=track2.Notes;
       
        //Iterate through all the files in the playlist
        for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
        {     
            //Get the file from the current position in the playlist
            MediaCenter.IMJFileAutomation track = playlist.GetFile(counter);
            {
            if (saveChanges==true)
            {
            //Write the previously saved info for all files
            System.Console.WriteLine(trackInfo);
            track.Notes = trackInfo;
            }
            else
            {
            }
            }
            }
            }
    }
}
Logged

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1588
Re: Sample Script Files
« Reply #16 on: March 06, 2009, 11:03:50 am »

In response to a post in the main forum, this is a script to embed external subtitles into any given MKV. Largely based upon my MKV muxing script :)

Overview:
This script uses MrChriZ's scripting plugin to mux subtitles (.srt or .idx) into any MKVs present in Playing Now.
A new file will be produced, with -subs at the end to distinguish it from the original file, so it would look like this:
test.mkv ==> test-subs.mkv & so on.
Please don't assume its ready for primetime/ use on a live library- Its not, so please test on non-critical data first! Again, my coding may not be the best, but I think just about everything works as intended.

Available variables
These are the variables, which should be altered depending on how you want the script to run-
Quote
const bool autoupdate=false
true: The source AVI will be renamed to .bak or deleted (See below), and the new MKV will be inserted into the library (The filename has -subs inserted at the end, as you can't read & write an MKV at the same time).
false: You will be prompted as to whether to update the library with each muxed file. Choosing 'No' will leave the original file intact & in your library, regardless of whether you have selected to delete or rename files.
Quote
const bool deletefiles=true;
WARNING: SEVERE DATA DAMAGE/ LOSS POTENTIAL!!!
true: The source files will be deleted assuming a replacement is muxed.
false: Your original MKV file will be re-named to .bak & the subs will remain as-is. This is the default option, I'd advise only changing it if you are 100% sure things will work out fine ;)

A detailed log file may be found in %temp%\MKVMux_Log.txt (This logs to the scripting plugin console as well, but the detailed log should give times, as well as being persistant)
Code: [Select]
using System;
using System.Windows.Forms; 
using System.IO;
using System.Drawing;
using System.Data;
using System.ComponentModel;
using System.Collections;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
const bool autoupdate=false;
const bool deletefiles=false;

public string GetTempPath()
{
string path = System.Environment.GetEnvironmentVariable("TEMP");
if (!path.EndsWith("\\")) path += "\\";
return path;
}
public void LogMessageToFile(string msg)
{
System.IO.StreamWriter sw = System.IO.File.AppendText(
GetTempPath() + "MKVMux_log.txt");
try
{
string logLine = System.String.Format(
"{0:G}: {1}.", System.DateTime.Now, msg);
sw.WriteLine(logLine);
}
finally
{
sw.Close();
}
}
public void Init(MediaCenter.MCAutomation mediaCenterInterface)
{
//Start logging
LogMessageToFile("Subs Muxing started");
//Get the current playing now playlist
MediaCenter.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
//Iterate through all the files in the playlist
for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
{
//Get the file from the current position in the playlist
MediaCenter.IMJFileAutomation track = playlist.GetFile(counter);
string Extension= track.Filetype;
//Check the file's format- We can only mux subs into MKVs.
if (Extension == "mkv")
{
//Mux subs into the current MKV
System.Console.WriteLine("Needs muxing!");
System.Console.WriteLine("Looking for subtitles");
{
string subscheck=track.Filename;
subscheck= subscheck.Replace(".mkv",".srt");
string subscheck2=track.Filename;
subscheck2= subscheck2.Replace(".mkv",".idx");
if (File.Exists(subscheck))
{
//MKV Merge- With SRT Subs
string part1A=track.Filename;
string part2A="\"";
string part3A=" -o ";
string part4A=".mkv ";
string part5A=" ";
string subs=track.Filename;
subs= subs.Replace(".mkv",".srt");
string fileNameA=
string.Concat(part3A,part1A,part4A,part1A,part5A,subs);
fileNameA= fileNameA.Replace(".mkv.mkv","-subs.mkv");
//Launch MKV Merge
System.Console.WriteLine("Launching MKV Merge.....");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mkvmerge.exe";
//Pass the argument we constructed earlier
proc.StartInfo.Arguments = fileNameA;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
proc.WaitForExit();
//The MKV file has been created sucessfully- Print its path
System.Console.WriteLine(fileNameA);
System.Console.WriteLine("Muxed successfully!");
string fileName2= ("Muxed sucessfully!");
string fileName3=
string.Concat(part1A,fileName2);
LogMessageToFile(fileName3);
goto dbupdate;
}
if (File.Exists(subscheck2))
{
//MKV Merge- With IDX Subs
string part1A=track.Filename;
string part2A="\"";
string part3A=" -o ";
string part4A=".mkv ";
string part5A=" ";
string subs=track.Filename;
subs= subs.Replace(".mkv",".idx");
string fileNameA=
string.Concat(part3A,part1A,part4A,part1A,part5A,subs);
fileNameA= fileNameA.Replace(".mkv.mkv","-subs.mkv");
//Launch MKV Merge
System.Console.WriteLine("Launching MKV Merge.....");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mkvmerge.exe";
//Pass the argument we constructed earlier
proc.StartInfo.Arguments = fileNameA;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
proc.WaitForExit();
//The MKV file has been created sucessfully- Print its path
System.Console.WriteLine(fileNameA);
System.Console.WriteLine("Muxed successfully!");
string fileName2= ("Muxed sucessfully!");
string fileName3=
string.Concat(part1A,fileName2);
LogMessageToFile(fileName3);
goto dbupdate;
}
else
{
//No subs found- Nothing to do.
goto dontmux;
}
dontmux:
LogMessageToFile("No subs were found- Nothing to do");
}
dbupdate:
//Determines what to do with the original file.
//If autoupdate is set to true, then the original
//file will be renamed or deledted.
if (autoupdate==true)
{
//If deletefiles is set to true, the original file will be deleted.
//Otherwise, it will be renamed to .bak
if (deletefiles==true){
string deleteFile=track.Filename;
System.IO.File.Delete(deleteFile);
string deleteFile1=" has been deleted";
string deleteFile2=
string.Concat(deleteFile,deleteFile1);
LogMessageToFile(deleteFile2);
string deleteFile3=track.Filename;
deleteFile3= deleteFile3.Replace(".mkv",".srt");
deleteFile3= deleteFile3.Replace(".mkv",".idx");
System.IO.File.Delete(deleteFile3);
string deleteFile4=
string.Concat(deleteFile,deleteFile3);
LogMessageToFile(deleteFile4);
}
else
{
string trackFileBak1=track.Filename;
string trackFileBak2=track.Filename;
trackFileBak2= trackFileBak2.Replace(".mkv",".mkv.bak");
System.IO.File.Move(trackFileBak1, trackFileBak2);
string trackFileBak3= ("has been renamed to ");
string trackFileBak4=
string.Concat(trackFileBak1,trackFileBak3,trackFileBak2);
LogMessageToFile(trackFileBak4);
string trackFileName=track.Filename;
trackFileName= trackFileName.Replace(".mkv","-subs.mkv");
track.Filename = trackFileName;
string filetype = "mkv";
track.Filetype= filetype;
System.Console.WriteLine(trackFileName);
string trackFileBak5= ("Your database has been modified to point to the new MKV");
string trackFileBak6=
string.Concat(trackFileBak1,trackFileBak5);
LogMessageToFile(trackFileBak6);
}
}
if (autoupdate==false)
{
//If autoupdate is set to false, you will be prompted each time.
//Answering "No" will produce a new MKV which is not in the library
{
DialogResult reply = MessageBox.Show("Modify the database?",
"Do you want to modify the database to point to the new MKV?",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
 
if (reply == DialogResult.Yes){
if (deletefiles==true){
string deleteFile=track.Filename;
System.IO.File.Delete(deleteFile);
string deleteFile1=" has been deleted";
string deleteFile2=
string.Concat(deleteFile,deleteFile1);
LogMessageToFile(deleteFile2);
}
else{
string trackFileBak1=track.Filename;
string trackFileBak2=track.Filename;
trackFileBak2= trackFileBak2.Replace(".mkv",".mkv.bak");
System.IO.File.Move(trackFileBak1, trackFileBak2);
string trackFileBak3= ("has been renamed to ");
string trackFileBak4=
string.Concat(trackFileBak1,trackFileBak3,trackFileBak2);
LogMessageToFile(trackFileBak4);
}
string trackFileName=track.Filename;
string trackFileName1=track.Filename;
trackFileName= trackFileName1.Replace(".mkv","-subs.mkv");
track.Filename = trackFileName1;
string filetype = "mkv";
track.Filetype= filetype;
System.Console.WriteLine(trackFileName1);
string trackFileBak5= ("Your database has been modified to point to the new MKV");
string trackFileBak6=
string.Concat(trackFileName,trackFileBak5);
LogMessageToFile(trackFileBak6);
} else {
LogMessageToFile("Muxing was completed, but your database has not been modified at this time");
}
}
}
}
}
}
}

Cheers

-Leezer-
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Sample Script Files
« Reply #17 on: April 18, 2009, 04:45:01 am »

Purpose:
This script inserts the width and height of cover art images into a field of your choice where an image exists.
These can then be used to determine roughly the quality of the cover art for each cover art in the library.
At the time of writing there appears to be a bug with MC's handling of cover art across multiple Mp3's.
The script works on files that are in playing now, so you will have to add a few files to see the effect.

Configuration:
The first two variables fieldToUseForCoverArtHeight and fieldToUseForCoverArtWidth can be used to change which fields Media Center places the image widths and heights into.
Change the boolean overwriteOldValues if you want to overwrite all previous values

More Information
Can be found here Script to save cover art size

Code: [Select]
using System;
using System.Windows.Forms;     
using System.Collections.Generic;
using MediaCenter;       
using System.Drawing;         
using System.Runtime.Remoting.Lifetime;   
using System.IO;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{                                                                 
    private MediaCenter.MCAutomation mediaCenterInterface;
   
    public void Init(MediaCenter.MCAutomation mediaCenterInterfaceOld)
    {     
        //Get Interface to Media Center
        MCAutomation mediaCenterInterface = (MediaCenter.MCAutomation)System.Runtime.InteropServices.Marshal.GetActiveObject("MediaJukebox Application");
                   
        //Change the following to variables to change where the script places the image size'
        string fieldToUseForCoverArtHeight = "Image File (height)" ;
        string fieldToUseForCoverArtWidth = "Image File (width)";   
        bool overwriteOldValues = true;         
       
        //THE FOLLOWING VARIABLE SHOULD BE CAREFULLY CONSIDERED BEFORE SETTING TO TRUE!
        //The theory goes that files with embedded art will need to have the embedded art written out to a temporary directory
        //This flag will choose whether to delete the cover art afterwards
        //It's not beyond the realms of possability however that if you are not using embedded cover art, it could accidently delete the real image.
        //But at the same time it shouldn't.  Take Care You've been warned!
        bool deleteTempFiles = false;             
       
        //Set our Media Center Interface as an attribute
        this.mediaCenterInterface = mediaCenterInterface;
       
        //Get a list of audio files
        List<IMJFileAutomation> audioFiles = GetAudioFilesFromPlayingNow();   
       
        //Loop through the audio files getting the image file, measuring it's sides and placing them in the tags
        foreach (IMJFileAutomation audioFile in audioFiles)
        {                                                                                                                                                                                     
            if (audioFile.Get(fieldToUseForCoverArtHeight, true) == string.Empty || overwriteOldValues)
            {   
                //First try the external image
                bool externalImageFound = false;   
                bool internalImageFound = false;
                string imageTempFilePath = audioFile.Get("Image File", true);
                string musicPath = audioFile.Get("Filename (path)", true);
               
                if (imageTempFilePath != string.Empty)
                {   
                    //Try first the path we are given
                    FileInfo imageFile = new FileInfo(imageTempFilePath);
                    //Alternatively Try just the filename with the path of the music file.                   
                    FileInfo alternateImageFile = new FileInfo( Path.Combine(musicPath,imageTempFilePath));
                   
                    if (imageFile.Exists)
                    {
                        SetTags(imageFile.FullName, audioFile, fieldToUseForCoverArtHeight, fieldToUseForCoverArtWidth);
                        externalImageFound = true;
                    }
                    else if (alternateImageFile.Exists)
                    {
                        SetTags(alternateImageFile.FullName, audioFile, fieldToUseForCoverArtHeight, fieldToUseForCoverArtWidth);
                        externalImageFound = true;
                    }     
                }
               
                //If external File Failed try internal embedded image
                if (externalImageFound == false)
                {
                    imageTempFilePath = audioFile.GetImageFile(MediaCenter.MJImageFileFlags.IMAGEFILE_IN_FILE);               
                    if (imageTempFilePath != string.Empty)
                    {                             
                        internalImageFound = true;
                        SetTags(imageTempFilePath, audioFile, fieldToUseForCoverArtHeight, fieldToUseForCoverArtWidth);                       
                       
                        //If the user wishes it delete the temp files created by MC
                        if ( deleteTempFiles )
                        {                   
                            try
                            {                               
                                Console.WriteLine("Deleting image temp file " + imageTempFilePath);               
                                File.Delete(imageTempFilePath);
                            }
                            catch(Exception exception)
                            {
                                Console.WriteLine("Failed deleting image temp file " + imageTempFilePath);               
                            }
                        }
                    }                                       
                }
               
                if( (externalImageFound | internalImageFound) == false)
                {
                    Console.WriteLine("Media Center Returned No Image");               
                }
               
            }
            else
            {
                Console.WriteLine("Media Center File:" + audioFile.Filename + "  Cover Art Width:" + audioFile.Get(fieldToUseForCoverArtWidth, true) + "  Cover Art Height:" + audioFile.Get(fieldToUseForCoverArtHeight, true) );           
            }
        }
    }   
   
    private void SetTags(string imageFile, IMJFileAutomation audioFile, string fieldToUseForCoverArtHeight, string fieldToUseForCoverArtWidth)
    {
        //Create an image object from the file
        Image coverArtFile = Image.FromFile(imageFile);     
       
        //Set the attributes on the file
        audioFile.Set(fieldToUseForCoverArtHeight,coverArtFile.Height.ToString());
        audioFile.Set(fieldToUseForCoverArtWidth,coverArtFile.Width.ToString());
                       
        //Write out to the console information useful to the user
        Console.WriteLine("Media Center File:" + audioFile.Filename + "  Cover Art Width:" + coverArtFile.Width.ToString() + "  Cover Art Height:" + coverArtFile.Height.ToString() );
       
        coverArtFile.Dispose();
    }
                         
    /// <summary>
    /// Gets a list of audio files from Playing Now and returns them in a generic collection
    /// </summary>
    private List<IMJFileAutomation> GetAudioFilesFromPlayingNow()   
    {
        List<IMJFileAutomation> audioFiles = new List<IMJFileAutomation>();
       
        //Get all the files in the Playing now playlist
        MediaCenter.IMJCurPlaylistAutomation currentFileList = this.mediaCenterInterface.GetCurPlaylist();
       
        //Get Number of files in playlist
        int numberOfFilesInPlaylist = currentFileList.GetNumberFiles();

        //Enumerate through files in playlist
        for (int counter = 0; counter < numberOfFilesInPlaylist; ++counter)
        {
            if (currentFileList.GetFile(counter).Get("Media Type", true) == "Audio")
            {                                               
                IMJFileAutomation currentFile = currentFileList.GetFile(counter);                       
                audioFiles.Add(currentFile);                               
            }
        }
        return audioFiles;
    }                   
   
    public override Object InitializeLifetimeService()
    {
        return null;
    }
}
Pages: [1]   Go Up