Exemplo n.º 1
0
    def request(self,url,data=None,retry=False,withToken=True):

        headers = {
            'content-type': 'application/json',
            # 'trakt-api-key': '14b5146e25005b96c03cb8b125d7b5cb452e15e0cfe073685dc92992bbb707f9', # komakino
            'trakt-api-key': 'd4161a7a106424551add171e5470112e4afdaf2438e6ef2fe0548edc75924868', # script.trakt
            # 'trakt-api-key': '90b2bb1a8203e81a0272fb8717fa8b19ec635d8568632e41d1fcf872a2a2d9d0', # stolen ;)
            'trakt-api-version': '2'
        }

        if withToken:
            headers.update({
                'trakt-user-login': addon.getSetting("trakt_username"),
                'trakt-user-token': self.token
            })

        fullurl = 'https://api-v2launch.trakt.tv/%s' % url

        log.info("Requesting %s with headers %s" % (fullurl,headers))

        req = urllib2.Request(fullurl,data,headers)
        req.add_header("User-Agent", USER_AGENT)

        try:
            response = urllib2.urlopen(req)
        except urllib2.HTTPError, e:
            log.error("http error: %s => %d %s" % (url, e.code, e.reason))
            return {}
Exemplo n.º 2
0
 def parse_json(self,data):
         try:
             import simplejson as json
         except ImportError:
             import json
         jsonData = json.loads(data)
         log.info(jsonData)
         return jsonData
Exemplo n.º 3
0
def run():
    log.info("Running service")

    sync_trakt_episodes = addon.getSetting('sync_trakt_episodes')
    sync_trakt_watchlist = addon.getSetting('sync_trakt_watchlist')
    sync_imdb_watchlist = addon.getSetting('sync_imdb_watchlist')

    if sync_trakt_episodes:
        sync.trakt_syncEpisodes()

    if sync_trakt_watchlist:
        sync.trakt_syncWatchlist()

    if sync_imdb_watchlist:
        sync.imdb_syncWatchlist()
Exemplo n.º 4
0
def run():
    log.info("Running service")

    sync_trakt_episodes = addon.getSetting('sync_trakt_episodes')
    sync_trakt_watchlist = addon.getSetting('sync_trakt_watchlist')
    sync_imdb_watchlist = addon.getSetting('sync_imdb_watchlist')

    if sync_trakt_episodes:
        sync.trakt_syncEpisodes()

    if sync_trakt_watchlist:
        sync.trakt_syncWatchlist()

    if sync_imdb_watchlist:
        sync.imdb_syncWatchlist()
Exemplo n.º 5
0
def createFile(item):
    typepath = addon.getSetting(item["type"] + '_folder')
    basepath = xbmc.translatePath(typepath)

    link        = generateLink(item)
    nfoLink     = generateNfoLink(item)

    item["title"] = clean_title(item["title"])

    if item["type"] is 'show':
        item["episode_title"] = clean_title(item["episode_title"])

        titleyear   = '%s' % (item["title"])
        folder      = os.path.join(titleyear,'Season %s' % item["season"])
        filename    = 'S%02dE%02d' % (item["season"],item["episode"])

    elif item["type"] is 'movie':
        titleyear   = '%s (%s)' % (item["title"],item["year"])
        folder      = titleyear
        filename    = titleyear

    folderpath      = os.path.join(basepath,folder)
    filepath        = os.path.join(basepath,folder,filename)
    scanpath        = os.path.join(typepath)

    if not os.path.exists(folderpath):
        try:
            os.makedirs(folderpath)
        except:
            pass

    if not os.path.isfile(filepath + '.strm'):
        with open(filepath + '.strm', "w") as strm_file:  # create .strm
            strm_file.write(link)
            log.info('File created: %s' % filename)

        with open(filepath + '.nfo', "w") as nfo_file:  # create .strm
            nfo_file.write(nfoLink)
            log.info('File created: %s' % filename)

        log.info(item)
        log.info('Update path: %s' % scanpath)

        xbmc.executebuiltin('XBMC.UpdateLibrary(video,"%s")' % scanpath);

        return True

    else:
        return False
Exemplo n.º 6
0
def extractItems(items):
    movies = []

    for item in items:

        movie = {"type":"movie"}

        matches = re.search('^(.*) \((\\d{4})\)$',item["title"])

        # If no match is found, it could be a TV series where instead of (2012) it would be like (2012 TV Series)
        if matches:
            movie["title"] = matches.group(1)
            movie["year"] = int(matches.group(2))

            matches = re.search('\/(tt\d*)',item["id"])

            if matches:
                movie["id"] = matches.group(1)
                movies.append(movie)
        else:
            log.info("Could not add item with title '%s'" % item["title"])

    return movies
Exemplo n.º 7
0
def extractItems(items):
    movies = []

    for item in items:

        movie = {"type": "movie"}

        matches = re.search('^(.*) \((\\d{4})\)$', item["title"])

        # If no match is found, it could be a TV series where instead of (2012) it would be like (2012 TV Series)
        if matches:
            movie["title"] = matches.group(1)
            movie["year"] = int(matches.group(2))

            matches = re.search('\/(tt\d*)', item["id"])

            if matches:
                movie["id"] = matches.group(1)
                movies.append(movie)
        else:
            log.info("Could not add item with title '%s'" % item["title"])

    return movies
Exemplo n.º 8
0
import sys, os, xbmc
sys.path.insert(
    0, os.path.join(os.path.dirname(__file__), 'resources', 'site-packages'))

from traktorbeam import service, log, addon

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    frequency = addon.getSetting("frequency")
    seconds = float(frequency) * 60 * 60

    log.info("Starting service. Running every %s seconds" % seconds)

    while True:

        service.run()

        # Sleep/wait for abort
        if monitor.waitForAbort(seconds):
            # Abort was requested while waiting. We should exit
            log.info("Stopping service")
            break
Exemplo n.º 9
0
 def getToken(self):
     log.info("Token is: %s" % self.token)
Exemplo n.º 10
0
 def __init__(self):
     log.info('Init traktorbeam trakt')
     if not self.token:
         self.requestToken()
     self.getToken()
Exemplo n.º 11
0
import sys, os, xbmc
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources', 'site-packages'))

from traktorbeam import service, log, addon

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    frequency = addon.getSetting("frequency")
    seconds = float(frequency) * 60 * 60

    log.info("Starting service. Running every %s seconds" % seconds)

    while True:

        service.run()

        # Sleep/wait for abort
        if monitor.waitForAbort(seconds):
            # Abort was requested while waiting. We should exit
            log.info("Stopping service")
            break
Exemplo n.º 12
0
def selectAction(title, options):
    ret = xbmcgui.Dialog().select(title, [opt[0] for opt in options])
    if 0 <= ret < len(options) and len(options[ret]) > 1 and hasattr(options[ret][1], '__call__'): 
        log.info('Running action: %s' % options[ret][0])
        options[ret][1]()