summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Ajanki <antti.ajanki@iki.fi>2011-06-12 15:18:36 +0300
committerAntti Ajanki <antti.ajanki@iki.fi>2011-06-12 15:18:36 +0300
commit541779154be54e113ddd8bfac7245aed484e9ced (patch)
tree3c4384f255b27db0c930defd14052374af9febbe
parentbd478ec0ef43d29f47a8892d558280cdd05a1dbb (diff)
downloadvdr-plugin-webvideo-541779154be54e113ddd8bfac7245aed484e9ced.tar.gz
vdr-plugin-webvideo-541779154be54e113ddd8bfac7245aed484e9ced.tar.bz2
Fix Katsomo, add encoding attribute to <submission> node
-rw-r--r--src/vdr-plugin/common.c3
-rw-r--r--src/vdr-plugin/history.c4
-rw-r--r--src/vdr-plugin/history.h2
-rw-r--r--src/vdr-plugin/menu.c13
-rw-r--r--src/vdr-plugin/menudata.c39
-rw-r--r--src/vdr-plugin/menudata.h10
-rw-r--r--src/webvicli/webvicli/client.py6
-rw-r--r--src/webvicli/webvicli/menu.py10
-rw-r--r--templates/katsomo.fi/description.xsl55
-rw-r--r--templates/katsomo.fi/mainmenu.xsl15
-rw-r--r--templates/katsomo.fi/navigation.xsl48
-rw-r--r--templates/katsomo.fi/program.xsl36
-rw-r--r--templates/katsomo.fi/search.xsl2
-rw-r--r--templates/katsomo.fi/searchresults.xsl64
-rw-r--r--templates/katsomo.fi/video.xsl26
-rw-r--r--templates/katsomo.fi/videopage.xsl31
-rw-r--r--templates/www.katsomo.fi/videopage.xsl15
17 files changed, 270 insertions, 109 deletions
diff --git a/src/vdr-plugin/common.c b/src/vdr-plugin/common.c
index 17a73b0..2792d24 100644
--- a/src/vdr-plugin/common.c
+++ b/src/vdr-plugin/common.c
@@ -142,6 +142,9 @@ char *URLencode(const char *s) {
'\0'
};
+ if (!s)
+ return NULL;
+
char *buf = (char *)malloc((3*strlen(s)+1)*sizeof(char));
if (!buf)
return NULL;
diff --git a/src/vdr-plugin/history.c b/src/vdr-plugin/history.c
index a463bac..fe444ca 100644
--- a/src/vdr-plugin/history.c
+++ b/src/vdr-plugin/history.c
@@ -43,11 +43,11 @@ int cHistoryObject::QuerySize() const {
return editData.Size();
}
-char *cHistoryObject::GetQueryFragment(int i) const {
+char *cHistoryObject::GetQueryFragment(int i, const char *encoding) const {
if (i < 0 && i >= editData.Size())
return NULL;
else
- return editData[i]->GetQueryFragment();
+ return editData[i]->GetQueryFragment(encoding);
}
cTextFieldData *cHistoryObject::GetTextFieldData(const char *controlName) {
diff --git a/src/vdr-plugin/history.h b/src/vdr-plugin/history.h
index fd5fcf9..a999098 100644
--- a/src/vdr-plugin/history.h
+++ b/src/vdr-plugin/history.h
@@ -35,7 +35,7 @@ public:
int GetSelected() const { return selected; }
int QuerySize() const;
- char *GetQueryFragment(int i) const;
+ char *GetQueryFragment(int i, const char *encoding) const;
cTextFieldData *GetTextFieldData(const char *controlName);
cItemListData *GetItemListData(const char *controlName,
cStringList &items,
diff --git a/src/vdr-plugin/menu.c b/src/vdr-plugin/menu.c
index 111339f..d03c61d 100644
--- a/src/vdr-plugin/menu.c
+++ b/src/vdr-plugin/menu.c
@@ -291,6 +291,7 @@ void cNavigationMenu::NewButton(xmlDocPtr doc, xmlNodePtr node) {
// label and submission tags
xmlChar *itemtitle = NULL, *submission = NULL;
cHistoryObject *curhistpage = history->Current();
+ xmlChar *encoding = NULL;
node = node->xmlChildrenNode;
while (node) {
@@ -302,6 +303,13 @@ void cNavigationMenu::NewButton(xmlDocPtr doc, xmlNodePtr node) {
if (submission)
xmlFree(submission);
submission = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+
+ xmlChar *enc = xmlGetProp(node, BAD_CAST "encoding");
+ if (enc) {
+ if (encoding)
+ xmlFree(encoding);
+ encoding = enc;
+ }
}
node = node->next;
}
@@ -309,7 +317,8 @@ void cNavigationMenu::NewButton(xmlDocPtr doc, xmlNodePtr node) {
itemtitle = xmlCharStrdup("???");
cSubmissionButtonData *data = \
- new cSubmissionButtonData((char *)submission, curhistpage);
+ new cSubmissionButtonData((char *)submission, curhistpage,
+ (char *)encoding);
const char *titleconv = csc.Convert((char *)itemtitle); // do not free
char *newtitle = (char *)malloc((strlen(titleconv)+3)*sizeof(char));
if (newtitle) {
@@ -326,6 +335,8 @@ void cNavigationMenu::NewButton(xmlDocPtr doc, xmlNodePtr node) {
xmlFree(itemtitle);
if (submission)
xmlFree(submission);
+ if (encoding)
+ xmlFree(encoding);
}
void cNavigationMenu::NewTitle(xmlDocPtr doc, xmlNodePtr node) {
diff --git a/src/vdr-plugin/menudata.c b/src/vdr-plugin/menudata.c
index 45db133..6fc899c 100644
--- a/src/vdr-plugin/menudata.c
+++ b/src/vdr-plugin/menudata.c
@@ -55,13 +55,20 @@ cTextFieldData::~cTextFieldData() {
free(valuebuffer);
}
-char *cTextFieldData::GetQueryFragment() {
+char *cTextFieldData::GetQueryFragment(const char *encoding) {
const char *name = GetName();
+ char *val;
if (name && *name && valuebuffer) {
- char *encoded = URLencode(valuebuffer);
- cString tmp = cString::sprintf("%s,%s", name, encoded);
- free(encoded);
+ if (encoding) {
+ cCharSetConv charsetconv = cCharSetConv("UTF-8", encoding);
+ val = URLencode(charsetconv.Convert(valuebuffer));
+ } else {
+ val = URLencode(valuebuffer);
+ }
+
+ cString tmp = cString::sprintf("%s,%s", name, val);
+ free(val);
return strdup(tmp);
}
@@ -98,11 +105,20 @@ cItemListData::~cItemListData() {
free(stringvalues);
}
-char *cItemListData::GetQueryFragment() {
+char *cItemListData::GetQueryFragment(const char *encoding) {
const char *name = GetName();
+ char *val;
if (name && *name) {
- cString tmp = cString::sprintf("%s,%s", name, stringvalues[value]);
+ if (encoding) {
+ cCharSetConv charsetconv = cCharSetConv("UTF-8", encoding);
+ val = URLencode(charsetconv.Convert(stringvalues[value]));
+ } else {
+ val = URLencode(stringvalues[value]);
+ }
+
+ cString tmp = cString::sprintf("%s,%s", name, val);
+ free(val);
return strdup(tmp);
}
@@ -128,15 +144,19 @@ int *cItemListData::GetValuePtr() {
// --- cSubmissionButtonData -----------------------------------------------
cSubmissionButtonData::cSubmissionButtonData(
- const char *queryUrl, const cHistoryObject *currentPage)
+ const char *queryUrl, const cHistoryObject *currentPage,
+ const char *enc)
{
querybase = queryUrl ? strdup(queryUrl) : NULL;
page = currentPage;
+ encoding = enc ? strdup(enc) : NULL;
}
cSubmissionButtonData::~cSubmissionButtonData() {
if (querybase)
free(querybase);
+ if (encoding)
+ free(encoding);
// do not free page
}
@@ -157,9 +177,10 @@ char *cSubmissionButtonData::GetURL() {
int numparameters = 0;
for (int i=0; i<page->QuerySize(); i++) {
- char *parameter = page->GetQueryFragment(i);
+ char *parameter = page->GetQueryFragment(i, encoding);
if (parameter) {
- querystr = (char *)realloc(querystr, (strlen(querystr)+strlen(parameter)+8)*sizeof(char));
+ size_t len = strlen(querystr) + strlen(parameter) + 8;
+ querystr = (char *)realloc(querystr, len*sizeof(char));
if (i > 0)
strcat(querystr, "&");
strcat(querystr, "subst=");
diff --git a/src/vdr-plugin/menudata.h b/src/vdr-plugin/menudata.h
index 23a126c..98e5915 100644
--- a/src/vdr-plugin/menudata.h
+++ b/src/vdr-plugin/menudata.h
@@ -30,7 +30,7 @@ public:
virtual ~cQueryData();
const char *GetName() { return name; }
- virtual char *GetQueryFragment() = 0;
+ virtual char *GetQueryFragment(const char *encoding) = 0;
};
// --- cSimpleLink ---------------------------------------------------------
@@ -56,7 +56,7 @@ public:
cTextFieldData(const char *Name, int Length);
virtual ~cTextFieldData();
- virtual char *GetQueryFragment();
+ virtual char *GetQueryFragment(const char *encoding);
char *GetValue();
int GetLength();
};
@@ -74,7 +74,7 @@ public:
cItemListData(const char *Name, char **Strings, char **StringValues, int NumStrings);
virtual ~cItemListData();
- virtual char *GetQueryFragment();
+ virtual char *GetQueryFragment(const char *encoding);
char **GetStrings();
char **GetStringValues();
int GetNumStrings();
@@ -89,9 +89,11 @@ class cSubmissionButtonData : public cLinkBase {
private:
char *querybase;
const cHistoryObject *page;
+ char *encoding;
public:
cSubmissionButtonData(const char *queryUrl,
- const cHistoryObject *currentPage);
+ const cHistoryObject *currentPage,
+ const char *encoding);
virtual ~cSubmissionButtonData();
virtual char *GetURL();
diff --git a/src/webvicli/webvicli/client.py b/src/webvicli/webvicli/client.py
index 78a933d..f82c32a 100644
--- a/src/webvicli/webvicli/client.py
+++ b/src/webvicli/webvicli/client.py
@@ -279,14 +279,18 @@ class WVClient:
def parse_button(self, node, queryitems):
label = ''
submission = None
+ encoding = 'utf-8'
child = node.children
while child:
if child.name == 'label':
label = webvi.utils.get_content_unicode(child)
elif child.name == 'submission':
submission = webvi.utils.get_content_unicode(child)
+ enc = child.hasProp('encoding')
+ if enc is not None:
+ encoding = webvi.utils.get_content_unicode(enc)
child = child.next
- return menu.MenuItemSubmitButton(label, submission, queryitems)
+ return menu.MenuItemSubmitButton(label, submission, queryitems, encoding)
def guess_extension(self, mimetype, url):
ext = mimetypes.guess_extension(mimetype)
diff --git a/src/webvicli/webvicli/menu.py b/src/webvicli/webvicli/menu.py
index f1f1f21..d8551a7 100644
--- a/src/webvicli/webvicli/menu.py
+++ b/src/webvicli/webvicli/menu.py
@@ -145,13 +145,14 @@ class MenuItemList:
class MenuItemSubmitButton:
- def __init__(self, label, baseurl, subitems):
+ def __init__(self, label, baseurl, subitems, encoding):
self.label = label
if type(baseurl) == unicode:
self.baseurl = baseurl.encode('utf-8')
else:
self.baseurl = baseurl
self.subitems = subitems
+ self.encoding = encoding
def __str__(self):
return '[' + self.label + ']'
@@ -166,6 +167,11 @@ class MenuItemSubmitButton:
parts = []
for sub in self.subitems:
for key, val in sub.get_query().iteritems():
- parts.append('subst=' + urllib.quote_plus(key.encode('utf-8')) + ',' + urllib.quote_plus(val.encode('utf-8')))
+ try:
+ parts.append('subst=' + \
+ urllib.quote_plus(key.encode(self.encoding, 'ignore')) + ',' + \
+ urllib.quote_plus(val.encode(self.encoding, 'ignore')))
+ except LookupError:
+ pass
return baseurl + '&'.join(parts)
diff --git a/templates/katsomo.fi/description.xsl b/templates/katsomo.fi/description.xsl
new file mode 100644
index 0000000..59c313b
--- /dev/null
+++ b/templates/katsomo.fi/description.xsl
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:str="http://exslt.org/strings"
+ exclude-result-prefixes="str">
+
+<xsl:param name="docurl"/>
+<xsl:param name="live"/>
+
+<xsl:template match="/">
+<xsl:variable name="episodetitle">
+ <xsl:choose>
+ <xsl:when test="contains(/html/head/meta[@name='title']/@content, ' - Katsomo')">
+ <xsl:value-of select="substring-before(/html/head/meta[@name='title']/@content, ' - Katsomo')"/>
+ </xsl:when>
+ <xsl:when test="contains(/html/head/meta[@name='title']/@content, ' - MTV3 Katsomo')">
+ <xsl:value-of select="substring-before(/html/head/meta[@name='title']/@content, ' - MTV3 Katsomo')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="/html/head/meta[@name='title']/@content"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="title" select="normalize-space(concat(id('program_content')/h1, ' ', $episodetitle))"/>
+
+<xsl:variable name="pid" select="substring-after($docurl, 'progId=')"/>
+
+<wvmenu>
+ <title><xsl:value-of select="$title"/></title>
+
+ <textarea>
+ <label><xsl:value-of select="/html/head/meta[@name='description']/@content"/></label>
+ </textarea>
+
+ <xsl:choose>
+ <xsl:when test="$live">
+ <textarea>
+ <label><xsl:value-of select="$live"/></label>
+ </textarea>
+ </xsl:when>
+
+ <xsl:when test="$pid">
+ <link>
+ <label>Download this video</label>
+ <stream>wvt:///katsomo.fi/video.xsl?param=pid,<xsl:value-of select="$pid"/>&amp;param=title,<xsl:value-of select="str:encode-uri($title, true())"/></stream>
+ </link>
+ </xsl:when>
+ </xsl:choose>
+
+</wvmenu>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/templates/katsomo.fi/mainmenu.xsl b/templates/katsomo.fi/mainmenu.xsl
index 2bf3d3a..1e43126 100644
--- a/templates/katsomo.fi/mainmenu.xsl
+++ b/templates/katsomo.fi/mainmenu.xsl
@@ -5,6 +5,14 @@
xmlns:str="http://exslt.org/strings"
exclude-result-prefixes="str">
+<xsl:template match="id('all_programs_tab1')//a">
+ <link>
+ <label><xsl:value-of select="normalize-space(string(.))"/></label>
+ <ref>wvt:///katsomo.fi/program.xsl?srcurl=<xsl:value-of select="str:encode-uri(@href, true())"/></ref>
+ </link>
+</xsl:template>
+
+
<xsl:template match="/">
<wvmenu>
<title>MTV3 Katsomo</title>
@@ -14,12 +22,7 @@
<ref>wvt:///katsomo.fi/search.xsl</ref>
</link>
- <xsl:for-each select="id('mainMenu')/li[a/@href != '/']">
- <link>
- <label><xsl:value-of select="a"/></label>
- <ref>wvt:///katsomo.fi/navigation.xsl?srcurl=<xsl:value-of select="str:encode-uri(a/@href, true())"/></ref>
- </link>
- </xsl:for-each>
+ <xsl:apply-templates select="id('all_programs_tab1')//a"/>
</wvmenu>
</xsl:template>
diff --git a/templates/katsomo.fi/navigation.xsl b/templates/katsomo.fi/navigation.xsl
deleted file mode 100644
index 15aa98f..0000000
--- a/templates/katsomo.fi/navigation.xsl
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:str="http://exslt.org/strings"
- exclude-result-prefixes="str">
-
-<xsl:param name="docurl"/>
-
-<xsl:template match="ol[@class='categoryList']/li">
- <link>
- <label><xsl:value-of select="normalize-space(a)"/></label>
- <ref>wvt:///katsomo.fi/navigation.xsl?srcurl=<xsl:value-of select="str:encode-uri(a/@href, true())"/></ref>
- </link>
-</xsl:template>
-
-<xsl:template match="ol[@class='programList']/li">
- <xsl:variable name="progId" select="substring-after(a/@href, 'progId=')"/>
- <xsl:variable name="treeId" select="substring-after($docurl, 'treeId=')"/>
- <xsl:variable name="title" select="normalize-space(a[string(.)])"/>
-
- <link>
- <label><xsl:value-of select="$title"/></label>
- <stream>wvt:///katsomo.fi/video.xsl?srcurl=<xsl:value-of select="str:encode-uri(concat('http://katsomo.fi/showContent.do?treeId=', $treeId, '&amp;progId=', $progId, '&amp;adData=%7B%22ad%22%3A%20%7B%7D%7D&amp;ajax=true&amp;serial=1'), true())"/>&amp;param=title,<xsl:value-of select="str:encode-uri($title, true())"/>&amp;HTTP-header=cookie,webtv.bandwidth%3D1000%3BautoFullScreen%3Dfalse%3Bwebtv.playerPlatform%3D0</stream>
- </link>
-</xsl:template>
-
-<xsl:template match="/">
-<wvmenu>
- <title><xsl:value-of select="/html/head/meta[@name='title']/@content"/></title>
-
- <xsl:if test="//ol[@class='categoryList']/li and //ol[@class='programList']/li">
- <textarea>
- <label>Ohjelmat</label>
- </textarea>
- </xsl:if>
- <xsl:apply-templates select="//ol[@class='categoryList']/li"/>
-
- <xsl:if test="//ol[@class='categoryList']/li and //ol[@class='programList']/li">
- <textarea>
- <label>Jaksot</label>
- </textarea>
- </xsl:if>
- <xsl:apply-templates select="//ol[@class='programList']/li"/>
-</wvmenu>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/templates/katsomo.fi/program.xsl b/templates/katsomo.fi/program.xsl
new file mode 100644
index 0000000..f1c527a
--- /dev/null
+++ b/templates/katsomo.fi/program.xsl
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:str="http://exslt.org/strings"
+ exclude-result-prefixes="str">
+
+<xsl:template match="div[contains(@class, 'item')]">
+ <xsl:choose>
+ <xsl:when test="div[@class='row1']/span[@class='live']">
+ <xsl:variable name="upcoming" select="concat(div[@class='row1']/span[@class='live'], ' ', div[@class='row1']/span[contains(@class, 'time')])"/>
+
+ <link>
+ <label><xsl:value-of select="normalize-space(concat(div[@class='row2']/a, ' ', $upcoming))"/></label>
+ <ref>wvt:///katsomo.fi/description.xsl?srcurl=<xsl:value-of select="str:encode-uri(div[@class='row2']/a/@href, true())"/>&amp;param=live,<xsl:value-of select="str:encode-uri($upcoming, true())"/></ref>
+ </link>
+ </xsl:when>
+ <xsl:otherwise>
+ <link>
+ <label><xsl:value-of select="div[@class='row2']/a"/></label>
+ <ref>wvt:///katsomo.fi/description.xsl?srcurl=<xsl:value-of select="str:encode-uri(div[@class='row2']/a/@href, true())"/></ref>
+ <stream>wvt:///katsomo.fi/video.xsl?param=pid,<xsl:value-of select="substring-after(div[@class='row2']/a/@href, 'progId=')"/>&amp;param=title,<xsl:value-of select="normalize-space(str:encode-uri(concat(id('program_content')/h1, ' ', div[@class='row2']/a), true()))"/></stream>
+ </link>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="/">
+<wvmenu>
+ <title><xsl:value-of select="/html/head/meta[@name='title']/@content"/></title>
+
+ <xsl:apply-templates select="//div[@class='content episode']/div[contains(@class, 'item') and not(contains(@class, 'not-free'))]"/>
+</wvmenu>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/templates/katsomo.fi/search.xsl b/templates/katsomo.fi/search.xsl
index aaecfd6..619708d 100644
--- a/templates/katsomo.fi/search.xsl
+++ b/templates/katsomo.fi/search.xsl
@@ -15,7 +15,7 @@
<button>
<label>Hae</label>
- <submission>wvt:///katsomo.fi/searchresults.xsl?srcurl=<xsl:value-of select="str:encode-uri('http://katsomo.fi/search.do?keywords={query}&amp;treeId=9992', true())"/></submission>
+ <submission encoding='iso-8859-1'>wvt:///katsomo.fi/searchresults.xsl?srcurl=<xsl:value-of select="str:encode-uri('http://katsomo.fi/search.do?keywords={query}&amp;treeId=33992', true())"/></submission>
</button>
</wvmenu>
</xsl:template>
diff --git a/templates/katsomo.fi/searchresults.xsl b/templates/katsomo.fi/searchresults.xsl
index 3b0ab8d..bb6cae2 100644
--- a/templates/katsomo.fi/searchresults.xsl
+++ b/templates/katsomo.fi/searchresults.xsl
@@ -5,27 +5,69 @@
xmlns:str="http://exslt.org/strings"
exclude-result-prefixes="str">
-<xsl:template match="a">
- <xsl:variable name="progId" select="substring-after(@href, 'progId=')"/>
- <xsl:variable name="title" select="normalize-space(.)"/>
+<!-- Helper function for extracting progId from href -->
+<xsl:template name="extract_pid">
+ <xsl:param name="href"/>
+
+ <xsl:choose>
+ <xsl:when test="contains(substring-after($href, 'progId='), '&amp;')">
+ <xsl:value-of select="substring-before(substring-after($href, 'progId='), '&amp;')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="substring-after($href, 'progId=')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Create video link -->
+<xsl:template name="video_link">
+ <xsl:param name="title"/>
+ <xsl:param name="href"/>
+ <xsl:variable name="pid">
+ <xsl:call-template name="extract_pid">
+ <xsl:with-param name="href" select="$href"/>
+ </xsl:call-template>
+ </xsl:variable>
<link>
<label><xsl:value-of select="$title"/></label>
- <stream>wvt:///katsomo.fi/video.xsl?srcurl=<xsl:value-of select="str:encode-uri(concat('http://katsomo.fi/showContent.do?progId=', $progId, '&amp;adData=%7B%22ad%22%3A%20%7B%7D%7D&amp;ajax=true&amp;serial=1'), true())"/>&amp;param=title,<xsl:value-of select="str:encode-uri($title, true())"/>&amp;HTTP-header=cookie,webtv.bandwidth%3D1000%3BautoFullScreen%3Dfalse%3Bwebtv.playerPlatform%3D0</stream>
+ <ref>wvt:///katsomo.fi/description.xsl?srcurl=<xsl:value-of select="str:encode-uri($href, true())"/></ref>
+ <stream>wvt:///katsomo.fi/video.xsl?param=pid,<xsl:value-of select="$pid"/>&amp;param=title,<xsl:value-of select="str:encode-uri($title, true())"/></stream>
</link>
</xsl:template>
+<xsl:template match="id('search_episodes')/div">
+ <xsl:call-template name="video_link">
+ <xsl:with-param name="title" select="normalize-space(h4/a)"/>
+ <xsl:with-param name="href" select="h4/a/@href"/>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="id('search_clips')/div">
+ <xsl:call-template name="video_link">
+ <xsl:with-param name="title" select="normalize-space(concat(p/a[1], ' ', h4/a))"/>
+ <xsl:with-param name="href" select="h4/a/@href"/>
+ </xsl:call-template>
+</xsl:template>
+
<xsl:template match="/">
<wvmenu>
- <title>Hakutulokset: <xsl:value-of select="id('searchResults')/div/div[@class='description']/span"/></title>
+ <title><xsl:value-of select="/html/head/title"/></title>
+
+ <!-- Program search results require javascript. This is not a -->
+ <!-- problem because all programs are listed on the main page -->
+ <!-- anyway. -->
+ <!-- <xsl:apply-templates select="id('search_results')/div[contains(@class, 'item')]"/> -->
- <xsl:if test="not(id('resultList')/div[@class='item'])">
- <textarea>
- <label><xsl:value-of select="normalize-space(id('siteMapList')/p)"/></label>
- </textarea>
- </xsl:if>
+ <textarea>
+ <label>Jaksot</label>
+ </textarea>
+ <xsl:apply-templates select="id('search_episodes')/div[contains(@class, 'item')]"/>
- <xsl:apply-templates select="id('resultList')/div[@class='item']/h6/a[not(@class='programType')]"/>
+ <textarea>
+ <label>Klipit</label>
+ </textarea>
+ <xsl:apply-templates select="id('search_clips')/div[contains(@class, 'item')]"/>
</wvmenu>
</xsl:template>
diff --git a/templates/katsomo.fi/video.xsl b/templates/katsomo.fi/video.xsl
index 9d20c49..dee8d21 100644
--- a/templates/katsomo.fi/video.xsl
+++ b/templates/katsomo.fi/video.xsl
@@ -1,18 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:str="http://exslt.org/strings"
- exclude-result-prefixes="str">
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<xsl:param name="title">katsomovideo</xsl:param>
+<xsl:param name="title">katsomo_video</xsl:param>
+<xsl:param name="pid"/>
-<xsl:template match="/">
+<xsl:template name="mediaurl">
+<xsl:param name="title"/>
+<xsl:param name="pid"/>
<mediaurl>
<title><xsl:value-of select="$title"/></title>
-
- <url><xsl:value-of select='substring-before(substring-after(//script, "metaUrl&apos;: &apos;"), "&apos;")'/></url>
+ <url>
+ <xsl:if test="$pid">
+ <xsl:value-of select="concat('http://www.katsomo.fi/metafile.asx?p=', $pid, '&amp;bw=800')"/>
+ </xsl:if>
+ </url>
</mediaurl>
</xsl:template>
+<xsl:template match="/">
+ <xsl:call-template name="mediaurl">
+ <xsl:with-param name="title" select="$title"/>
+ <xsl:with-param name="pid" select="$pid"/>
+ </xsl:call-template>
+</xsl:template>
+
</xsl:stylesheet>
diff --git a/templates/katsomo.fi/videopage.xsl b/templates/katsomo.fi/videopage.xsl
index 591a81b..76eb44e 100644
--- a/templates/katsomo.fi/videopage.xsl
+++ b/templates/katsomo.fi/videopage.xsl
@@ -5,12 +5,33 @@
xmlns:str="http://exslt.org/strings"
exclude-result-prefixes="str">
+<xsl:template name="main">
+<xsl:variable name="episodetitle">
+ <xsl:choose>
+ <xsl:when test="contains(/html/head/meta[@name='title']/@content, ' - Katsomo')">
+ <xsl:value-of select="substring-before(/html/head/meta[@name='title']/@content, ' - Katsomo')"/>
+ </xsl:when>
+ <xsl:when test="contains(/html/head/meta[@name='title']/@content, ' - MTV3 Katsomo')">
+ <xsl:value-of select="substring-before(/html/head/meta[@name='title']/@content, ' - MTV3 Katsomo')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="/html/head/meta[@name='title']/@content"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="pid" select="substring-before(substring-after(/html/body/script[contains(., 'userNav.play(')], 'userNav.play('), ',')"/>
+
+<xsl:if test="$pid">
+ <mediaurl>
+ <title><xsl:value-of select="$episodetitle"/></title>
+ <url><xsl:value-of select="concat('http://www.katsomo.fi/metafile.asx?p=', $pid, '&amp;bw=800')"/></url>
+ </mediaurl>
+</xsl:if>
+</xsl:template>
+
<xsl:template match="/">
-<!-- direct URLs on katsomo.fi not yet supported -->
-<mediaurl>
- <title></title>
- <url></url>
-</mediaurl>
+ <xsl:call-template name="main"/>
</xsl:template>
</xsl:stylesheet>
diff --git a/templates/www.katsomo.fi/videopage.xsl b/templates/www.katsomo.fi/videopage.xsl
index 591a81b..7496df8 100644
--- a/templates/www.katsomo.fi/videopage.xsl
+++ b/templates/www.katsomo.fi/videopage.xsl
@@ -1,16 +1,11 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:str="http://exslt.org/strings"
- exclude-result-prefixes="str">
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:import href="../katsomo.fi/videopage.xsl"/>
<xsl:template match="/">
-<!-- direct URLs on katsomo.fi not yet supported -->
-<mediaurl>
- <title></title>
- <url></url>
-</mediaurl>
+ <xsl:call-template name="main"/>
</xsl:template>
</xsl:stylesheet>