Page 12 of 23 FirstFirst ... 2101112131422 ... LastLast
Results 111 to 120 of 226

Thread: Trakt.tv

  1. #111

    Default

    Could this be a way to make it run as a service on windows?
    http://stackoverflow.com/questions/3...in-windows-how

  2. #112

    Default

    cant get it to work. nothing posted on trakt page.

    Have paired it okay, then i ran the command "c:\python27\python.exe traktforboxee.py"

    With the following result:
    2011-11-24 11:50:40,223::TraktForBoxee:EBUG::Initialized Trakt for Boxee.
    2011-11-24 11:50:40,223::BoxeeBoxPythonClient:EBUG::Initialized Boxee Box Pyth
    on Client.
    Traceback (most recent call last):
    File "traktforboxee.py", line 158, in <module>
    client = TraktForBoxee()
    File "traktforboxee.py", line 39, in __init__
    trakt_password = self.config.get("Trakt", "Password")
    File "c:\python27\lib\ConfigParser.py", line 332, in get
    raise NoOptionError(option, section)
    ConfigParser.NoOptionError: No option 'Password' in section: 'Trakt'


    Im leaving the command line window open, and watched one movie on the boxee box but nothing posted. Watching some tv shows now.

  3. #113

    Default

    Quote Originally Posted by TheTrooper View Post
    cant get it to work. nothing posted on trakt page.

    Have paired it okay, then i ran the command "c:\python27\python.exe traktforboxee.py"

    With the following result:
    2011-11-24 11:50:40,223::TraktForBoxee:EBUG::Initialized Trakt for Boxee.
    2011-11-24 11:50:40,223::BoxeeBoxPythonClient:EBUG::Initialized Boxee Box Pyth
    on Client.
    Traceback (most recent call last):
    File "traktforboxee.py", line 158, in <module>
    client = TraktForBoxee()
    File "traktforboxee.py", line 39, in __init__
    trakt_password = self.config.get("Trakt", "Password")
    File "c:\python27\lib\ConfigParser.py", line 332, in get
    raise NoOptionError(option, section)
    ConfigParser.NoOptionError: No option 'Password' in section: 'Trakt'


    Im leaving the command line window open, and watched one movie on the boxee box but nothing posted. Watching some tv shows now.
    Looks like your config settings are wrong.

  4. #114
    Join Date
    Dec 2010
    Posts
    23

    Default

    In regards to the requests to run it as a service I will definitely look into that, thank you for the suggestion. It will probably end up being a unix-only solution as the windows solution doesn't appear nearly as nice.

    Quote Originally Posted by TheTrooper View Post
    cant get it to work. nothing posted on trakt page.

    Have paired it okay, then i ran the command "c:\python27\python.exe traktforboxee.py"

    With the following result:
    2011-11-24 11:50:40,223::TraktForBoxee:EBUG::Initialized Trakt for Boxee.
    2011-11-24 11:50:40,223::BoxeeBoxPythonClient:EBUG::Initialized Boxee Box Pyth
    on Client.
    Traceback (most recent call last):
    File "traktforboxee.py", line 158, in <module>
    client = TraktForBoxee()
    File "traktforboxee.py", line 39, in __init__
    trakt_password = self.config.get("Trakt", "Password")
    File "c:\python27\lib\ConfigParser.py", line 332, in get
    raise NoOptionError(option, section)
    ConfigParser.NoOptionError: No option 'Password' in section: 'Trakt'


    Im leaving the command line window open, and watched one movie on the boxee box but nothing posted. Watching some tv shows now.
    That suggests something is wrong with your settings.cfg file, like SpyDawg suggested. If you could, create an issue on the project page with that debug output as well as your settings.cfg file without your passwords/usernames.
    Interested in tracking what you watch on your Boxee Box to Trakt.tv? Check out the Trakt For Boxee Client now!

  5. #115
    Join Date
    Dec 2010
    Posts
    135

    Default

    Quote Originally Posted by dloc View Post
    In regards to the requests to run it as a service I will definitely look into that, thank you for the suggestion. It will probably end up being a unix-only solution as the windows solution doesn't appear nearly as nice.



    That suggests something is wrong with your settings.cfg file, like SpyDawg suggested. If you could, create an issue on the project page with that debug output as well as your settings.cfg file without your passwords/usernames.
    Thanks!

    I'm also looking into it (partly to start with python, partly because i'd just like to mess around with it . If I have something, I'll post it here.

    Other request: logging to file. If this is a service/daemon, the console output will not be catched on some system. Having own log files might be better then.

    Thanks for the awesome stuff you've created so far, enjoying it very much

  6. #116
    Join Date
    Dec 2010
    Posts
    23

    Default

    Quote Originally Posted by dieterblomme View Post
    Thanks!

    I'm also looking into it (partly to start with python, partly because i'd just like to mess around with it . If I have something, I'll post it here.

    Other request: logging to file. If this is a service/daemon, the console output will not be catched on some system. Having own log files might be better then.

    Thanks for the awesome stuff you've created so far, enjoying it very much
    Well, as my project is open source feel free to fork it and if/when you get anything you want to add just throw a pull request my way and I'll take a look.

    In regards to the logging it will of course change to file if run as a daemon, gotta have logs!
    Interested in tracking what you watch on your Boxee Box to Trakt.tv? Check out the Trakt For Boxee Client now!

  7. #117
    Join Date
    Dec 2010
    Posts
    135

    Default

    Got an error, probably due to internet connectivity issues, but no more calls are being made now:
    Code:
    2011-11-25 02:06:58,162::TraktClient::DEBUG::Response from Trakt: <html>
    <head><title>504 Gateway Time-out</title></head>
    <body bgcolor="white">
    <center><h1>504 Gateway Time-out</h1></center>
    <hr><center>nginx/1.0.6</center>
    </body>
    </html>
    
    Traceback (most recent call last):
      File "/opt/local/Trakt-for-Boxee/TraktForBoxee.py", line 159, in <module>
        client.run()
      File "/opt/local/Trakt-for-Boxee/TraktForBoxee.py", line 122, in run
        episode=status["episode"])
      File "/opt/local/Trakt-for-Boxee/TraktClient.py", line 70, in update_media_status
        self.call_method(method, data)
      File "/opt/local/Trakt-for-Boxee/TraktClient.py", line 40, in call_method
        except (IOError, JSONDecodeError):
    NameError: global name 'JSONDecodeError' is not defined

  8. #118
    Join Date
    Dec 2010
    Posts
    23

    Default

    Quote Originally Posted by dieterblomme View Post
    Got an error, probably due to internet connectivity issues, but no more calls are being made now:
    Code:
    2011-11-25 02:06:58,162::TraktClient::DEBUG::Response from Trakt: <html>
    <head><title>504 Gateway Time-out</title></head>
    <body bgcolor="white">
    <center><h1>504 Gateway Time-out</h1></center>
    <hr><center>nginx/1.0.6</center>
    </body>
    </html>
    
    Traceback (most recent call last):
      File "/opt/local/Trakt-for-Boxee/TraktForBoxee.py", line 159, in <module>
        client.run()
      File "/opt/local/Trakt-for-Boxee/TraktForBoxee.py", line 122, in run
        episode=status["episode"])
      File "/opt/local/Trakt-for-Boxee/TraktClient.py", line 70, in update_media_status
        self.call_method(method, data)
      File "/opt/local/Trakt-for-Boxee/TraktClient.py", line 40, in call_method
        except (IOError, JSONDecodeError):
    NameError: global name 'JSONDecodeError' is not defined
    This should be fixed in the latest version.
    Interested in tracking what you watch on your Boxee Box to Trakt.tv? Check out the Trakt For Boxee Client now!

  9. #119
    Join Date
    Dec 2010
    Posts
    135

    Default

    Updated TraktForBoxee.py
    Now pair and daemon are options, they should work together as well

    Added daemonize function
    Changed main item (proposal: move this in main function and let last section just call that function)

    can somebody test this in full, i don't have access to a boxee box right now ...

    thanks!

    ps: we still need file logging i think, for a python developer, probably couple of mins work, i don't know how to start (this is my first python development )

    Code:
    #!/usr/bin/env python
    
    import logging
    import ConfigParser
    import boxeeboxclient
    import TraktClient
    import sys
    import time
    import re
    import os
    import getopt
    
    VERSION = "1.0"
    BOXEE_VERSION = BOXEE_DATE = ""
    TIMER_INTERVAL = 10
    
    class TraktForBoxee(object):
    
        def __init__(self):
            logging.basicConfig(format="%(asctime)s::%(name)s::%(levelname)s::%(message)s",
                                level=logging.INFO,
                                stream=sys.stdout)
    
            self.log = logging.getLogger("TraktForBoxee")
            self.log.info("Initialized Trakt for Boxee.")
    
            self.config = ConfigParser.RawConfigParser()
            self.config.read(sys.path[0] + "/settings.cfg")
    
            boxee_ip = self.config.get("Boxee", "IP")
            boxee_port = self.config.getint("Boxee", "Port")
    
            self.boxee_client = boxeeboxclient.BoxeeBoxClient("9001",
                                                              boxee_ip,
                                                              boxee_port,
                                                              "traktforboxee",
                                                              "Trakt for Boxee")
    
            trakt_api = "f46fbebb833fbeb8196b69e0e8d5de8f852b7ea6"
            trakt_username = self.config.get("Trakt", "Username")
            trakt_password = self.config.get("Trakt", "Password")
    
            self.trakt_client = TraktClient.TraktClient(trakt_api,
                                                        trakt_username,
                                                        trakt_password)
    
            build_info = self.boxee_client.getInfoLabels(["System.BuildVersion",
                                                          "System.BuildDate"])
            BOXEE_VERSION = build_info["System.BuildVersion"]
            BOXEE_DATE = build_info["System.BuildDate"]
    
            self.SCROBBLE_TV = self.config.getboolean("TraktForBoxee", "ScrobbleTV")
            self.SCROBBLE_MOVIE = self.config.getboolean("TraktForBoxee", "ScrobbleMovie")
            self.NOTIFY_BOXEE = self.config.getboolean("TraktForBoxee", "NotifyBoxee")
    
            self.scrobbled = False
            self.watching_now = ""
    
        def run(self):
            timer = 0
            while (True):
                timer += TIMER_INTERVAL
                status = self.boxee_client.getCurrentlyPlaying()
    
                tv = status["type"] == "tv"
    
                if (status["type"] == "none"):
                    self.log.debug("Boxee not playing anything, sleep.")
                    if (self.watching_now != ""):
                        self.log.info("We were just watching something, canceling our watching status on Trakt.tv")
                        self.trakt_client.cancelWatching()
                        self.watching_now = ""
                else:
                    boxee_idle = self.boxee_client.getIdle(300)
    
                    if (boxee_idle):
                        if (self.watching_now != ""):
                            self.log.info("Boxee is idle, cancelling watching status.")
                            self.watching_now = ""
                            self.trakt_client.cancelWatching()
                    else:
                        watching_now = (status["title"] + status["year"] +
                                        status["episode"] + status["season"] +
                                        status["episode_title"] + str(status["duration"]))
                        if (self.watching_now != watching_now):
                            self.watching_now = watching_now
                            self.scrobbled = False
                            self.log.debug("Now watching something else, canceling previous watching status.")
                            self.trakt_client.cancelWatching()
                            timer = 900 #Set watching first round through please
    
                        if ((tv and not self.SCROBBLE_TV) or
                            (not tv and not self.SCROBBLE_MOVIE)):
                            self.log.info("Set to ignore this media type, doing so.")
                        else:
                            if (status["percentage"] >= 90
                                and not self.scrobbled):
                                    self.log.info("Scrobbling to Trakt")
                                    if (self.NOTIFY_BOXEE):
                                        self.boxee_client.showNotification("Scrobbling to Trakt!")
    
                                    try:
                                        self.trakt_client.update_media_status(status["title"],
                                                                              status["year"],
                                                                              status["duration"],
                                                                              status["percentage"],
                                                                              VERSION,
                                                                              BOXEE_VERSION,
                                                                              BOXEE_DATE,
                                                                              tv=tv,
                                                                              scrobble=True,
                                                                              season=status["season"],
                                                                              episode=status["episode"])
                                        self.scrobbled = True
                                    except TraktClient.TraktError, (e):
                                        self.log.error("An error occurred while trying to scrobble: " + e.msg)
    
                            elif (status["percentage"] < 90
                                  and not self.scrobbled
                                  and timer >= 900):
                                self.log.info("Watching on Trakt")
                                timer = 0
    
                                try:
                                    self.trakt_client.update_media_status(status["title"],
                                                                          status["year"],
                                                                          status["duration"],
                                                                          status["percentage"],
                                                                          VERSION,
                                                                          BOXEE_VERSION,
                                                                          BOXEE_DATE,
                                                                          tv=tv,
                                                                          season=status["season"],
                                                                          episode=status["episode"])
    
                                    if (self.NOTIFY_BOXEE):
                                        self.boxee_client.showNotification("Watching on Trakt!")
                                except TraktClient.TraktError, (e):
                                    timer = 870
                                    self.log.error("An error occurred while trying to mark watching: " + e.msg)
    
                self.log.debug("NOT SCROBBLING... " + str(timer))
                time.sleep(TIMER_INTERVAL)
    
    def daemonize():
    
        # Make a non-session-leader child process
            try:
                pid = os.fork() #@UndefinedVariable - only available in UNIX
                if pid != 0:
                    sys.exit(0)
            except OSError, e:
                raise RuntimeError("1st fork failed: %s [%d]" %
                           (e.strerror, e.errno))
    
            os.setsid() #@UndefinedVariable - only available in UNIX
    
            # Make sure I can read my own files and shut out others
            prev = os.umask(0)
            os.umask(prev and int('077', 8))
    
            # Make the child a session-leader by detaching from the terminal
            try:
                pid = os.fork() #@UndefinedVariable - only available in UNIX
                if pid != 0:
                    sys.exit(0)
            except OSError, e:
                raise RuntimeError("2st fork failed: %s [%d]" %
                           (e.strerror, e.errno))
    
            dev_null = file('/dev/null', 'r')
            os.dup2(dev_null.fileno(), sys.stdin.fileno())
    
    def pair():
        config = ConfigParser.RawConfigParser()
        config.read(sys.path[0] + "/settings.cfg")
    
        ip = config.get("Boxee", "IP")
        port = config.get("Boxee", "Port")
    
        client = boxeeboxclient.BoxeeBoxClient("9001", ip, int(port), "traktforboxee",
                                               "Trakt for Boxee")
        client.callMethod("Device.PairChallenge", {'deviceid': "9001",
                                                   'applicationid': client.application_id,
                                                   'label': client.application_label,
                                                   'icon': "http://dir.boxee.tv/apps/workbench/images/thumb.png",
                                                   'type': 'other'})
    
        pattern = re.compile("^[0-9]{4}$")
    
        code = False
        while (not code or pattern.match(code) is None):
            code = raw_input("Enter the code displyed on the screen of your Boxee Box: ")
    
        client.callMethod("Device.PairResponse", {'deviceid': "9001", 'code': code})
        print "You are now ready to scrobble to Trakt.tv."

  10. #120
    Join Date
    Dec 2010
    Posts
    135

    Default

    Main code (had to split out because of length)

    Code:
    if __name__ == '__main__':
        Pair = False
        Daemon = False
    
        try:
            opts, args = getopt.getopt(sys.argv[1:], "dp", ['daemon', 'pair']) #@UnusedVariable
        except getopt.GetoptError:
            print "Available options: --daemon, --pair"
            sys.exit()
    
        for o, a in opts:
            # Pair to the Boxee box
            if o in ('-p', '--pair'):
                Pair = True
    
            # Run as a daemon
            if o in ('-d', '--daemon'):
                if sys.platform == 'win32':
                    print "Daemonize not supported under Windows, starting normally"
                else:
                    consoleLogging = False
                    Daemon = True
    
        if Pair:
            pair()
    
        if Daemon:
            daemonize()
    
        client = TraktForBoxee()
        client.run()

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •