The branch, dharma-pre has been updated
       via  1b233f2a0668770c5f84ef7e4ff2694d55cc6264 (commit)
      from  8a4698f17f498be595a3e245e38b04bb19d6c3d8 (commit)

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

commit 1b233f2a0668770c5f84ef7e4ff2694d55cc6264
Author: spiff <[email protected]>
Date:   Mon Nov 15 10:02:43 2010 +0100

    [plugin.video.nrk] updated to version 2.1.0

diff --git a/plugin.video.nrk/addon.xml b/plugin.video.nrk/addon.xml
index 040f9b0..14d1ccb 100644
--- a/plugin.video.nrk/addon.xml
+++ b/plugin.video.nrk/addon.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon id="plugin.video.nrk"
        name="NRK"
-       version="2.0.0"
+       version="2.1.0"
        provider-name="takoi">
   <requires>
     <import addon="xbmc.python" version="1.0"/>
diff --git a/plugin.video.nrk/data.py b/plugin.video.nrk/data.py
index ab77a2f..b4dc767 100644
--- a/plugin.video.nrk/data.py
+++ b/plugin.video.nrk/data.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 '''
     NRK plugin for XBMC
     Copyright (C) 2010 Thomas Amland
@@ -16,20 +17,26 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 '''
 
-import urllib, re, time
+import urllib, re
 from BeautifulSoup import BeautifulSoup
-import xbmcaddon
+from DataItem import DataItem
+from dataStatic import *
+from utils import *
+
+
+global BITRATES, BITRATE_ID
+def setQuality(id):
+    global BITRATES, BITRATE_ID
+    BITRATE_ID = id
+    BITRATES = ['400', '800', '1200']
 
-id = xbmcaddon.Addon(id="plugin.video.nrk").getSetting("quality")
-QUALITY = {'0' : '400', '1' : '800', '2' : '1200' }[id]
-QUALITY_STR = {'0' : 'l', '1' : 'm', '2' : 'h' }[id]
 
 def getLive():
-    items = []
-    items.append(DataItem(title="NRK 1", 
url="mms://straumv.nrk.no/nrk_tv_direkte_nrk1_"+QUALITY_STR+"?UseSilverlight=1",
 isPlayable=True))
-    items.append(DataItem(title="NRK 2", 
url="mms://straumv.nrk.no/nrk_tv_direkte_nrk2_"+QUALITY_STR+"?UseSilverlight=1",
 isPlayable=True))
-    items.append(DataItem(title="NRK 3", 
url="mms://straumv.nrk.no/nrk_tv_direkte_nrk3_"+QUALITY_STR+"?UseSilverlight=1",
 isPlayable=True))
-    return items
+    url = "mms://straumv.nrk.no/nrk_tv_direkte_nrk%s_%s?UseSilverlight=1"
+    quality = ['l', 'm', 'h' ][BITRATE_ID]
+    return [DataItem(title="NRK 1", url=url % (1,quality), 
thumb=os.path.join(R_PATH, "nrk1.jpg"), isPlayable=True),
+            DataItem(title="NRK 2", url=url % (2,quality), 
thumb=os.path.join(R_PATH, "nrk2.jpg"), isPlayable=True),
+            DataItem(title="NRK 3", url=url % (3,quality), 
thumb=os.path.join(R_PATH, "nrk3.jpg"), isPlayable=True)]
 
 
 def getLatest():
@@ -38,32 +45,50 @@ def getLatest():
     items = []
     for e in li:
         anc = e.find('a', attrs={'href' : 
re.compile('^/nett-tv/klipp/[0-9]+')})
-        items.append( _getVideoById(anc['href'].split('/').pop()) )
+        items.append( _getVideo(anc['href']) )
     return items
 
 
-def getByLetter(ch):
-    url = "http://www.nrk.no/nett-tv/bokstav/"; + urllib.quote(ch)
+def getSearchResults(query):
+    soup = BeautifulSoup(urllib.urlopen("http://www.nrk.no/nett-tv/sok/"; + 
urllib.quote(query)))
+    li = soup.find('div', attrs={'id' : 'search-results'}).findAll('li')
+    items = []
+    for e in li:
+        url = e.find('em').string
+        if contains(url, "klipp"):
+            items.append( _getVideo(url) )
+        elif contains(url, "prosjekt"):
+            title = decodeHtml(e.find('a').string)
+            descr = decodeHtml(e.find('p').string)
+            items.append( DataItem(title=title, description=descr, 
url="/nett-tv/prosjekt/"+getId(url)) )
+    return items
+
+
+def getMostWatched(days):
+    url = "http://www.nrk.no/nett-tv/ml/topp12.aspx?dager=%s"; % days
     soup = BeautifulSoup(urllib.urlopen(url))
-    
+    li = soup.findAll('li')
     items = []
-    li = soup.find('div', attrs={'class' : 'nettv-category 
clearfix'}).findAll('li') 
     for e in li:
-        anc = e.find('a', attrs={'href' : 
re.compile('^/nett-tv/prosjekt/[0-9]+')})
-        title = anc['title']
-        url   = anc['href']
-        items.append( DataItem(title=title, url=url) )
+        url = e.find('a')['href']
+        if contains(url, "klipp"):
+            items.append( _getVideo(url))
     return items
 
 
 def getByUrl(url):
-    if (url.startswith("/nett-tv/prosjekt")):
+    if (url.startswith("/nett-tv/tema") or url.startswith("/nett-tv/bokstav")):
+        url = "http://www.nrk.no"; + url 
+        soup = BeautifulSoup(urllib.urlopen(url))
+        return _getAllProsjekt(soup)
+    
+    elif (url.startswith("/nett-tv/prosjekt")):
         url = "http://www.nrk.no"; + url
-    elif url.startswith("/nett-tv/kategori"):
-        url = "http://www.nrk.no/nett-tv/menyfragment.aspx?type=category&id="; 
+ url.split('/').pop()
+        
+    elif (url.startswith("/nett-tv/kategori")):
+        url = "http://www.nrk.no/nett-tv/menyfragment.aspx?type=category&id="; 
+ getId(url)
     
     soup = BeautifulSoup(urllib.urlopen(url))
-        
     items = []
     items.extend(_getAllKlipp(soup))
     items.extend(_getAllKategori(soup))
@@ -71,71 +96,54 @@ def getByUrl(url):
 
 
 def _getAllKlipp(soup):
-    items = soup.findAll('a', attrs={'class':re.compile('icon-video-black.*'), 
'href':re.compile('.*nett-tv/klipp/[0-9]+$')})
-    return [ _getVideoById(e['href'].split('/').pop()) for e in items ]
+    items = soup.findAll('a', 
attrs={'class':re.compile('icon-(video|sound)-black.*'), 
'href':re.compile('.*nett-tv/klipp/[0-9]+$')})
+    return [ _getVideo(e['href']) for e in items ]
+
 
-    
 def _getAllKategori(soup):
     items = soup.findAll('a', 
attrs={'class':re.compile('icon-closed-black.*'), 
'href':re.compile('^/nett-tv/kategori/[0-9]+')})
-    return [ DataItem(title=e['title'], url=e['href']) for e in items ]
+    return [ DataItem(title=decodeHtml(e['title']), url=e['href']) for e in 
items ]
 
 
-def _getVideoById(id):
-    url = "http://www.nrk.no/nett-tv/silverlight/getmediaxml.ashx?id="; + id + 
"&hastighet=" + QUALITY
-    soup = BeautifulSoup(urllib.urlopen(url))
-    title = soup.find('title').string
-    
-    url = soup.find('mediaurl').string
-    #some uri's contais illegal chars so need to fix this
-    url = url.split("mms://", 1)[1]
+def _getAllProsjekt(soup):
+    items = []
+    li = soup.find('div', attrs={'class' : 'nettv-category 
clearfix'}).findAll('li') 
+    for e in li:
+        anc = e.find('a', attrs={'href' : 
re.compile('^/nett-tv/prosjekt/[0-9]+')})
+        title = decodeHtml(anc['title'])
+        url   = anc['href']
+        img   = _getImg(e.find('img')['src'])
+        descr = decodeHtml(str(e.find('div', 
attrs={'class':'summary'}).find('p').string))
+        
+        items.append( DataItem(title=title, description=descr, thumb=img, 
url=url) )
+    return items
+
+
+def _getVideo(url):
+    id = getId(url)
+    (soup, url) = _findVideoUrl(id, BITRATE_ID)
+    url = url.split("mms://", 1)[1] #some uri's contais illegal chars so need 
to fix this
     url = url.encode('latin-1') #urllib cant unicode
     url = urllib.quote(url)
-    url = "mms://" + url + "?UseSilverlight=1"
-    
-    return DataItem(title=title, url=url, isPlayable=True)
-
-
-class DataItem:
-    def __init__(self, title="", description="", date="", author="", 
category="", image="", url="", isPlayable=False):
-        self._title = title
-        self._description = description
-        self._date = date
-        self._author = author
-        self._category = category
-        self._image = image
-        self._url = url
-        self._isPlayable = isPlayable
-    
-    @property
-    def isPlayable(self):
-        return self._isPlayable
-    
-    @property
-    def title(self):
-        return self._title
+    url = "mms://%s?UseSilverlight=1" % url
     
-    @property
-    def description(self):
-        return self._description
-    
-    @property
-    def date(self):
-        return self._date
-    
-    @property
-    def author(self):
-        return self._author
-    
-    @property
-    def category(self):
-        return self._category
-    
-    @property
-    def image(self):
-        return self._image
-    
-    @property
-    def url(self):
-        return self._url
+    title = decodeHtml(soup.find('title').string)
+    descr = decodeHtml(str(soup.find('description').string))
+    img   = _getImg(soup.find('imageurl').string)
+    return DataItem(title=title, description=descr, thumb=img, url=url, 
isPlayable=True)
+
+
+def _findVideoUrl(id, bitrate):
+    if bitrate >= len(BITRATES):
+        return (None, None)
+    url = 
"http://www.nrk.no/nett-tv/silverlight/getmediaxml.ashx?id=%s&hastighet=%s"; % 
(id, BITRATES[bitrate])
+    soup = BeautifulSoup(urllib.urlopen(url))
+    url = soup.find('mediaurl').string
+    if not url:
+        return _findVideoUrl(id, bitrate+1)
+    return (soup, url)
+     
+
+def _getImg(url):
+    return re.sub("^(.*cropid.*)w[0-9]+$", "\\1w650", url)
 
-    
diff --git a/plugin.video.nrk/default.py b/plugin.video.nrk/default.py
index 889df26..d19520a 100644
--- a/plugin.video.nrk/default.py
+++ b/plugin.video.nrk/default.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 '''
     NRK plugin for XBMC
     Copyright (C) 2010 Thomas Amland
@@ -16,17 +17,24 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 '''
 
-import os, sys
+import sys
 import xbmc, xbmcgui, xbmcaddon, xbmcplugin
 import data as Data
 from data import DataItem
 
-_ = xbmcaddon.Addon(id="plugin.video.nrk").getLocalizedString
+addon = xbmcaddon.Addon(id="plugin.video.nrk")
+Data.setQuality(int(addon.getSetting("quality")))
+_ = addon.getLocalizedString
 
 def nodes(baseUrl, handle):
-    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=live",    
xbmcgui.ListItem(_(30101)), True);
-    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=latest",  
xbmcgui.ListItem(_(30102)), True);
-    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=letters", 
xbmcgui.ListItem("A-Å"), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=live",     
xbmcgui.ListItem(_(30101)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=letters",  
xbmcgui.ListItem(_(30103)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=genres",   
xbmcgui.ListItem(_(30104)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=latest",   
xbmcgui.ListItem(_(30102)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=topweek",  
xbmcgui.ListItem(_(30106)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=topmonth", 
xbmcgui.ListItem(_(30107)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=toptotal", 
xbmcgui.ListItem(_(30108)), True);
+    xbmcplugin.addDirectoryItem(handle, baseUrl+"?node=search",   
xbmcgui.ListItem(_(30105)), True);
     xbmcplugin.endOfDirectory(handle)
 
 def node_live(baseUrl, handle):
@@ -36,50 +44,64 @@ def node_live(baseUrl, handle):
 def node_latest(baseUrl, handle):
     dataItems = Data.getLatest()
     create(baseUrl, handle, dataItems)
-
-def node_url(baseUrl, handle, url):
-    dataItems = Data.getByUrl(url)
+    
+def node_letters(baseUrl, handle):
+    dataItems = Data.getLetters()
     create(baseUrl, handle, dataItems)
     
-def node_letter(baseUrl, handle, letter):
-    dataItems = Data.getByLetter(letter)
+def node_genres(baseUrl, handle):
+    dataItems = Data.getGenres()
     create(baseUrl, handle, dataItems)
     
-def node_letters(baseUrl, handle):
-    #TODO: move this to data layer
-    letters = range(ord('a'), ord('z'))
-    letters.append(ord('1'))
-    letters.append(ord('2'))
-    letters.append(ord('3'))
-    letters.append(ord('7'))
-    letters.append(230) #æ
-    letters.append(216) #ø
-    letters.append(229) #Ã¥
-      
-    listItems = []
-    for l in letters:
-        ch = unichr(l)
-        url = baseUrl + "?letter=" + ch
-        listItems.append( (url, xbmcgui.ListItem(ch.upper()), True) )
+def node_topWeek(baseUrl, handle):
+    dataItems = Data.getMostWatched(7)
+    create(baseUrl, handle, dataItems)
+    
+def node_topMonth(baseUrl, handle):
+    dataItems = Data.getMostWatched(30)
+    create(baseUrl, handle, dataItems)
+    
+def node_topTotal(baseUrl, handle):
+    dataItems = Data.getMostWatched(9999)
+    create(baseUrl, handle, dataItems)
+    
+def node_search(baseUrl, handle):
+    kb = xbmc.Keyboard()
+    kb.doModal()
+    if (kb.isConfirmed()):
+        text = kb.getText()
+        dataItems = Data.getSearchResults(text)
+        create(baseUrl, handle, dataItems)
+
+def node_url(baseUrl, handle, url):
+    dataItems = Data.getByUrl(url)
+    create(baseUrl, handle, dataItems)
     
-    xbmcplugin.addDirectoryItems(handle=handle, items=listItems)
-    xbmcplugin.endOfDirectory(handle)
     
 def create(baseUrl, handle, dataItems):
     listItems = []
     for e in dataItems:
-        l = xbmcgui.ListItem(e.title)
-        l.setInfo( type="Video", infoLabels={"title": e.title} )
-        l.setProperty("IsPlayable", str(e.isPlayable));
+        l = xbmcgui.ListItem(e.title, thumbnailImage=e.thumb)
+        l.setInfo( type="Video", infoLabels={"title": e.title, 
"plot":e.description, "tvshowtitle":e.title} )
+        l.setProperty("IsPlayable", str(e.isPlayable))
+        
         isdir = not(e.isPlayable)
-        if isdir: url = baseUrl + "?url=" + e.url
-        else: url = e.url
+        if isdir:
+            url = baseUrl + "?url=" + e.url
+        else:
+            url = e.url
         listItems.append( (url, l, isdir) )
+        
     xbmcplugin.addDirectoryItems(handle=handle, items=listItems)
     xbmcplugin.endOfDirectory(handle)
     
 
 if ( __name__ == "__main__" ):
+    #using episodes because most skins expects 16/9 thumbs for this
+    xbmcplugin.setContent(int(sys.argv[1]), "episodes")
+    xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
+    xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
+    
     arg = sys.argv[2].split('=', 1)
 
     if (arg[0] == "?node"):
@@ -89,13 +111,19 @@ if ( __name__ == "__main__" ):
             node_letters(sys.argv[0], int(sys.argv[1]))
         elif(arg[1] == "latest"):
             node_latest(sys.argv[0], int(sys.argv[1]))
+        elif(arg[1] == "genres"):
+            node_genres(sys.argv[0], int(sys.argv[1]))
+        elif(arg[1] == "search"):
+            node_search(sys.argv[0], int(sys.argv[1]))
+        elif(arg[1] == "topweek"):
+            node_topWeek(sys.argv[0], int(sys.argv[1]))
+        elif(arg[1] == "topmonth"):
+            node_topMonth(sys.argv[0], int(sys.argv[1]))
+        elif(arg[1] == "toptotal"):
+            node_topTotal(sys.argv[0], int(sys.argv[1]))
     
-    elif (arg[0] == "?letter"):
-        node_letter(sys.argv[0], int(sys.argv[1]), arg[1])
-        
     elif (arg[0] == "?url"):
         node_url(sys.argv[0], int(sys.argv[1]), arg[1])
     
     else:
         nodes(sys.argv[0], int(sys.argv[1]))
-    
diff --git a/plugin.video.nrk/resources/language/English/strings.xml 
b/plugin.video.nrk/resources/language/English/strings.xml
index a9f0757..1d56f22 100644
--- a/plugin.video.nrk/resources/language/English/strings.xml
+++ b/plugin.video.nrk/resources/language/English/strings.xml
@@ -9,4 +9,10 @@
        
        <string id="30101">Live</string>
        <string id="30102">New</string>
+       <string id="30103">Alphabetical</string>
+       <string id="30104">Categories</string>
+       <string id="30105">Search</string>
+       <string id="30106">Most watched this week</string>
+       <string id="30107">Most watched this month</string>
+       <string id="30108">Most watched total</string>
 </strings>
diff --git a/plugin.video.nrk/resources/language/Norwegian/strings.xml 
b/plugin.video.nrk/resources/language/Norwegian/strings.xml
index a44e4ba..bec0e98 100644
--- a/plugin.video.nrk/resources/language/Norwegian/strings.xml
+++ b/plugin.video.nrk/resources/language/Norwegian/strings.xml
@@ -9,4 +9,10 @@
        
        <string id="30101">Direkte</string>
        <string id="30102">Nytt i nett-tv</string>
+       <string id="30103">Alfabetisk</string>
+       <string id="30104">Kategorier</string>
+       <string id="30105">Søk</string>
+       <string id="30106">Mest sett denne uken</string>
+       <string id="30107">Mest sett denne måneden</string>
+       <string id="30108">Mest sett totalt</string>
 </strings>

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

Summary of changes:
 plugin.video.nrk/DataItem.py                       |   66 ++++++++
 plugin.video.nrk/addon.xml                         |    2 +-
 plugin.video.nrk/changelog.txt                     |    8 +
 plugin.video.nrk/data.py                           |  172 ++++++++++----------
 plugin.video.nrk/dataStatic.py                     |   54 ++++++
 plugin.video.nrk/default.py                        |  102 ++++++++-----
 plugin.video.nrk/resources/images/nrk1.jpg         |  Bin 0 -> 3406 bytes
 plugin.video.nrk/resources/images/nrk2.jpg         |  Bin 0 -> 2915 bytes
 plugin.video.nrk/resources/images/nrk3.jpg         |  Bin 0 -> 3540 bytes
 plugin.video.nrk/resources/images/thm_cult.png     |  Bin 0 -> 51281 bytes
 plugin.video.nrk/resources/images/thm_docu.png     |  Bin 0 -> 32499 bytes
 plugin.video.nrk/resources/images/thm_drma.png     |  Bin 0 -> 35782 bytes
 plugin.video.nrk/resources/images/thm_entn.png     |  Bin 0 -> 83809 bytes
 plugin.video.nrk/resources/images/thm_fact.png     |  Bin 0 -> 68498 bytes
 plugin.video.nrk/resources/images/thm_food.png     |  Bin 0 -> 52835 bytes
 plugin.video.nrk/resources/images/thm_kids.png     |  Bin 0 -> 76271 bytes
 plugin.video.nrk/resources/images/thm_life.png     |  Bin 0 -> 32879 bytes
 plugin.video.nrk/resources/images/thm_msic.png     |  Bin 0 -> 56501 bytes
 plugin.video.nrk/resources/images/thm_news.png     |  Bin 0 -> 66582 bytes
 plugin.video.nrk/resources/images/thm_ntur.png     |  Bin 0 -> 49383 bytes
 plugin.video.nrk/resources/images/thm_rgns.png     |  Bin 0 -> 67391 bytes
 plugin.video.nrk/resources/images/thm_sami.png     |  Bin 0 -> 26279 bytes
 plugin.video.nrk/resources/images/thm_sign.png     |  Bin 0 -> 29417 bytes
 plugin.video.nrk/resources/images/thm_sprt.png     |  Bin 0 -> 428563 bytes
 plugin.video.nrk/resources/images/thm_teen.png     |  Bin 0 -> 52665 bytes
 .../resources/language/English/strings.xml         |    6 +
 .../resources/language/Norwegian/strings.xml       |    6 +
 plugin.video.nrk/tests/textdata.py                 |   34 ++++
 plugin.video.nrk/tests/videos.py                   |   35 ++++
 plugin.video.nrk/utils.py                          |   27 +++
 30 files changed, 392 insertions(+), 120 deletions(-)
 create mode 100644 plugin.video.nrk/DataItem.py
 create mode 100644 plugin.video.nrk/changelog.txt
 create mode 100644 plugin.video.nrk/dataStatic.py
 create mode 100644 plugin.video.nrk/resources/images/nrk1.jpg
 create mode 100644 plugin.video.nrk/resources/images/nrk2.jpg
 create mode 100644 plugin.video.nrk/resources/images/nrk3.jpg
 create mode 100644 plugin.video.nrk/resources/images/thm_cult.png
 create mode 100644 plugin.video.nrk/resources/images/thm_docu.png
 create mode 100644 plugin.video.nrk/resources/images/thm_drma.png
 create mode 100644 plugin.video.nrk/resources/images/thm_entn.png
 create mode 100644 plugin.video.nrk/resources/images/thm_fact.png
 create mode 100644 plugin.video.nrk/resources/images/thm_food.png
 create mode 100644 plugin.video.nrk/resources/images/thm_kids.png
 create mode 100644 plugin.video.nrk/resources/images/thm_life.png
 create mode 100644 plugin.video.nrk/resources/images/thm_msic.png
 create mode 100644 plugin.video.nrk/resources/images/thm_news.png
 create mode 100644 plugin.video.nrk/resources/images/thm_ntur.png
 create mode 100644 plugin.video.nrk/resources/images/thm_rgns.png
 create mode 100644 plugin.video.nrk/resources/images/thm_sami.png
 create mode 100644 plugin.video.nrk/resources/images/thm_sign.png
 create mode 100644 plugin.video.nrk/resources/images/thm_sprt.png
 create mode 100644 plugin.video.nrk/resources/images/thm_teen.png
 create mode 100644 plugin.video.nrk/tests/textdata.py
 create mode 100644 plugin.video.nrk/tests/videos.py
 create mode 100644 plugin.video.nrk/utils.py


hooks/post-receive
-- 
Plugins

------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to