# Custom Agent not updating

**URL:** <https://forums.plex.tv/t/custom-agent-not-updating/12853>\
**Category:** Dev/API Corner\
**Tags:** scanner-agent-dev\
**Created:** [December 1, 2011, 7:49pm UTC](https://forums.plex.tv/t/custom-agent-not-updating/12853 "2011-12-01T19:49:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ekuzai\_yahoo.com](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@ekuzai\_yahoo.com](https://forums.plex.tv/u/ekuzai_yahoo.com)\
**Post date:** [December 1, 2011, 7:49pm UTC](https://forums.plex.tv/t/custom-agent-not-updating/12853/1 "2011-12-01T19:49:18Z")

</div>

Hi,  
  
  
  
I’ve been looking over posts, and other agents to learn how to create my own agent.  
  
I think I’m close but I am stuck on why the info would not be updated.  
  
  
  
Here is the code I’m using…

```auto

import urllib2, urllib, unicodedata, re<br />
<br />
# URLS<br />
DMM_BASEURL = 'http://www.dmm.co.jp'<br />
DMM_SEARCH_MOVIES = DMM_BASEURL + '/search/=/searchstr=%s/analyze=V1EBCFcEUQM_/limit=30/n1=FgRCTw9VBA4GCF5WXA__/n2=Aw1fVhQKX19XC15nV0AC/sort=rank_asc/num=1/'<br />
DMM_DETAIL_PAGE = DMM_BASEURL + '%s'<br />
<br />
def Start():<br />
    HTTP.CacheTime = CACHE_1MINUTE<br />
    HTTP.SetHeader('User-agent', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)')<br />
<br />
class DmmAgent(Agent.Movies):<br />
    name = 'Dmm.co.jp'<br />
    languages = [Locale.Language.Japanese]<br />
    primary_provider = True<br />
    accepts_from = ['com.plexapp.agents.localmedia']<br />
    <br />
    def search(self, results, media, lang):<br />
        title = media.name<br />
        query = String.URLEncode(String.StripDiacritics(title.replace('-','')))<br />
        first_movie = HTML.ElementFromURL(DMM_SEARCH_MOVIES % query).xpath('//p[contains(@class,"tmb")][1]/a')<br />
        link = first_movie[0].get('href')<br />
        <br />
        results.Append(MetadataSearchResult(id=link, score=100, lang=lang))<br />
<br />
    def update(self, metadata, media, lang):<br />
        <br />
        for movie in HTML.ElementFromURL(DMM_DETAIL_PAGE % metadata.id).xpath('//div[contains(@class,"page-detail")]'):<br />
            metadata.title = movie.xpath('//h1[contains(@id, "title")]')[0].text<br />
            metadata.year = int(movie.xpath('//table[contains(@class, "mg-b20")]/tr[1]/td[2]')[0].text[:4])<br />
            metadata.summary = movie.xpath('//div[contains(@class,"mg-b20")]/p[contains(@class, "mg-b20")]')[0].text_content().strip()<br />
            metadata.studio = movie.xpath('//table[contains(@class, "mg-b20")]/tr[7]/td[2]/a')[0].text<br />
        <br />
        Log("[TITLE] = %s, [YEAR] = %s, [SUMMARY] = %s, [STUDIO] = %s" %(metadata.title, metadata.year, metadata.summary, metadata.studio) )

```

  
  
  
If I run this agent, the Log at the end of update shows all the correct title, year, summary, studio.  
I also checked this file /Library/Application Support/Plex Media Server/Metadata/Movies/8/da7efbf50b0cf23d766d625d2a2e633fb0043c0.bundle/Contents/com.plexapp.agents.dmm/Info.xml  
  
and checked that it is populated with the correct info.  
  
  
But if I check the movie, everything comes out blank.  
  
Is there some code I'm missing to push the info?  
  
Any help/pointers would be appreciated.  
  
Thanks!

---

<div class="post-metadata">

**Author:** ![ekuzai\_yahoo.com](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@ekuzai\_yahoo.com](https://forums.plex.tv/u/ekuzai_yahoo.com)\
**Post date:** [December 1, 2011, 10:08pm UTC](https://forums.plex.tv/t/custom-agent-not-updating/12853/2 "2011-12-01T22:08:28Z")

</div>

Fixed after playing around.  
  
  
  
The metadata.id  
  
  
  
results.Append(MetadataSearchResult( **id=link** , score=100, lang=lang))  
  
  
  
cannot be a url.  
  
  
  
Changing it so that it only had alphabet/numbers fixed the problem.

---

<div class="post-metadata">

**Author:** ![otakugangata](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/otakugangata/32/4561_2.png) [@otakugangata](https://forums.plex.tv/u/otakugangata)\
**Post date:** [December 9, 2012, 10:02pm UTC](https://forums.plex.tv/t/custom-agent-not-updating/12853/3 "2012-12-09T22:02:29Z")

</div>

I could so really use this agent, is it completed?

---

<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, 9:28pm UTC](https://forums.plex.tv/t/custom-agent-not-updating/12853/4 "2019-12-20T21:28:55Z")

</div>

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