Created
August 29, 2010 20:19
-
-
Save elan/556652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#amazon | |
IMDB_MOVIE_PAGE = 'http://www.imdb.com/title/%s/' | |
IMDB_BASEURL = 'http://www.imdb.com' | |
def Start(): | |
HTTP.CacheTime = CACHE_1DAY | |
class AmazonAgent(Agent.Movies): | |
name = 'Amazon' | |
languages = [Locale.Language.English] | |
primary_provider = False | |
contributes_to = ['com.plexapp.agents.imdb'] | |
def search(self, results, media, lang): | |
try: | |
amazonSearchUrl = IMDB_BASEURL + HTML.ElementFromURL(IMDB_MOVIE_PAGE % str(media.primary_metadata.id)).xpath("//a[@class='linkasbutton-secondary' and contains(@href,'buy-at-amazon')]")[0].get('href') | |
except: #amazon link may be disabled on imdb page | |
return | |
results.Append( | |
MetadataSearchResult( | |
id = amazonSearchUrl, | |
score = 100 | |
) | |
) | |
def update(self, metadata, media, lang): | |
#load the product page and grab the image url | |
for product in HTML.ElementFromURL(metadata.id).xpath("//div[contains(@class,'productResult')]"): | |
if product.xpath('.//span[@class="format"]')[0].text != "Video On Demand": | |
amazonImageUrl = product.xpath('.//img')[0].get('src').replace('._SL160_AA115_','') | |
name = amazonImageUrl.split('/')[-1] | |
# Poster. | |
if name not in metadata.posters: | |
metadata.posters[name] = Proxy.Media(HTTP.Request(amazonImageUrl)) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment