SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-20-2009, 04:17 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Data Type Definitions and Access

Another Java/Studio noob question. I'm looking to modify some data that is of type sage.MediaFile[]. I understand that this variable is an array of sage.MediaFile objects (is that the right word?)

Two questions:

1. Where in the Sage docs can I find a definition of what's in each sage.MediaFile?

2. How do reference these items?

For example, I remember from my C days that there would be a "struc" to define the object along the lines of:

struc sage.MediaFile {
int item1;
int item2;
string item3;
}

and if I had a variable (call it MyArray) that was an array of sage.MediaFile then I could address data like this:

MyArray[1].item1 = 7;
MyArray[125].item3 = "some string";

So where do I find what items are in each sage.MediaFile and how do I manipulate the data in Java?

What I'm looking to do is loop through all the data elements in the array altering one item in each element.

If it helps, the data I want to manipulate was created as a call to GetMediaFile().

Thanks,

Tom
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #2  
Old 07-20-2009, 06:19 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Here's the link to javadoc for the sage api. Be sure to read the description section for the sage.api package, since it explains some very fundamental things about calling the sage api from java.

Even though the sage api is javadoc'd as being a java api, it is not a java in the true sense. The API docs are there for reference, but when you call the Sage api from studio, you can simply call the method names that exist in the javadoc.

ie, To get all media files, the javadoc, includes a sage.api.MediaFile class with a static method of GetMediaFiles(). From the stv, you would simply call GetMediaFiles()., but from pure java, you'd actually call something like
Code:
Object mediaFiles[] = sage.SageTV.api("GetMediaFiles")

// or to get all TV files
Object mediaFiles[] = sage.SageTV.api("GetMediaFiles", new Object[] {"T"})
Now, most people that use the SageTV api directly end up either writing their own wrappers for the most commonly used api calls, or they use greg's autogenerated api wrappers, or, if you are me, then you use my autogenerated wrappers.

Greg's wrappers, makes working with the Sage objects alot simpler. You basically get an object on which you can call methods, so something like,
Code:
MediaFile mf = MediaFileAPI.GetMediaFileById(123343);
System.out.println("Media Title: " + mf.getMediaTitle());
In My api, I actually mirror the actual api and it is used pretty much as Sage publishes the documentation, but I don't expose actual sage types, and there is no object wrapping.
Code:
Object mf = MediaFileAPI.GetMediaFileById(12322);
System.out.println("Title: " + MediaFileAPI.GetMediaTitle(mf));
Just to put in a plug for my api My APIs are also called the Sage Remote APIs, since their purpose was to expose and access sage from java from outside the running Sage JVM. I tend to use the apis in all my projects, since I can code and troubleshoot from my desktop, even though my sage server is running on a completely different box. But, when I deploy the code to the server, then the API will autosense that it is running within sage, and it work exactly the same.

BTW, a MediaFile is read only object (for the most part), and there are no simple ways to set mediafile metadata short of using the properties files, or by manually creating and importing new Show/Airing objects for a given media file. Check out the metadata editor part of nielm's webserver to see how much effort is involved in updating metadata for an existing media file.

Good luck with your programming.

Last edited by stuckless; 07-20-2009 at 06:29 PM. Reason: Added Links for Greg's API and the Remote APIs
Reply With Quote
  #3  
Old 07-20-2009, 07:10 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Thanks for all of the info Sean, but you have burst my bubble. I didn't know the sage.MediaFile was read only. Back to the drawing board....
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #4  
Old 07-20-2009, 07:25 PM
stanger89's Avatar
stanger89 stanger89 is offline
SageTVaholic
 
Join Date: May 2003
Location: Marion, IA
Posts: 15,188
The 6.5 beta has added a SetMediaFileMetadata API call to edit the metadata associated with a MediaFile.

I can't really think of anything else you'd want to change in it.
Reply With Quote
  #5  
Old 07-20-2009, 07:49 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by stanger89 View Post
The 6.5 beta has added a SetMediaFileMetadata API call to edit the metadata associated with a MediaFile.

I can't really think of anything else you'd want to change in it.
Just to clarify... SetMediaFileMetadata() is used to set the custom metadata fields (ie, user defined fields, such as those added by phoenix/fanart). But, If you call SetMediaFileMetadata("Title", "new title"), then it will not reset the sage title in the wiz.bin... but it may still write the "Title" to the .properties.
Reply With Quote
  #6  
Old 07-20-2009, 08:11 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Thanks Stanger, that's what I was looking for! Too many things to learn all at once so I missed that API.

So if I have an array of n MediaFile's how do I address an individual entry? Or is there a way to perform an operation on all n entries at the same time?

Here is my train of thought, let me know if I'm headed for a trainwreck....

I want to fix the way Sage handles music artists that have different capitalizations and leading "The "'s. For example I want "A Flock of Seagulls" and "A Flock Of Seagulls" to be treated as one artist, not two. Same thing for "The Beatles" and "Beatles".

I searched the default STV and there is a single variable called AllMusicFiles that is set by a single call to GetMediaFiles("ML"), like this:

Code:
AllMusicFiles = GetMediaFiles("ML")
All of the music data structures used in the default STV are built up based on the contents of AllMusicFiles. What I'd like to do is change the Artist names in AllMusicFiles (strip off "The " and change capitalizations) immediately after the call to GetMediaFiles().

So something like this logic:

Code:
For n = 1 to sizeof(AllMusicFiles) do
  SetMediaFileMetadata(AllMusicFiles[n], Artist, FixedUpArtistName(AllMusicFiles[n]))
FixedUpArtistName() is a Java function that I'll have to write. (I'm assuming this is not possible to do directly in Studio, right?)

I'm I on the right track? Is there an easier way to do what I am trying to do?

stuckless - I'm not interested in changing the wiz.bin. I just want to change the data once it's read into the STV

Thanks,

Tom
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.

Last edited by tmiranda; 07-20-2009 at 08:13 PM. Reason: Saw stuckless post
Reply With Quote
  #7  
Old 07-20-2009, 08:31 PM
stanger89's Avatar
stanger89 stanger89 is offline
SageTVaholic
 
Join Date: May 2003
Location: Marion, IA
Posts: 15,188
Quote:
Originally Posted by tmiranda View Post
Thanks Stanger, that's what I was looking for! Too many things to learn all at once so I missed that API.

So if I have an array of n MediaFile's how do I address an individual entry? Or is there a way to perform an operation on all n entries at the same time?

Here is my train of thought, let me know if I'm headed for a trainwreck....

I want to fix the way Sage handles music artists that have different capitalizations and leading "The "'s. For example I want "A Flock of Seagulls" and "A Flock Of Seagulls" to be treated as one artist, not two. Same thing for "The Beatles" and "Beatles".
I think the way to fix that is to fix the ID3 tags in your music files, that's where Sage pulls the data from. There should be plenty of tools that can do that.

And I obviously haven't followed the set metadata discussions
Reply With Quote
  #8  
Old 07-20-2009, 09:04 PM
razrsharpe razrsharpe is offline
Sage Icon
 
Join Date: Sep 2008
Location: Boston, MA
Posts: 2,111
Quote:
Originally Posted by tmiranda View Post
stuckless - I'm not interested in changing the wiz.bin. I just want to change the data once it's read into the STV
To be more specific you just want to change how sage handles and displays the data... not change the database... Calls to SetMediaFileMetadata will change the wiz.bin.

I think what you really want to do is have Sage group those artists ("The Beatles", "the beatles", and "beatles") properly so that in the media browser when browsing by artist they are all grouped together... therefore you need to use a GroupByMethod(AllMusicFiles, GroupMethod) call after the AllMusicFiles = GetMediaFile("ML") call... this is all in studio.

Code:
AllMusicFiles = GetMediaFile("ML")
GroupByMethod(AllMusicFiles, GroupMethod)
The trick is in the GroupMethod... this needs to be a java call that takes as a single argument one of the elements of AllMusicFiles and returns a string that the GroupByMethod will group the music file by. In your case it needs to be a custom java call that will take as input a music file, get the artist name, make it a constant case, and filter out the unwanted "the's" and "a's".

This is what the jar file that i sent you does (SMW also uses it). behind the scenes inside the call i do the following:

psuedocode
Code:
String musicartist = GetArtistName(MusicFile)
musicartist = tolowercase(musicartist)
filter out "the ", "the.", "a ", "a.", "an", and "an "
then return musicartist
now sage is has something useful to group by.
unfortunately, im not at home right now so i cant post the source that i did this with...


Quote:
Originally Posted by stuckless View Post
In My api, I actually mirror the actual api and it is used pretty much as Sage publishes the documentation, but I don't expose actual sage types, and there is no object wrapping.
...
Just to put in a plug for my api
Sean, on a side note I love your api.. At first i started interfacing with the sage api all manually... then i figured i would try out sagex... wow.. so much simpler it makes calling sage calls from custom code trivial love them thanks
__________________
Server 2003 r2 32bit, SageTV9 (finally!)
2x Dual HDHR (OTA), 1x HD-PVR (Comcast), 1x HDHR-3CC via SageDCT (Comcast)
2x HD300, 1x SageClient (Win10 Test/Development)
Check out TVExplorer

Last edited by razrsharpe; 07-20-2009 at 09:06 PM.
Reply With Quote
  #9  
Old 07-21-2009, 06:03 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Stanger - Yes, there are lots of ID3 editing tools but with 15,000 MP3 files to deal with it is next to impossible to get all the capitalization correct.

razrsharpe - Thanks for the info and also a big thanks for the code you already supplied me. I do not want to chaneg the wiz.bin so I will stay away from SetMediaFileMetadata().

The STV uses GroupByArrayMethod() to build the data that is eventually displayed but I do not fully understand how the function works. I do know however that AllMusicFiles is the foundation for all the data.

I'm at work and can't see the STV but the logic seems to be to extract all of the artist names from AllMusicFiles and then use the artist list and AllMusicFiles in GroupByArrayMethod(). My thinking is that if I can get the Artist names "fixed" in AllMusicFiles as soon as Sage loads it into memory(which is essentially changing the ID3 info after it's read into memory) then the STV will have "clean" data to work with and all will be well!

My main issue is that I do not understand what GroupByMethod() and GroupByArrayMethod() actually do. Remember, I'm a UNIX device driver guy, not a "high level language" guy and these functions are very "high level". I guess i have a lot more homework to do.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #10  
Old 07-21-2009, 06:39 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Hey,

I am still learning studio/java but basically the two calls are described here

GroupByArrayMethod

GroupByMethod

The difference is how the items are grouped. Array puts the group in a Array while GroupByMethod puts it into a Vector.

So say you have this

Code:
AllMusicFiles = GetMediaFiles("ML")
You could then group it by ArtistName by calling
Code:
AllMusicFiles = GroupByMethod(AllMusicFiles,false,"
GetAlbumArtist")
That will then group all the music files by the album artist names. So like Razorsaid you would replace the "GetAlbumArtist" with the appropriate call from his jar that makes them lowercase and removes "the" "a" and "an". I am not in front of my correct computer to get his actual calls for music files but they are there.

Hopefully that helps

On a Side note I would interested on where you are going with this fully and are you building on the defualt STV or SageMC? PM and we can talk.

Last edited by PLUCKYHD; 07-21-2009 at 06:41 AM.
Reply With Quote
  #11  
Old 07-21-2009, 08:36 AM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,624
Quote:
Originally Posted by PLUCKYHD View Post
I am still learning studio/java but basically the two calls are described here

GroupByArrayMethod

GroupByMethod

The difference is how the items are grouped. Array puts the group in a Array while GroupByMethod puts it into a Vector.
No, this is not the difference.

If you look at the documentation, you'll see that they both return the same thing. The difference is the return value of the Method used for performing the grouping of the original Data list. You can see example usage in the default STV.


GroupByMethod expects a Method that returns a single key at a time. Thus, you can use a call like:
Code:
AlbumGrouping = GroupByMethod(AllMusicFiles, "GetAlbumForFile")

GroupByArrayMethod expects a Method that returns an array of keys. Thus, this example call:
Code:
ArtistGrouping = GroupByArrayMethod(AllMusicFiles, "GetPeopleListInShowInRoles", ArtistRoles)
- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #12  
Old 07-21-2009, 08:41 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Andy,

Thanks now that makes more sense to me like I said I am still learning. So the results are the same it is just how it is expecting the group by call.
Reply With Quote
  #13  
Old 07-21-2009, 01:44 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by stuckless View Post
BTW, a MediaFile is read only object (for the most part), and there are no simple ways to set mediafile metadata short of using the properties files, or by manually creating and importing new Show/Airing objects for a given media file.
So just to be clear on this. Are you saying that if I have a statment like:

Code:
AllMediaFiles=getMediaFile("ML")
I can't edit the data in AllMediaFile? Not even if I write some Java code to get the job done?
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #14  
Old 07-21-2009, 01:55 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by tmiranda View Post
So just to be clear on this. Are you saying that if I have a statment like:

Code:
AllMediaFiles=getMediaFile("ML")
I can't edit the data in AllMediaFile? Not even if I write some Java code to get the job done?
No you can but you want to edit it in your sorting or grouping call not in the getmediafile call IMHO.

For instance if you called

Code:
AllMediaFiles = GroupByMethod(AllMediaFiles,false,"your java method")
That is where you would call to lowercase them all and use your java code to remove "the", "a" or whatever you are wanting to do.

"Yourjavacode" = call setup in your code.

I prefer to call it during sorting

Code:
AllMediFiles = SortLexical(AllMediaFiles,false,"your java method")
That way the grouping names stay in tact and they are sorted how you want but the names themselves are not changed in the interface.
Reply With Quote
  #15  
Old 07-21-2009, 02:39 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by tmiranda View Post
So just to be clear on this. Are you saying that if I have a statment like:

Code:
AllMediaFiles=getMediaFile("ML")
I can't edit the data in AllMediaFile? Not even if I write some Java code to get the job done?
Depends on what you mean by "edit the data". The array will be a mutable object that you can alter the contents of (e.g. insert, delete, sort, move items around, etc). But the individual MediaFile objects are not mutable in the sense that you do not have direct access to their field data, which is private to the class definition. What you do have is a set of public methods you can call on those objects. If the documentation for any given method says that it alters the contents of the object, then you should probably believe it. If none of the methods say that, i.e. if they're all "getter" methods with no "setter" methods, then the object is for practical purposes unalterable.

This is the whole point of object-oriented programming: the class decides what operations it allows on objects of that class. Clients of the class don't get to override those design choices and start fiddling with the raw data on their own. They have to work within the public interface defined by the class.

You are of course free to define your own data structures that you populate with data copied from MediaFile objects and then edit that copied data as you see fit. But the MediaFile objects themselves are off-limits to third-party modification, except as explicitly allowed by the MediaFileAPI methods. That's a good thing.
__________________
-- Greg
Reply With Quote
  #16  
Old 07-21-2009, 03:25 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Thanks Plucky and GKusnick. It's starting to make more sense now. This "object stuff" is just very different from what I am used to. The "grouping" stuff is also starting to make some sense.

Several people have all pointed me in the same direction and, lo and behold, it's starting to sink into my hard head.
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
  #17  
Old 07-22-2009, 05:56 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Eureka!

Hooray! My first STVi is working. I just need to do some more testing before I unleash it on the community.

Many, many, many thanks to all who helped me.

I wrote an STVi that combines Music Artists that only differ because of:
- Leading "The"
- Leading "A"
- Case sensitivity

So now if you have The Beatles, Beatles, the Beatles and you look under the "Artists" view they will all show up under "The Beatles".

Again, thank you all.

If anybody wants to look at it and provide constructive criticism please let me know.

Tom
__________________

Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Sage data using Windows Powershell rickw SageTV Customizations 0 12-29-2006 02:10 PM
Access to program guide data GKenny SageTV Customizations 4 02-26-2005 04:22 AM
Something I've always wondered about - how exactly does the STV Client access data? TerryMathews SageTV Software 1 12-15-2004 10:30 PM
Public Access EPG data ToonGal SageTV EPG Service 1 12-15-2004 01:27 PM
IRD Definitions for Blackbird? tankd0g SageTV Software 5 10-14-2004 05:53 PM


All times are GMT -6. The time now is 02:27 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.