The branch, dharma has been updated
       via  8ed272d03d341972a5fe027b531b9a98c1f4b193 (commit)
      from  e696fa3cfd1c9a82df4dd3b7e75ee42d4f7127ae (commit)

- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/plugins;a=commit;h=8ed272d03d341972a5fe027b531b9a98c1f4b193

commit 8ed272d03d341972a5fe027b531b9a98c1f4b193
Author: spiff <[email protected]>
Date:   Tue May 17 11:36:55 2011 +0200

    [plugin.video.drnu] updated to version 1.3.0

diff --git a/plugin.video.drnu/addon.xml b/plugin.video.drnu/addon.xml
index ef2ceb2..e188e9b 100644
--- a/plugin.video.drnu/addon.xml
+++ b/plugin.video.drnu/addon.xml
@@ -1,9 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<addon id="plugin.video.drnu" version="1.2.1" name="DR NU Player" 
provider-name="InKaKiLLeR, twinther [[email protected]]">
+<addon id="plugin.video.drnu" version="1.3.0" name="DR NU Player" 
provider-name="InKaKiLLeR, twinther [[email protected]]">
     <requires>
         <import addon="xbmc.python" version="1.0"/>
         <import addon="script.module.simplejson" version="2.0.10"/>
-        <import addon="script.module.danishaddons" version="1.1.0"/>
     </requires>
     <extension point="xbmc.python.pluginsource" library="drnu.py">
         <provides>video</provides>
diff --git a/plugin.video.drnu/api.py b/plugin.video.drnu/api.py
index bf0e162..c5d9073 100644
--- a/plugin.video.drnu/api.py
+++ b/plugin.video.drnu/api.py
@@ -1,20 +1,20 @@
 import os
-import simplejson as json
+import simplejson
+import time
+import urllib2
 
-import danishaddons
-import danishaddons.web
+class DrNuApi(object):
+    BASE_API_URL = 'http://www.dr.dk/NU/api/%s'
 
-BASE_API_URL = 'http://www.dr.dk/NU/api/%s'
+    def __init__(self, cachePath, cacheMinutes):
+        """
+        DR NU API specs is available at http://www.dr.dk/nu/api/
 
-class DRnuApi(object):
-    """
-    DR NU API specs is available at http://www.dr.dk/nu/api/
-
-       Keyword arguments:
-       cacheMinutes -- the contents will be retrieve from the cache if it's 
age is less than specified minutes
-
-    """
-    def __init__(self, cacheMinutes):
+        @param self:
+        @param cacheMinutes: the contents will be retrieve from the cache if 
it's age is less than specified minutes
+        @type cacheMinutes: int
+        """
+        self.cachePath = cachePath
         self.cacheMinutes = cacheMinutes
 
     def getProgramSeries(self):
@@ -33,21 +33,39 @@ class DRnuApi(object):
         return self._call_api('programseries/%s/videos' % programSeriesSlug, 
'programseries-%s.json' % programSeriesSlug)
 
     def getVideoById(self, id):
-        video = danishaddons.web.downloadUrl(BASE_API_URL % ('videos/%s' % id))
-        return json.loads(video)
+        return self._call_api('videos/%s' % id, 'videos-%s.json' % id)
 
     def getProgramSeriesImageUrl(self, programSlug, width, height = None):
         if height is None:
             height = width
-        return BASE_API_URL % ('programseries/%s/images/%dx%d.jpg' % 
(programSlug, width, height))
+        return self.BASE_API_URL % ('programseries/%s/images/%dx%d.jpg' % 
(programSlug, width, height))
 
     def getVideoImageUrl(self, id, width, height = None):
         if height is None:
             height = width
-        return BASE_API_URL % ('videos/%s/images/%dx%d.jpg' % (id, width, 
height))
+        return self.BASE_API_URL % ('videos/%s/images/%dx%d.jpg' % (id, width, 
height))
 
     def _call_api(self, path, cacheFilename):
-        response = danishaddons.web.downloadAndCacheUrl(
-                BASE_API_URL % path,
-                os.path.join(danishaddons.ADDON_DATA_PATH, cacheFilename), 
self.cacheMinutes)
-        return json.loads(response)
+        cachePath = os.path.join(self.cachePath, cacheFilename)
+        try:
+            cachedOn = os.path.getmtime(cachePath)
+        except OSError: # File not found
+            cachedOn = 0
+
+        if time.time() - self.cacheMinutes * 60 >= cachedOn:
+            # Cache expired or miss
+            u = urllib2.urlopen(self.BASE_API_URL % path)
+            content = u.read()
+            u.close()
+
+            f = open(cachePath, 'w')
+            f.write(content)
+            f.close()
+
+        else:
+            f = open(cachePath)
+            content = f.read()
+            f.close()
+
+        return simplejson.loads(content)
+
diff --git a/plugin.video.drnu/changelog.txt b/plugin.video.drnu/changelog.txt
index 8123113..1eaa3af 100644
--- a/plugin.video.drnu/changelog.txt
+++ b/plugin.video.drnu/changelog.txt
@@ -1,3 +1,7 @@
+[B]Version 1.3.0[/B] - 2011-05-16
+- Removed dependency on script.module.danishaddons
+- Fixed errors while display some program series
+
 [B]Version 1.2.1[/B] - 2011-02-01
 - Fixed problem with favorites and recently watched when lists were empty
 - Fixed problem with remove favorite
diff --git a/plugin.video.drnu/drnu.py b/plugin.video.drnu/drnu.py
index eeccc0d..23afb34 100644
--- a/plugin.video.drnu/drnu.py
+++ b/plugin.video.drnu/drnu.py
@@ -2,17 +2,17 @@ import pickle
 import os
 import sys
 
+import xbmc
 import xbmcgui
-
-import danishaddons
-import danishaddons.web
-import danishaddons.info
+import xbmcaddon
 
 import api
 import ui
 
 print "DRNU: %s" % sys.argv
 
+ADDON = xbmcaddon.Addon(id = 'plugin.video.drnu')
+
 def addFavorite(slug):
     if os.path.exists(FAVORITES_PATH):
         favorites = pickle.load(open(FAVORITES_PATH, 'rb'))
@@ -23,7 +23,7 @@ def addFavorite(slug):
         favorites.append(slug)
     pickle.dump(favorites, open(FAVORITES_PATH, 'wb'))
 
-    xbmcgui.Dialog().ok(danishaddons.msg(30008), danishaddons.msg(30009))
+    xbmcgui.Dialog().ok(ADDON.getLocalizedString(30008), 
ADDON.getLocalizedString(30009))
 
 def delFavorite(slug):
     if os.path.exists(FAVORITES_PATH):
@@ -31,7 +31,7 @@ def delFavorite(slug):
         favorites.remove(slug)
         pickle.dump(favorites, open(FAVORITES_PATH, 'wb'))
 
-    xbmcgui.Dialog().ok(danishaddons.msg(30008), danishaddons.msg(30010))
+    xbmcgui.Dialog().ok(ADDON.getLocalizedString(30008), 
ADDON.getLocalizedString(30010))
 
 def updateRecentlyWatched(slug):
     if os.path.exists(RECENT_PATH):
@@ -46,48 +46,60 @@ def updateRecentlyWatched(slug):
     recent = recent[0:10] # Limit to ten items
     pickle.dump(recent, open(RECENT_PATH, 'wb'))
 
+def parseParams(input):
+    params = {}
+    for pair in input.split('&'):
+        if pair.find('=') >= 0:
+            keyvalue = pair.split('=', 1)
+            params[keyvalue[0]] = keyvalue[1]
+        else:
+            params[pair] = None
 
+    return params
+    
 
 if __name__ == '__main__':
-    danishaddons.init(sys.argv)
-    api = api.DRnuApi(60)
-    ui = ui.DRnuUI(api)
+    dataPath = xbmc.translatePath(ADDON.getAddonInfo("Profile"))
+    api = api.DrNuApi(dataPath, 60)
+    ui = ui.DRnuUI(api, int(sys.argv[1]), sys.argv[0])
 
-    FAVORITES_PATH = os.path.join(danishaddons.ADDON_DATA_PATH, 
'favorites.pickle')
-    RECENT_PATH = os.path.join(danishaddons.ADDON_DATA_PATH, 'recent.pickle')
+    FAVORITES_PATH = os.path.join(dataPath, 'favorites.pickle')
+    RECENT_PATH = os.path.join(dataPath, 'recent.pickle')
+    
+    params = parseParams(sys.argv[2][1:])
 
-    if danishaddons.ADDON_PARAMS.has_key('slug'):
-        updateRecentlyWatched(danishaddons.ADDON_PARAMS['slug'])
-        
ui.listVideos(api.getProgramSeriesVideos(danishaddons.ADDON_PARAMS['slug']), 
False)
+    if params.has_key('slug'):
+        updateRecentlyWatched(params['slug'])
+        ui.listVideos(api.getProgramSeriesVideos(params['slug']), False)
 
-    elif danishaddons.ADDON_PARAMS.has_key('newest'):
+    elif params.has_key('newest'):
         ui.listVideos(api.getNewestVideos(), False)
 
-    elif danishaddons.ADDON_PARAMS.has_key('spot'):
+    elif params.has_key('spot'):
         ui.listVideos(api.getSpotlightVideos(), True)
 
-    elif danishaddons.ADDON_PARAMS.has_key('search'):
+    elif params.has_key('search'):
         ui.searchVideos()
 
-    elif danishaddons.ADDON_PARAMS.has_key('id'):
-        ui.playVideo(danishaddons.ADDON_PARAMS['id'])
+    elif params.has_key('id'):
+        ui.playVideo(params['id'])
 
-    elif danishaddons.ADDON_PARAMS.has_key('all'):
+    elif params.has_key('all'):
         ui.getProgramSeries()
 
-    elif danishaddons.ADDON_PARAMS.has_key('addfavorite'):
-        addFavorite(danishaddons.ADDON_PARAMS['addfavorite'])
+    elif params.has_key('addfavorite'):
+        addFavorite(params['addfavorite'])
 
-    elif danishaddons.ADDON_PARAMS.has_key('delfavorite'):
-        delFavorite(danishaddons.ADDON_PARAMS['delfavorite'])
+    elif params.has_key('delfavorite'):
+        delFavorite(params['delfavorite'])
 
-    elif danishaddons.ADDON_PARAMS.has_key('favorites'):
+    elif params.has_key('favorites'):
         favorites = list()
         if os.path.exists(FAVORITES_PATH):
             favorites = pickle.load(open(FAVORITES_PATH, 'rb'))
         ui.getProgramSeries(favorites, False)
 
-    elif danishaddons.ADDON_PARAMS.has_key('recentlywatched'):
+    elif params.has_key('recentlywatched'):
         recent = list()
         if os.path.exists(RECENT_PATH):
             recent = pickle.load(open(RECENT_PATH, 'rb'))
diff --git a/plugin.video.drnu/ui.py b/plugin.video.drnu/ui.py
index ddb902b..29e464d 100644
--- a/plugin.video.drnu/ui.py
+++ b/plugin.video.drnu/ui.py
@@ -1,41 +1,42 @@
 import re
 import datetime
 import os
+import urllib2
 
 import xbmc
 import xbmcgui
+import xbmcaddon
 import xbmcplugin
 
-import danishaddons
-import danishaddons.web
-import danishaddons.info
-
 class DRnuUI(object):
-    def __init__(self, api):
+    ADDON = xbmcaddon.Addon(id = 'plugin.video.drnu')
+    def __init__(self, api, addonHandle, addonPath):
         self.api = api
+        self.addonHandle = addonHandle
+        self.addonPath = addonPath
 
     def getMainMenu(self):
-        iconImage = os.path.join(danishaddons.ADDON.getAddonInfo('path'), 
'icon.png')
+        iconImage = os.path.join(self.ADDON.getAddonInfo('path'), 'icon.png')
         # All Program Series
-        item = xbmcgui.ListItem(danishaddons.msg(30000), iconImage=iconImage)
-        xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, 
danishaddons.ADDON_PATH + '?all', item, isFolder=True)
+        item = xbmcgui.ListItem(self.ADDON.getLocalizedString(30000), 
iconImage=iconImage)
+        xbmcplugin.addDirectoryItem(self.addonHandle, self.addonPath + '?all', 
item, isFolder=True)
         # Latest
-        item = xbmcgui.ListItem(danishaddons.msg(30001), iconImage=iconImage)
-        xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, 
danishaddons.ADDON_PATH + '?newest', item, isFolder=True)
+        item = xbmcgui.ListItem(self.ADDON.getLocalizedString(30001), 
iconImage=iconImage)
+        xbmcplugin.addDirectoryItem(self.addonHandle, self.addonPath + 
'?newest', item, isFolder=True)
         # Spotlight
-        item = xbmcgui.ListItem(danishaddons.msg(30002), iconImage=iconImage)
-        xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, 
danishaddons.ADDON_PATH + '?spot', item, isFolder=True)
+        item = xbmcgui.ListItem(self.ADDON.getLocalizedString(30002), 
iconImage=iconImage)
+        xbmcplugin.addDirectoryItem(self.addonHandle, self.addonPath + 
'?spot', item, isFolder=True)
         # Search
-        item = xbmcgui.ListItem(danishaddons.msg(30003), iconImage=iconImage)
-        xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, 
danishaddons.ADDON_PATH + '?search', item, isFolder=True)
+        item = xbmcgui.ListItem(self.ADDON.getLocalizedString(30003), 
iconImage=iconImage)
+        xbmcplugin.addDirectoryItem(self.addonHandle, self.addonPath + 
'?search', item, isFolder=True)
         # Recently watched Program Series
-        item = xbmcgui.ListItem(danishaddons.msg(30007), iconImage=iconImage)
-        xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, 
danishaddons.ADDON_PATH + '?recentlywatched', item, isFolder=True)
+        item = xbmcgui.ListItem(self.ADDON.getLocalizedString(30007), 
iconImage=iconImage)
+        xbmcplugin.addDirectoryItem(self.addonHandle, self.addonPath + 
'?recentlywatched', item, isFolder=True)
         # Favorite Program Series
-        item = xbmcgui.ListItem(danishaddons.msg(30008), iconImage=iconImage)
-        xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, 
danishaddons.ADDON_PATH + '?favorites', item, isFolder=True)
+        item = xbmcgui.ListItem(self.ADDON.getLocalizedString(30008), 
iconImage=iconImage)
+        xbmcplugin.addDirectoryItem(self.addonHandle, self.addonPath + 
'?favorites', item, isFolder=True)
 
-        xbmcplugin.endOfDirectory(danishaddons.ADDON_HANDLE)
+        xbmcplugin.endOfDirectory(self.addonHandle)
 
     def getProgramSeries(self, limitToSlugs = None, addToFavorites = True):
         programSeries = self.api.getProgramSeries()
@@ -55,7 +56,7 @@ class DRnuUI(object):
 
             if program['newestVideoPublishTime'] is not None:
                 publishTime = self.parseDate(program['newestVideoPublishTime'])
-                infoLabels['plotoutline'] = danishaddons.msg(30004) % 
publishTime.strftime('%d. %b %Y kl. %H:%M')
+                infoLabels['plotoutline'] = 
self.ADDON.getLocalizedString(30004) % publishTime.strftime('%d. %b %Y kl. 
%H:%M')
                 infoLabels['date'] = publishTime.strftime('%d.%m.%Y')
                 infoLabels['year'] = int(publishTime.strftime('%Y'))
 
@@ -73,18 +74,18 @@ class DRnuUI(object):
 
             if addToFavorites:
                 runScript = 
"XBMC.RunPlugin(plugin://plugin.video.drnu/?addfavorite=%s)" % program['slug']
-                item.addContextMenuItems([(danishaddons.msg(30200), 
runScript)], True)
+                
item.addContextMenuItems([(self.ADDON.getLocalizedString(30200), runScript)], 
True)
             else:
                 runScript = 
"XBMC.RunPlugin(plugin://plugin.video.drnu/?delfavorite=%s)" % program['slug']
-                item.addContextMenuItems([(danishaddons.msg(30201), 
runScript)], True)
+                
item.addContextMenuItems([(self.ADDON.getLocalizedString(30201), runScript)], 
True)
 
-            url = danishaddons.ADDON_PATH + '?slug=' + program['slug']
-            xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, url, item, 
isFolder=True)
+            url = self.addonPath + '?slug=' + program['slug']
+            xbmcplugin.addDirectoryItem(self.addonHandle, url, item, 
isFolder=True)
 
-        xbmcplugin.endOfDirectory(danishaddons.ADDON_HANDLE)
+        xbmcplugin.endOfDirectory(self.addonHandle)
 
     def searchVideos(self):
-        keyboard = xbmc.Keyboard('', danishaddons.msg(30003))
+        keyboard = xbmc.Keyboard('', self.ADDON.getLocalizedString(30003))
         keyboard.doModal()
         if keyboard.isConfirmed():
             keyword = keyboard.getText()
@@ -97,7 +98,7 @@ class DRnuUI(object):
                     del videos[idx]
 
             if not len(videos):
-                xbmcgui.Dialog().ok(danishaddons.msg(30003), 
danishaddons.msg(30005))
+                xbmcgui.Dialog().ok(self.ADDON.getLocalizedString(30003), 
self.ADDON.getLocalizedString(30005))
             else:
                 self.listVideos(videos, False)
 
@@ -109,17 +110,17 @@ class DRnuUI(object):
             if video['title'] is not None:
                 infoLabels['title'] = video['title']
             else:
-                infoLabels['title'] = danishaddons.msg(30006)
+                infoLabels['title'] = self.ADDON.getLocalizedString(30006)
 
             if isSpot:
                 infoLabels['plot'] = video['spotSubTitle']
             else:
                 infoLabels['plot'] = video['description']
-                if video.has_key('duration'):
+                if video.has_key('duration') and video['duration'] is not None:
                     infoLabels['duration'] = video['duration']
-                if video.has_key('broadcastChannel'):
+                if video.has_key('broadcastChannel') and 
video['broadcastChannel'] is not None:
                     infoLabels['studio'] = video['broadcastChannel']
-                if video['broadcastTime'] is not None:
+                if video.has_key('broadcastTime') and video['broadcastTime'] 
is not None:
                     broadcastTime = self.parseDate(video['broadcastTime'])
                     infoLabels['plotoutline'] = 'Sendt: %s' % 
broadcastTime.strftime('%d. %b %Y kl. %H:%M')
                     infoLabels['date'] = broadcastTime.strftime('%d.%m.%Y')
@@ -134,24 +135,27 @@ class DRnuUI(object):
             item.setInfo('video', infoLabels)
             item.setProperty('IsPlayable', 'true')
             item.setProperty('Fanart_Image', fanartImage)
-            url = danishaddons.ADDON_PATH + '?id=' + str(video['id'])
-            xbmcplugin.addDirectoryItem(danishaddons.ADDON_HANDLE, url, item)
+            url = self.addonPath + '?id=' + str(video['id'])
+            xbmcplugin.addDirectoryItem(self.addonHandle, url, item)
 
-        xbmcplugin.addSortMethod(danishaddons.ADDON_HANDLE, 
xbmcplugin.SORT_METHOD_DATE)
-        xbmcplugin.endOfDirectory(danishaddons.ADDON_HANDLE)
+        xbmcplugin.addSortMethod(self.addonHandle, xbmcplugin.SORT_METHOD_DATE)
+        xbmcplugin.endOfDirectory(self.addonHandle)
 
 
     def playVideo(self, videoId):
         video = self.api.getVideoById(videoId)
 
-        rtmpUrl = danishaddons.web.downloadUrl(video['videoManifestUrl'])
+        u = urllib2.urlopen(video['videoManifestUrl'])
+        rtmpUrl = u.read()
+        u.close()
+        
         if rtmpUrl[0:7] == '<script':
             d = xbmcgui.Dialog()
-            d.ok(danishaddons.msg(30100), danishaddons.msg(30101), 
danishaddons.msg(30102))
+            d.ok(self.ADDON.getLocalizedString(30100), 
self.ADDON.getLocalizedString(30101), self.ADDON.getLocalizedString(30102))
         else:
             rtmpUrl = rtmpUrl.replace('rtmp://vod.dr.dk/', 
'rtmp://vod.dr.dk/cms/')
             item = xbmcgui.ListItem(path = rtmpUrl)
-            xbmcplugin.setResolvedUrl(danishaddons.ADDON_HANDLE, True, item)
+            xbmcplugin.setResolvedUrl(self.addonHandle, True, item)
 
     def parseDate(self, dateString):
         m = re.search('/Date\(([0-9]+).*?\)/', dateString)

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

Summary of changes:
 plugin.video.drnu/addon.xml     |    3 +-
 plugin.video.drnu/api.py        |   60 +++++++++++++++++++----------
 plugin.video.drnu/changelog.txt |    4 ++
 plugin.video.drnu/drnu.py       |   64 ++++++++++++++++++-------------
 plugin.video.drnu/ui.py         |   80 ++++++++++++++++++++------------------
 5 files changed, 124 insertions(+), 87 deletions(-)


hooks/post-receive
-- 
Plugins

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to