Writing a plug-in

Talk to other Pedia users about the programs, share tricks and tips or ask questions about existing features.
User avatar
Conor
Top Dog
Posts: 5343
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

I would use the string methods. The NSPredicate is powerful, but since you want to do a replace. I would go straight for the replaceOccurrencesOfString: method.

Code: Select all

[cleanString replaceOccurrencesOfString:@"\t" withString:@""  options:NSLiteralSearch range:NSMakeRange(0, [cleanString length])];
Stack as many of those in a row, there is no point in using the rangeOfString: to then determine if you are going to remove the same section. It's quite likely that internally replaceOccurrencesOfString: uses rangeOfString: method.

Code: Select all

[cleanString replaceOccurrencesOfString:@"\n\n" withString:@"\n"  options:NSLiteralSearch range:NSMakeRange(0, [cleanString length])];
Bug if you really want to be specific and find the range of a string, the location value of the range will let you know if the string was found:

Code: Select all

NSRange range = [results rangeOfString:@"\t"];
if (range.location != NSNotFound) {
    //match
}
There no need to escape the back slash as "\t" is equal to tab.
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Post by Rigido »

That's why you wrote *pedias and I just wrote small VisualBasic routine! :(
I was going for the while loop in order to remove ALL of the occurrences of a given string and probably I didn't find this method because i was looking on the NSString class (hope I'm using right terms).
What do you think on substituting double spaces with single one (so, in case of an even number of spaces we will remain with just one)?
User avatar
Conor
Top Dog
Posts: 5343
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

Your going to need the "while" loop to run the replace a number of times until there are no double spaces. The replaceOccurrencesOfString: returns the number of replacements that took place, so adding it to a while loop is enough.

Code: Select all

while ([cleanString replaceOccurrencesOfString:@"\n\n" withString:@"\n"  options:NSLiteralSearch range:NSMakeRange(0, [cleanString length])] != 0);
The "!= 0" is not needed and can be implicit, but I put it in to make clear what is happening.

Your doing really well for recently diving into Cocoa and objective-C. It's a documentation heavy language as there is so much to it. Inheritance is one of the tricky parts to remember. That an object might respond to more messages than are in NSString, that it might be a subset or that it has parents that have more methods. Speaking of NSMutableString, make sure to turn the string you pass into the method into a NSMutableString if necessary, just like the other clean method.
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Post by Rigido »

Here I am...again! :)
First I would like to ask what do you think about assumptions (hope the online dictionary works well). I mean that I put on the plugin some code to convert video format to uppercase (so we will always have PAL and NTSC) and even to convert to uppercase media type if string length <= 3 (DVD, HD or BD but not blu-ray).
Secondly I have a little problem with actors code

Code: Select all

	//Cast
	NSString *castSection = [results 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:@"</a"]; //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 to the dictionary
		   [creditsArray addObject:oneCredit];
	}
	if ([creditsArray count])
		   [returnData setValue:creditsArray forKey:@"creditsSet"];
It looks good on the console

Code: Select all

05/02/08 00:38:16 DVDpedia[1047] Details: {
    creditsSet =     (
                {
            name = "Alan Rickman";
        },
                {
            name = "Brendan Gleeson";
        },
                {
            name = "Daniel Radcliffe";
        },
                {
            name = "Emma Watson";
        },
                {
            name = "Fiona Shaw";
        }
    );
But nothing appears on DVDpedia Input window, any hint?
User avatar
Conor
Top Dog
Posts: 5343
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

I have to update the constant.h but the real key for credits is just "credits" without the "Set", sorry about that old information. It should be:

Code: Select all

[returnData setValue:creditsArray forKey:@"credits"];
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Post by Rigido »

Conor wrote:I have to update the constant.h but the real key for credits is just "credits" without the "Set", sorry about that old information. It should be:

Code: Select all

[returnData setValue:creditsArray forKey:@"credits"];
Do I have to change the constant.h on my project too?
User avatar
Conor
Top Dog
Posts: 5343
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

Not in this case, as you are using the string directly @"credits" and not the constant MKKeyDVDCredits.
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Post by Rigido »

Ciao Conor...you've got mail... ;)
James23
Junior Member
Junior Member
Posts: 3
Joined: Wed Feb 20, 2008 7:37 pm
Contact:

Post by James23 »

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.
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Post by Rigido »

James23 wrote: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.
That's almost true...
Conor sent me a plug-in skeleton and I just had to write code to extract data but the constants.h file was not updated (that's why I asked about creditsSet, the constat in the header file...).
lenbanks
Contributor
Contributor
Posts: 5
Joined: Sun Apr 13, 2008 4:46 pm

Re: Writing a plug-in

Post by lenbanks »

I too would like a new sight added to search, but even after reading the instructions you offer to do this, it is just not in my skill set. Anyone open to doing this and making it available? The sight I want to add for searches is DVDEmpire.com. Before I started using DVDpedia, I was using another program that had them in the search options. Certainly Amazon and imdb are the best, but there just are those times when DVDEmpire had a better cover or summary.

Thanks in advance!!!
Post Reply