# Wikipedia agent modification

**URL:** <https://forums.plex.tv/t/wikipedia-agent-modification/23310>\
**Category:** Dev/API Corner\
**Tags:** scanner-agent-dev\
**Created:** [November 17, 2012, 11:50am UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310 "2012-11-17T11:50:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![EtherMan](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@EtherMan](https://forums.plex.tv/u/EtherMan)\
**Post date:** [November 17, 2012, 11:50am UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/1 "2012-11-17T11:50:37Z")

</div>

I hope this hasnt been done before more smoothly as then it’s kindof wasted but atleast I havnt found any thread for it.  
  
I was getting really annoyed at the fact that the wikipedia agent fetched useless facts about the production, rather than the plot in the field for plot.  
  
All movie articles I checked on wikipedia, was always the first section used, so the modifications for making it fetch this section  
  
  
  
Open C:\Users%Username%\AppData\Local\Plex Media Server\Plug-ins\Wikipedia.bundle\Contents\Code\__init_\_.py  
  
  
  
Now there’s just 5 things to change.

1. if page.find("’’’’’") != -1: -\> if page.find("==") != -1:  
2. page = page[page.find("’’’’’"):] -\> page = page[page.find("=="):]  
3. end = page.find(’==’, index) -\> end = findnth(page, ‘==’, 2)  
4. summary = page[index+1:end].strip().strip(":") -\> summary = page[findnth(page, ‘==’, 1)+2:end].strip().strip(":")  
  
  
  
The last thing. Is add the findnth function.  
  
  

```auto

def findnth(haystack, needle, n):<br />
    parts= haystack.split(needle, n+1)<br />
    if len(parts)<=n+1:<br />
        return -1<br />
    return len(haystack)-len(parts[-1])-len(needle)

```

  
  
Add this code just before class WikipediaAgent(Agent.Movies):  
  
Ok, and it's done. The wikipedia agent will now fetch the full plot summary, and as long as the language of wikipedia you use still have plot as the first section it will work for your language as well. If no sections exist (such as if the article is only a stub), then no summary will be fetched and it will go on to next service rather than fetching the imo useless information that the original use. If you dont want to edit anything just use the attached file and place it in the same place. I post changes done to it as a way to edit future versions of this script.  
  
Please do tell if you encounter any problems with the changes made or if you have any suggestions for improvement to this (improvements to this function... Not improvements to the agent in general).

---

<div class="post-metadata">

**Author:** ![Trudge](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@Trudge](https://forums.plex.tv/u/Trudge)\
**Post date:** [November 17, 2012, 11:58am UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/2 "2012-11-17T11:58:31Z")

</div>

> [@](#):
>
> I hope this hasnt been done before more smoothly as then it's kindof wasted but atleast I havnt found any thread for it.  
> I was getting really annoyed at the fact that the wikipedia agent fetched useless facts about the production, rather than the plot in the field for plot.  
> All movie articles I checked on wikipedia, was always the first section used, so the modifications for making it fetch this section  
>   
> Open C:\Users\%Username%\AppData\Local\Plex Media Server\Plug-ins\Wikipedia.bundle\Contents\Code\_\_init\_\_.py  
>   
> Now there's just 5 things to change.  
>   
> 1. if page.find("'''''") != -1: -\> if page.find("==") != -1:  
> 2. page = page[page.find("'''''"):] -\> page = page[page.find("=="):]  
> 3. end = page.find('==', index) -\> end = findnth(page, '==', 2)  
> 4. summary = page[index+1:end].strip().strip(":") -\> summary = page[findnth(page, '==', 1)+2:end].strip().strip(":")  
>   
> The last thing. Is add the findnth function.  
>   
> 
> ```auto
> 
> def findnth(haystack, needle, n):<br />
> parts= haystack.split(needle, n+1)<br />
> if len(parts)<=n+1:<br />
> return -1<br />
> return len(haystack)-len(parts[-1])-len(needle)
> 
> ```
> 
>   
>   
> Add this code just before class WikipediaAgent(Agent.Movies):  
>   
> Ok, and it's done. The wikipedia agent will now fetch the full plot summary, and as long as the language of wikipedia you use still have plot as the first section it will work for your language as well. If no sections exist (such as if the article is only a stub), then no summary will be fetched and it will go on to next service rather than fetching the imo useless information that the original use. If you dont want to edit anything just use the attached file and place it in the same place. I post changes done to it as a way to edit future versions of this script.  
>   
> Please do tell if you encounter any problems with the changes made or if you have any suggestions for improvement to this (improvements to this function... Not improvements to the agent in general).

  
Hi,  
  
Couple of things;  
  
1) The agent will update itself and replace anything you have edited with defaults every so often  
2) Why don't you simply change the agent order so it gets this info from other locations? Put moviepostersdb at the top and themoviesdb 2nd - doing so will fill these fields before it even gets to looking for them from wikipedia.

---

<div class="post-metadata">

**Author:** ![EtherMan](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@EtherMan](https://forums.plex.tv/u/EtherMan)\
**Post date:** [November 17, 2012, 12:06pm UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/3 "2012-11-17T12:06:40Z")

</div>

> [@](#):
>
> Hi,  
>   
> Couple of things;  
>   
> 1) The agent will update itself and replace anything you have edited with defaults every so often  
> 2) Why don't you simply change the agent order so it gets this info from other locations? Put moviepostersdb at the top and themoviesdb 2nd - doing so will fill these fields before it even gets to looking for them from wikipedia.

  
  
1. I know it will. Which just means I'll have to redo the changes every so often as well. I could make some new agent out of it if I knew how but for now, I dont. Perhaps in the future I will do that.  
2. As a comparison, TMDB summary for Star Wars Episode IV. 2 Sentences. The summary from wikipedia. 24 sentences over 5 paragraphs. It's 1200% the amount of content. I certainly know what I prefer.

---

<div class="post-metadata">

**Author:** ![Trudge](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@Trudge](https://forums.plex.tv/u/Trudge)\
**Post date:** [November 17, 2012, 12:23pm UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/4 "2012-11-17T12:23:14Z")

</div>

> [@](#):
>
> 1. I know it will. Which just means I'll have to redo the changes every so often as well. I could make some new agent out of it if I knew how but for now, I dont. Perhaps in the future I will do that.

  
Yes, but worth pointing out to the others you are advising to do this that is isn't a one-off fix, but a continual ongoing very repetitive process.

---

<div class="post-metadata">

**Author:** ![EtherMan](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@EtherMan](https://forums.plex.tv/u/EtherMan)\
**Post date:** [November 17, 2012, 12:38pm UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/5 "2012-11-17T12:38:17Z")

</div>

> [@](#):
>
> Yes, but worth pointing out to the others you are advising to do this that is isn't a one-off fix, but a continual ongoing very repetitive process.

  
  
Well not so much that Im advicing others about anything. Im just showing a way to make the current wikipedia agent fetch that area instead. Though I've just now found a movie that did not work. But that's due to a formatting error on wikipedia. Gonna try and see if I cant figure out how to fix that.

---

<div class="post-metadata">

**Author:** ![EtherMan](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@EtherMan](https://forums.plex.tv/u/EtherMan)\
**Post date:** [November 22, 2012, 2:50pm UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/6 "2012-11-22T14:50:03Z")

</div>

Created a new bundle out of it so it now identifies as its own agent that doesnt get overwritten by updates. Just download and extract to the plugin dir, then you can configure it as the normal wikipedia agent.

---

<div class="post-metadata">

**Author:** ![robot2xl](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/robot2xl/32/4102_2.png) [@robot2xl](https://forums.plex.tv/u/robot2xl)\
**Post date:** [November 19, 2015, 11:05pm UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/7 "2015-11-19T23:05:50Z")

</div>

Many thanks!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 10:25pm UTC](https://forums.plex.tv/t/wikipedia-agent-modification/23310/8 "2019-12-20T22:25:27Z")

</div>

Closed on December 20, 2019, 10:25pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
