Skip to content

Instantly share code, notes, and snippets.

@N3MIS15
Created April 28, 2013 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save N3MIS15/5478681 to your computer and use it in GitHub Desktop.
Save N3MIS15/5478681 to your computer and use it in GitHub Desktop.
test trakt addon rating
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.rate_test" version="0.0.1" name="Test Trakt Ratings" provider-name="N3MIS15">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.xbmcswift2" version="2.4.0" />
</requires>
<extension point="xbmc.python.pluginsource" library="plugin.py">
<provides>video</provides>
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en"></summary>
<description lang="en"></description>
<platform>all</platform>
<language>en</language>
<website></website>
<source></source>
<forum></forum>
<email></email>
</extension>
</addon>
# -*- coding: utf-8 -*-
import xbmcaddon
import xbmcgui
import urllib2
import urllib
from xbmcswift2 import Plugin, ListItem
plugin = Plugin()
__plugin__= "plugin.video.rate_test"
__addon__ = xbmcaddon.Addon(__plugin__)
show = {
"rating": "love",
"air_day": "Sunday",
"certification": "TV-MA",
"overview": "Based on the fantasy novel series \"A Song of Ice and Fire\", Game of Thrones explores the story of an epic battle among seven kingdoms and two ruling families in the only game that matters.. the Game of Thrones. All seek control of the Iron Throne, the possession of which ensures survival through the 40-year winter to come.",
"year": 2011,
"images": {
"fanart": "http://slurm.trakt.us/images/fanart/1395.23.jpg",
"poster": "http://slurm.trakt.us/images/posters/1395.23.jpg",
"banner": "http://slurm.trakt.us/images/banners/1395.23.jpg"
},
"watched": True,
"in_watchlist": False,
"ratings": {
"loved": 10266,
"percentage": 95,
"votes": 10437,
"hated": 171
},
"genres": [
"Action",
"Adventure",
"Drama",
"Fantasy"
],
"plays": 26,
"network": "HBO",
"title": "Game of Thrones",
"first_aired": 1303023600,
"poster": "http://slurm.trakt.us/images/posters/1395.23.jpg",
"tvdb_id": "121361",
"imdb_id": "tt0944947",
"air_time": "9:00pm",
"rating_advanced": 10,
"watchers": 30,
"url": "http://trakt.tv/show/game-of-thrones",
"country": "United States",
"runtime": 60,
"tvrage_id": "24493"
}
episode = {
"episode": {
"ratings": {
"loved": 866,
"percentage": 91,
"votes": 907,
"hated": 41
},
"plays": 1,
"title": "Winter Is Coming",
"url": "http://trakt.tv/show/game-of-thrones/season/1/episode/1",
"season": 1,
"tvdb_id": 3254641,
"number": 1,
"in_collection": True,
"in_watchlist": False,
"first_aired": 1303023600,
"overview": "Ned Stark, Lord of Winterfell learns that his mentor, Jon Arryn, has died and that King Robert is on his way north to offer Ned Arryn\u2019s position as the King\u2019s Hand. Across the Narrow Sea in Pentos, Viserys Targaryen plans to wed his sister Daenerys to the nomadic Dothraki warrior leader, Khal Drogo to forge an alliance to take the throne.",
"images": {
"screen": "http://slurm.trakt.us/images/episodes/1395-1-1.23.jpg"
},
"watched": True,
"rating_advanced": 10,
"rating": "love"
},
"show": {
"in_watchlist": False,
"ratings": {
"loved": 10266,
"percentage": 95,
"votes": 10437,
"hated": 171
},
"genres": [
"Action",
"Adventure",
"Drama",
"Fantasy"
],
"tvdb_id": "121361",
"air_day": "Sunday",
"network": "HBO",
"title": "Game of Thrones",
"url": "http://trakt.tv/show/game-of-thrones",
"country": "United States",
"first_aired": 1303023600,
"imdb_id": "tt0944947",
"air_time": "9:00pm",
"images": {
"fanart": "http://slurm.trakt.us/images/fanart/1395.23.jpg",
"poster": "http://slurm.trakt.us/images/posters/1395.23.jpg",
"banner": "http://slurm.trakt.us/images/banners/1395.23.jpg"
},
"rating_advanced": 10,
"year": 2011,
"certification": "TV-MA",
"runtime": 60,
"overview": "Based on the fantasy novel series \"A Song of Ice and Fire\", Game of Thrones explores the story of an epic battle among seven kingdoms and two ruling families in the only game that matters.. the Game of Thrones. All seek control of the Iron Throne, the possession of which ensures survival through the 40-year winter to come.",
"rating": "love",
"tvrage_id": "24493"
}
}
movie = {
"rating": False,
"certification": "PG-13",
"overview": "In an innocent heartland city, five are shot dead by an expert sniper. The police quickly identify and arrest the culprit, and build a slam-dunk case. But the accused man claims he's innocent and says \"Get Jack Reacher.\" Reacher himself sees the news report and turns up in the city. The defense is immensely relieved, but Reacher has come to bury the guy. Shocked at the accused's request, Reacher sets out to confirm for himself the absolute certainty of the man's guilt, but comes up with more than he bargained for.",
"year": 2012,
"images": {
"fanart": "http://slurm.trakt.us/images/fanart_movies/194674.3.jpg",
"poster": "http://slurm.trakt.us/images/posters_movies/194674.3.jpg"
},
"watched": False,
"in_watchlist": False,
"ratings": {
"loved": 730,
"percentage": 78,
"votes": 789,
"hated": 59
},
"genres": [
"Crime",
"Drama",
"Thriller"
],
"plays": 0,
"title": "Jack Reacher",
"tagline": "The Law Has Limits. He Does Not.",
"tmdb_id": "75780",
"poster": "http://slurm.trakt.us/images/posters_movies/194674.3.jpg",
"imdb_id": "tt0790724",
"released": 1356076800,
"rating_advanced": 0,
"watchers": 9,
"url": "http://trakt.tv/movie/jack-reacher-2012",
"in_collection": False,
"runtime": 130,
"trailer": "http://youtube.com/watch?v=lvQzb1YMdtY"
}
def base_media_li(media, media_type):
if media_type == "episode":
show = media['show']['title']
season = media['episode']['season']
episode = media['episode']['number']
ep_name = media['episode']['title']
label = "%s %ix%02d \"%s\"" % (show, season, episode, ep_name)
thumbnail = media['show']['images']['poster']
fanart = media['show']['images']['fanart']
else:
label = media['title']
thumbnail = media['images']['poster']
fanart = media['images']['fanart']
li = {
"label": label,
"thumbnail": thumbnail,
"path": plugin.url_for("index"),
"replace_context_menu": True,
"context_menu": [],
"properties": {
"Fanart_Image": fanart
}
}
if media_type == "show":
li['context_menu'] = [
("Rate With TVDB", "RunScript(script.trakt,action=rate,media_type=show,remoteid=%s)" % media['tvdb_id']),
("Rate With TV Rage", "RunScript(script.trakt,action=rate,media_type=show,remoteid=%s)" % media['tvrage_id']),
("Rate With IMDB", "RunScript(script.trakt,action=rate,media_type=show,remoteid=%s)" % media['imdb_id']),
]
elif media_type == "episode":
li['context_menu'] = [
("Rate With TVDB", "RunScript(script.trakt,action=rate,media_type=episode,remoteid=%s,season=%i,episode=%i)" % (media['show']['tvdb_id'], media['episode']['season'], media['episode']['number'])),
("Rate With TV Rage", "RunScript(script.trakt,action=rate,media_type=episode,remoteid=%s,season=%i,episode=%i)" % (media['show']['tvrage_id'], media['episode']['season'], media['episode']['number'])),
("Rate With IMDB", "RunScript(script.trakt,action=rate,media_type=episode,remoteid=%s,season=%i,episode=%i)" % (media['show']['imdb_id'], media['episode']['season'], media['episode']['number'])),
]
else:
li['context_menu'] = [
("Rate With TMDB", "RunScript(script.trakt,action=rate,media_type=movie,remoteid=%s)" % media['tmdb_id']),
("Rate With IMDB", "RunScript(script.trakt,action=rate,media_type=movie,remoteid=%s)" % media['imdb_id']),
]
return li
@plugin.route("/")
def index():
return [
base_media_li(show, "show"),
base_media_li(episode, "episode"),
base_media_li(movie, "movie")
]
if __name__ == '__main__':
plugin.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment