The branch, dharma has been updated
       via  663bd781cb2bbdd4d75725bcb5831d7f8df209c1 (commit)
      from  f3c0365e0e8e110470c945ff4069b2405f5d1675 (commit)

- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=663bd781cb2bbdd4d75725bcb5831d7f8df209c1

commit 663bd781cb2bbdd4d75725bcb5831d7f8df209c1
Author: Zeljko Ametovic <[email protected]>
Date:   Wed Dec 8 12:31:30 2010 +0400

    [script.trakt] -v 0.0.7
    - fixed double submit
    - added error handling for bad user/pass
    - fixed unicode issue with special characters in show name
    - added German translation thanks to BurningSky!
    - corrected tvdb id send
    - changed os.getcwd() to getAddonInfo('path')
    - instruction in addon xml
    - extended check time to 164 seconds (minimum needed for 20 minute shows)

diff --git a/script.trakt/addon.xml b/script.trakt/addon.xml
index 2028829..60beac0 100644
--- a/script.trakt/addon.xml
+++ b/script.trakt/addon.xml
@@ -10,7 +10,16 @@
              library="default.py" />
   <extension point="xbmc.addon.metadata">
     <summary lang="en">trakt</summary>
-    <description lang="en">trakt helps you keep a record of what TV shows you 
are watching. Based on your favorites, trakt recommends additional shows that 
you'll enjoy! Get your account started on http://trakt.tv</description>
+    <description lang="en">
+               Installation instructions: 
+               After installing this plugin, sign up for an account at 
http://trakt.tv.  Then.. 
+               
+               1. Press c (or rightclick if using a mouse) and select 
configure 
+               2. Enter in username and password that you have set up on the 
trakt website and any other configuration you would like 
+               3. Navigate to Home > Programs and activate trakt* (location of 
trakt activation is skin dependent and may be in other places labeled Addons, 
Scripts, etc.) 
+               
+               Note: if you do not configure trakt to autostart, you will need 
to repeat step 5 any time you would like to submit tv shows
+    </description>
     <platform>all</platform>
   </extension>
 </addon>
diff --git a/script.trakt/changelog.txt b/script.trakt/changelog.txt
index 3fb1340..329d032 100644
--- a/script.trakt/changelog.txt
+++ b/script.trakt/changelog.txt
@@ -1,3 +1,13 @@
+Version 0.0.7
+       - fixed double submit
+       - added error handling for bad user/pass
+       - fixed unicode issue with special characters in show name
+       - added German translation thanks to BurningSky!
+       - corrected tvdb id send
+       - changed os.getcwd() to getAddonInfo('path')
+       - instruction in addon xml
+       - extended check time to 164 seconds (minimum needed for 20 minute 
shows)
+
 Version 0.0.6
        - added icon to notifications
        - now sending video progress % to api
diff --git a/script.trakt/default.py b/script.trakt/default.py
index cdd02df..fdefe8d 100644
--- a/script.trakt/default.py
+++ b/script.trakt/default.py
@@ -12,7 +12,7 @@ import re
 __scriptname__ = "trakt"
 __author__ = "Sean Rudford"
 __url__ = "http://trakt.tv/";
-__version__ = "0.0.6"
+__version__ = "0.0.7"
 __XBMC_Revision__ = ""
 
 def addPadding(number):
@@ -36,9 +36,13 @@ def CheckAndSubmit(Manual=False):
         global lastUpdate
         global video_id
         
-        if(lasttitle == title and lasttitle != ""):
-            Debug('lasttitle == title, getID set to False', False)
-            getID = False
+        iPercComp = 
CalcPercentageRemaining(xbmc.getInfoLabel("VideoPlayer.Time"), 
xbmc.getInfoLabel("VideoPlayer.Duration"))
+        
+        if iPercComp > (float(VideoThreshold) / 100) or lastUpdate == 0:
+            # do nothing and let it continue to main script
+            Debug("continuing to main script")
+        elif (time.time() - lastUpdate < 900):
+            return
         
         pauseCheck = xbmc.Player().getTime()
         time.sleep(1)
@@ -75,45 +79,24 @@ def CheckAndSubmit(Manual=False):
         if len(xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) >= 1: # TvShow
             sType = "TVShow"
             Debug("Found TV Show", False)
-            # get tvdb id
-            if (xbmc.getInfoLabel("VideoPlayer.Year") != "" and getID == True):
-                getID = False
-                try:
-                    query = "select c12 from tvshow where c00 = '" + 
unicode(xbmc.getInfoLabel("VideoPlayer.TvShowTitle"), 'utf-8') + "'"
-                    res = xbmc.executehttpapi("queryvideodatabase(" + query + 
")")
-                    tvid = re.findall('[\d.]*\d+',res) # find it
-
-                    if len(tvid[0].strip()) >= 1:
-                        video_id = tvid[0].strip();
-                except:        
-                    video_id = ""
-                
+            
             # format: title, year, season, episode, tvdbid
-            title = (unicode(xbmc.getInfoLabel("VideoPlayer.TvShowTitle"), 
'utf-8') +
-                    ',' + unicode(xbmc.getInfoLabel("VideoPlayer.Year"), 
'utf-8') +
-                    ',' + 
unicode(addPadding(xbmc.getInfoLabel("VideoPlayer.Season")), 'utf-8') +
-                    ',' + 
unicode(addPadding(xbmc.getInfoLabel("VideoPlayer.Episode")), 'utf-8') +
-                    ',' + video_id)
+            showname = xbmc.getInfoLabel("VideoPlayer.TvShowTitle")
+            showname = showname.replace(",", '')
+            title = (showname +
+                    ',' + xbmc.getInfoLabel("VideoPlayer.Year") +
+                    ',' + addPadding(xbmc.getInfoLabel("VideoPlayer.Season")) +
+                    ',' + addPadding(xbmc.getInfoLabel("VideoPlayer.Episode")))
 
         elif len(xbmc.getInfoLabel("VideoPlayer.Title")) >= 1: #Movie
             sType = "Movie"
             Debug("Found Movie", False)
             
-            if (xbmc.getInfoLabel("VideoPlayer.Year") != "" and getID == True):
-                getID = False
-                try:
-                    query = "select case when not movie.c09 is null then 
movie.c09 else 'NOTFOUND' end as [MovieID] from movie where movie.c00 = '" + 
unicode(xbmc.getInfoLabel("VideoPlayer.Title")) + "' limit 1"
-                    res = xbmc.executehttpapi("queryvideodatabase(" + query + 
")")
-                    movieid = re.findall('>(.*?)<',res) # find it
-                    if len(movieid[1].strip()) >= 1:
-                        video_id = str(movieid[1].strip())
-                except:       
-                    video_id = ""
-            
             # format: title, year
-            title = (unicode(xbmc.getInfoLabel("VideoPlayer.Title"), 'utf-8') 
+ ',' +
-                    unicode(xbmc.getInfoLabel("VideoPlayer.Year"), 'utf-8') + 
',' +
-                    video_id)
+            moviename = xbmc.getInfoLabel("VideoPlayer.TvShowTitle")
+            moviename = moviename.replace(",", '')
+            
+            title = (moviename + ',' + xbmc.getInfoLabel("VideoPlayer.Year"))
                 
             #don't submit if not in library
             if (xbmc.getInfoLabel("VideoPlayer.Year") == ""):
@@ -125,26 +108,63 @@ def CheckAndSubmit(Manual=False):
         
         Debug("Title: " + title)
         
-        if ((title != "" and lasttitle != title) and not bExcluded):
-            iPercComp = 
CalcPercentageRemaining(xbmc.getInfoLabel("VideoPlayer.Time"), 
xbmc.getInfoLabel("VideoPlayer.Duration"))
+        if ((title != "" and lasttitle != title) and not bExcluded):           
     
+            get_id(sType)
+            
             if (iPercComp > (float(VideoThreshold) / 100)):
                 Debug('Title: ' + title + ', sending watched status, current 
percentage: ' + str(iPercComp), True)
-                SendUpdate(title, int(iPercComp*100), sType, "watched")
-                getID = True
+                SendUpdate(title+","+video_id, int(iPercComp*100), sType, 
"watched")
                 lasttitle = title
             elif (time.time() - lastUpdate >= 900):
                 Debug('Title: ' + title + ', sending watching status, current 
percentage: ' + str(iPercComp), True)
-                SendUpdate(title, int(iPercComp*100), sType, "watching")
+                SendUpdate(title+","+video_id, int(iPercComp*100), sType, 
"watching")
                 lastUpdate = time.time();
     
     else:
         Debug('Resetting last update timestamp')
         lastUpdate = 0
+        getID = True
+
+
+def get_id(video_type):
+    global getID
+    global video_id
     
+    getID = False
+    Debug("Looking up video ID (tvdb or imdb)", False)
+    
+    if video_type == "Movie":
+        try:
+            query = "select case when not movie.c09 is null then movie.c09 
else 'NOTFOUND' end as [MovieID] from movie where movie.c00 = '" + 
xbmc.getInfoLabel("VideoPlayer.Title") + "' limit 1"
+            res = xbmc.executehttpapi("queryvideodatabase(" + query + ")")
+            movieid = re.findall('>(.*?)<',res) # find it
+            if len(movieid[1].strip()) >= 1:
+                video_id = str(movieid[1].strip())
+        except:
+            video_id = ""
+            
+    elif video_type == "TVShow":
+        try:
+            query = "select c12 from tvshow where c00 = '" + 
xbmc.getInfoLabel("VideoPlayer.TvShowTitle") + "'"
+            res = xbmc.executehttpapi("queryvideodatabase(" + query + ")")
+            tvid = re.findall('[\d.]*\d+',res) # find it
+
+            if len(tvid[0].strip()) >= 1:
+                video_id = tvid[0].strip();
+        except:
+            video_id = ""
+
+
+###Settings related parsing
+__settings__ = xbmcaddon.Addon(id='script.trakt')
+__language__ = __settings__.getLocalizedString
+_ = sys.modules[ "__main__" ].__language__
+__cwd__ = __settings__.getAddonInfo('path')
+
 ###Path handling
-BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 
'resources', 'lib' ) )
-LANGUAGE_RESOURCE_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 
'resources', 'language' ) )
-MEDIA_RESOURCE_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 
'resources', 'skins' ) )
+BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 
'lib' ) )
+LANGUAGE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 
'resources', 'language' ) )
+MEDIA_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 
'skins' ) )
 sys.path.append (BASE_RESOURCE_PATH)
 sys.path.append (LANGUAGE_RESOURCE_PATH)
 
@@ -152,11 +172,6 @@ from utilities import *
     
 Debug('----------- ' + __scriptname__ + ' by ' + __author__ + ', version ' + 
__version__ + ' -----------', False)
 
-###Settings related parsing
-__settings__ = xbmcaddon.Addon(id='script.trakt')
-__language__ = __settings__.getLocalizedString
-_ = sys.modules[ "__main__" ].__language__
-
 ###Vars and initial load
 bRun = True #Enter idle state waiting to submit
 bStartup = False
@@ -220,6 +235,6 @@ if ((bStartup and bAutoStart) or bRun):
         if (bAutoSubmitVideo):
             CheckAndSubmit()
 
-        time.sleep(15)
+        time.sleep(168)
 
 Debug( 'Exiting...', False)
diff --git a/script.trakt/resources/lib/utilities.py 
b/script.trakt/resources/lib/utilities.py
index ee41aff..41603cf 100644
--- a/script.trakt/resources/lib/utilities.py
+++ b/script.trakt/resources/lib/utilities.py
@@ -2,24 +2,27 @@ import sys
 import os

 import xbmc

 import xbmcaddon

+import re

 import string

 import urllib

 import urllib2

+from urllib2 import URLError

+

+__settings__ = xbmcaddon.Addon(id='script.trakt')

+__language__ = __settings__.getLocalizedString

+__version__ = "0.0.7"

+__cwd__ = __settings__.getAddonInfo('path')

 

 #Path handling

-LANGUAGE_RESOURCE_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 
'resources', 'language' ) )

-CONFIG_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 'resources', 
'settings.cfg' ) )

+LANGUAGE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 
'resources', 'language' ) )

+CONFIG_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 
'settings.cfg' ) )

 AUTOEXEC_PATH = xbmc.translatePath( 'special://home/userdata/autoexec.py' )

 AUTOEXEC_FOLDER_PATH = xbmc.translatePath( 'special://home/userdata/' )

-VERSION_PATH = xbmc.translatePath( os.path.join( os.getcwd(), 'resources', 
'version.cfg' ) )

+VERSION_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 
'version.cfg' ) )

 

 #Consts

 AUTOEXEC_SCRIPT = '\nimport 
time;time.sleep(5);xbmc.executebuiltin("XBMC.RunScript(special://home/addons/script.trakt/default.py,-startup)")\n'

 

-__settings__ = xbmcaddon.Addon(id='script.trakt')

-__language__ = __settings__.getLocalizedString

-__version__ = "0.0.6"

-

 def SendUpdate(info, progress, sType, status):

     Debug("Creating data to send", False)

     

@@ -34,12 +37,17 @@ def SendUpdate(info, progress, sType, status):
     

     Debug(info, False)

     

+    if (sType == "TVShow"):

+        ID = getID(sType, 
unicode(xbmc.getInfoLabel("VideoPlayer.TvShowTitle"), 'utf-8'))

+    elif (sType == "Movie"):

+        ID = getID(sType, unicode(xbmc.getInfoLabel("VideoPlayer.Title")))

+    

     # split on type and create data packet for each type

     if (sType == "Movie"):

         Debug("Parsing Movie", False)

         

         # format: title, year

-        title, year, imdbid = info.split(",")

+        title, year, ID = info.split(",")

         

         # set alert text

         submitAlert = __language__(45052).encode( "utf-8", "ignore" )

@@ -50,7 +58,7 @@ def SendUpdate(info, progress, sType, status):
                                     "status": status,

                                     "title": title, 

                                     "year": year,

-                                    "imdbid": imdbid,

+                                    "imdbid": ID,

                                     "progress": progress,

                                     "plugin_version": __version__,

                                     "media_center": 'xbmc',

@@ -62,7 +70,7 @@ def SendUpdate(info, progress, sType, status):
         Debug("Parsing TVShow", False)

         

         # format: title, year, season, episode

-        title, year, season, episode, tvdbid = info.split(",")

+        title, year, season, episode, ID = info.split(",")

         

         # set alert text

         submitAlert = __language__(45053).encode( "utf-8", "ignore" )

@@ -76,7 +84,7 @@ def SendUpdate(info, progress, sType, status):
                                     "year": year, 

                                     "season": season, 

                                     "episode": episode,

-                                    "tvdbid": tvdbid,

+                                    "tvdbid": ID,

                                     "progress": progress,

                                     "plugin_version": __version__,

                                     "media_center": 'xbmc',

@@ -95,16 +103,6 @@ def SendUpdate(info, progress, sType, status):
     

 def transmit(status):

     bNotify = __settings__.getSetting( "NotifyOnSubmit" )

-    # may use this later if other auth methods suck

-    # def basic_authorization(user, password):

-    #         bUsername = __settings__.getSetting( "Username" )

-    #         bPassword = __settings__.getSetting( "Password" )

-    #         if(bUsername == '' || bPassword == '')

-    #             xbmc.executebuiltin('Notification(Trakt,' + 
__language__(45051).encode( "utf-8", "ignore" ) + ',3000)')

-    #             return false

-    #         

-    #         s = user + ":" + password

-    #         return "Basic " + s.encode("base64").rstrip()

 

     req = urllib2.Request("http://api.trakt.tv/post";,

             status,

@@ -114,10 +112,17 @@ def transmit(status):
 

     try:

         f = urllib2.urlopen(req)

-    

+        response = f.read()

+        Debug("Return packet: "+response)

+        

+    except URLError, e:

+        if e.code == 401:

+            Debug("Bad username or password", False)

+            if (bNotify == "true"):

+                notification("Trakt: Bad Authentication!", "Check your login 
information", 5000, __settings__.getAddonInfo("icon"))

+                

     except:

-        # do nothing 'cept spit out error

-        Debug("", False)

+        # do nothing 'cept spit out error (catch all)

         if (bNotify == "true"):

             notification("Trakt", "Error sending status.  API may not be 
reachable", 10000, __settings__.getAddonInfo("icon"))

 

@@ -199,4 +204,29 @@ def notification( header="", message="", sleep=5000, 
icon=__settings__.getAddonI
     """ Will display a notification dialog with the specified header and 
message,

         in addition you can set the length of time it displays in milliseconds 
and a icon image. 

     """

-    xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i,%s)" % ( header, message, 
sleep, icon ) )
\ No newline at end of file
+    xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i,%s)" % ( header, message, 
sleep, icon ) )

+    

+def getID(sType, title):

+    video_id = ""

+    if (sType == "TVShow"):

+        # get tvdb id

+        try:

+            query = "select c12 from tvshow where c00 = '" + title + "'"

+            res = xbmc.executehttpapi("queryvideodatabase(" + query + ")")

+            tvid = re.findall('[\d.]*\d+',res) # find it

+

+            if len(tvid[0].strip()) >= 1:

+                video_id = tvid[0].strip();

+        except:        

+            video_id = ""

+    else:

+        try:

+            query = "select case when not movie.c09 is null then movie.c09 
else 'NOTFOUND' end as [MovieID] from movie where movie.c00 = '" + title + "' 
limit 1"

+            res = xbmc.executehttpapi("queryvideodatabase(" + query + ")")

+            movieid = re.findall('>(.*?)<',res) # find it

+            if len(movieid[1].strip()) >= 1:

+                video_id = str(movieid[1].strip())

+        except:

+            video_id = ""

+    

+    return video_id
\ No newline at end of file

-----------------------------------------------------------------------

Summary of changes:
 script.trakt/addon.xml                             |   11 ++-
 script.trakt/changelog.txt                         |   10 ++
 script.trakt/default.py                            |  115 +++++++++++---------
 script.trakt/resources/language/German/strings.xml |   24 ++++
 script.trakt/resources/lib/utilities.py            |   80 ++++++++++-----
 5 files changed, 164 insertions(+), 76 deletions(-)
 create mode 100644 script.trakt/resources/language/German/strings.xml


hooks/post-receive
-- 
Scripts

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to