Writing a plug-in
Writing a plug-in
Hi,
I read the plug-in page and, as a newly switched Mac-user, I don't know anything about developing software on OSX.
I read that I need Xcode and that it is on the OSX DVD but I saw that during installation you have to choose which packages you need
Do I need all of the packages or can I save some space?
I don't know if there is a new Xcode version other the one on the Leopard DVD, if so will "Software update" update Xcode too?
How can I test and debug a plug-in?
Sorry for so silly questions...
I read the plug-in page and, as a newly switched Mac-user, I don't know anything about developing software on OSX.
I read that I need Xcode and that it is on the OSX DVD but I saw that during installation you have to choose which packages you need
Do I need all of the packages or can I save some space?
I don't know if there is a new Xcode version other the one on the Leopard DVD, if so will "Software update" update Xcode too?
How can I test and debug a plug-in?
Sorry for so silly questions...
Only the standard installation is needed, the developer tools and GCC 4.0 (as well as the SDK for 10.4, but I don't think it's and option not to include the 10.4 SDK); everything else is optional. The Leopard version is the newest version. Software update will not update Xcode, but you can always download the latest version for free at developers.apple.com, although you will need to create a free account.
What plug-in are you interested in? If it's one of the ones we already have I can send you the source code. As well as a step by step on how to set-up. Otherwise let me know what website you are looking at and I can send you the sample plug-in pre-filled.
What plug-in are you interested in? If it's one of the ones we already have I can send you the source code. As well as a step by step on how to set-up. Otherwise let me know what website you are looking at and I can send you the sample plug-in pre-filled.
Just installed Xcode 3.0 from the Leopard DVD and there were few option to choose from so I hope I did the right one.
I'm interested in writing a plug-in for other Italian website (http://www.terminalvideo.it), I'm sorry but dvd.it and bow.it aren't the best websites to download from.
I'm interested in writing a plug-in for other Italian website (http://www.terminalvideo.it), I'm sorry but dvd.it and bow.it aren't the best websites to download from.
Here is a started plug-in for terminal video.
1. Unzip the project
2. Place a copy of DVDpedia.app in both "DVD terminalvideo/build/Debug" and "DVD terminalvideo/build/Release"
3. Open the Xcode project (blue icon)
4. In the menu Projects --> New Custom Executable choose the DVDpedia in "DVD terminalvideo/build/Debug"
5. Set the build configuration to "Debug". You can now run the project and test the plug-in, you can also use build and debug (command-y) to set breakpoints and use the debugger (command-shift-y). The great advantage of this is you can ctrl-click on the code and say 'add breakpoint' and the debugger will come up and stop the program at that point and you can step through each instruction and see the variables change. I have also left some "NSLog" that will print information as the plug-in runs. You only want to build in Release to share the plug-ins with others or to copy the plug-in from "DVD terminalvideo/build/Debug" to your home folder ~/Library/Application Support/DVDpedia/Plug-ins to install the plug-in in your regular DVDpedia. As you can see I have already added the director and the Image to get you started:
1. Unzip the project
2. Place a copy of DVDpedia.app in both "DVD terminalvideo/build/Debug" and "DVD terminalvideo/build/Release"
3. Open the Xcode project (blue icon)
4. In the menu Projects --> New Custom Executable choose the DVDpedia in "DVD terminalvideo/build/Debug"
5. Set the build configuration to "Debug". You can now run the project and test the plug-in, you can also use build and debug (command-y) to set breakpoints and use the debugger (command-shift-y). The great advantage of this is you can ctrl-click on the code and say 'add breakpoint' and the debugger will come up and stop the program at that point and you can step through each instruction and see the variables change. I have also left some "NSLog" that will print information as the plug-in runs. You only want to build in Release to share the plug-ins with others or to copy the plug-in from "DVD terminalvideo/build/Debug" to your home folder ~/Library/Application Support/DVDpedia/Plug-ins to install the plug-in in your regular DVDpedia. As you can see I have already added the director and the Image to get you started:
You only need to add more details information for the data you want to download. The file constant.h will give a list of all the keys you can use to pass data in, but they are mostly what you would expect.
The only hard part now is also data that is a list such as credits, it would be something like this (written in Safari so it might have typos):
The only hard part now is also data that is a list such as credits, it would be something like this (written in Safari so it might have typos):
Code: Select all
NSString *castSection = [templateImagesFolder stringBetween:@">Cast:" and:@"ShowCast"];
NSArray *credits = [castSection stringsBetween:@"sottolinguette href='/tvweb/appli" and:@"</"]; //notice plural of 'strings' returns a list of strings
NSMutableArray *creditsArray = [NSMutableArray array]; //To hold our credit information
NSEnumerator *creditsEnum = [credits objectEnumerator];
NSString *nextPerson;
while (nextPerson = [creditsEnum nextObject]) {
nextPerson = [nextPerson stringBetween:@">" and:@"END"]; //remove URL part
NSMutableDictionary *oneCredit = [NSMutableDictionary dictionary];
[oneCredit setValue:nextPerson forKey:@"name"];
//[oneCredit setValue:nextRole forKey:@"role"]; //if there was a role it would be added here tothe dictionary
[creditsArray addObject:oneCredit];
}
if ([creditsArray count])
[returnData setValue:creditsArray forKey:@"creditsSet"];
Ciao Conor,
I think I found all the TerminalVideo/DVDpedia variables I have just one question (as I don't know anything about Xcode): what will happen if I use the stringBetween on a field with multiple entries?
Take a look at "Giu' per il tubo" on Terminalvideo, there are two directors (Regia:)!
I think I found all the TerminalVideo/DVDpedia variables I have just one question (as I don't know anything about Xcode): what will happen if I use the stringBetween on a field with multiple entries?
Take a look at "Giu' per il tubo" on Terminalvideo, there are two directors (Regia:)!
You would have to merge the two names. See the credits above. Use the stringBetween:and: to get the entire section and then use the stringsBetweens:and: to get the individiual parts and clean them up and merge them. It would normally be easier as there is an Apple function to merge a list, but since here they have white spaces you need to clean that up as well.
This will work for both one director or many.
Code: Select all
NSString *directorSection = [templateImagesFolder stringBetween:@">Regia:" and:@"</TR"];
NSArray *directors = [castSection stringsBetween:@"'>" and:@"</"];
NSMutableString *directorsComplete = [NSMutableString string];
NSEnumerator *directorsEnum = [directors objectEnumerator];
NSString *nextDirector;
while (nextDirector = [directorsEnum nextObject]) {
nextDirector = [self removePrefixandSuffixSpace:nextDirector];
if (![directorsComplete isEqualToString:@""])
[directorsComplete appendString:@", "];
[directorsComplete appendString:nextDirector];
}
if (![directorsComplete isEqualToString:@""])
[returnData setValue: directorsComplete forKey:@"director"];
Thank you,
would you explain why this piece of code doesn't seem to work?
On the console.app I have the right value:
and the same on the Details message
But on the edit window I have just "Region: 2" and "Vdeo Format: PAL" (instead of the value Pal).
EDIT: Do you put the default value even if the plugin returns valid data?
would you explain why this piece of code doesn't seem to work?
Code: Select all
//Region
NSString *region = [results stringBetween:@"Codifica " and:@"</font>"]; // region section
region = [region stringBetween:@">" and:@"<"]; // cut to only the name
region = [self removePrefixandSuffixSpace:region];
NSLog (@"Region: %@", region);
if (region)
[returnData setObject:region forKey:MKKeyDVDRegion];
Code: Select all
31/01/08 00:41:45 DVDpedia[1161] Region: Area 2 (Europa/Giappone)
Code: Select all
31/01/08 00:41:45 DVDpedia[1161] Details: {
director = "David Yates
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
duration = "133
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tminuti";
genre = "Film - Family/Ragazzi";
imageLocation = "http://www.terminalvideo.com/images/articles/LRG/66/img_263466_LRG.jpg";
media = "Dvd
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
pictureFormat = "Wide Screen
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
price = "27,99
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t€
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
rated = "Per tutti";
region = "Area 2 (Europa/Giappone)
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
sound = "Dolby Digital 5.1
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
studio = "Warner Home Video";
title = "Harry Potter E L'Ordine Della Fenice (SE) (2 Dvd)
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(Dvd) (ITA)";
url = "http://www.terminalvideo.com/tvweb/applications/dettaglio.aspx?ART_Id=263466";
videoFormat = "Pal
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
}
EDIT: Do you put the default value even if the plugin returns valid data?
To the removePrefixandSuffixSpace: method you should add the remove the tab as well as part of the if statement add:
The region and the video format is being set to the default, it's a bug I need to fix. I will have it fixed for the next version. Thank you for pointing it out.
Code: Select all
|| [stringToClean hasPrefix:@"\t"]
and
|| [stringToClean hasSuffix:@"\t"]
I think that I will clone-out removePrefixandSuffixSpace to something like cleanString to remove spaces, \t, \n...Conor wrote:To the removePrefixandSuffixSpace: method you should add the remove the tab as well as part of the if statement add:The region and the video format is being set to the default, it's a bug I need to fix. I will have it fixed for the next version. Thank you for pointing it out.Code: Select all
|| [stringToClean hasPrefix:@"\t"] and || [stringToClean hasSuffix:@"\t"]
You can also re-download DVDpedia and the bug with region and video format from the plug-in being overridden by the default is fixed.
Ciao Conor,
thank you for the quick fix.
Yesterday I took a look at the removePrefixandSuffixSpace function and I saw that you remove wrong characters only if they are at the beginning or at the end of the string, so I tried to make a new function that will remove \t and \n (I thought to remove even double spaces) despite their position in the string, but I get lost in the Cocoa documentation.
I was searching for a function that would return a boolean if stringA is into stringB and I found the rangeOfString method (even if it returns a NSRange value) but the documentation stated that for a simple check would be better to use a NSPredicate but I didn't understand how to declare it.
This is the example they put on the Cocoa documentation:
At 1:30a.m. I gave up
I think today I will go with the rangeOfString...
thank you for the quick fix.
Yesterday I took a look at the removePrefixandSuffixSpace function and I saw that you remove wrong characters only if they are at the beginning or at the end of the string, so I tried to make a new function that will remove \t and \n (I thought to remove even double spaces) despite their position in the string, but I get lost in the Cocoa documentation.
I was searching for a function that would return a boolean if stringA is into stringB and I found the rangeOfString method (even if it returns a NSRange value) but the documentation stated that for a simple check would be better to use a NSPredicate but I didn't understand how to declare it.
This is the example they put on the Cocoa documentation:
Code: Select all
BOOL match = [myPredicate evaluateWithObject:myString];
I think today I will go with the rangeOfString...
Do you think that something like the following could work?
Code: Select all
NSString *wrongString = @"\\t"; //I think I have to escape \t
NSPredicate *myPredicate= [NSPredicate
predicateWithFormat:@"CONTAINS %@", wrongString];
while ([myPredicate evaluateWithObject:stringToClean]) {
remove wrongString;
}