forked from linnoss/MediaApps2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npr.xsl
118 lines (105 loc) · 4.68 KB
/
npr.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:where="http://where.yahooapis.com/v1/schema.rng" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:npr="http://www.npr.org/rss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="1.0">
<xsl:output method="xml" indent="yes"/>
<!-- ROOT -->
<xsl:template match="/plugin">
<plugin>
<name>NPR</name>
<enabled>false</enabled>
<period>1440</period>
<description>Radio stations and podcasts from America's National Public Radio network</description>
<link>http://www.npr.org/</link>
<artwork>http://www.npr.org/about/images/press/npr_logo.jpg</artwork>
<container>/home</container>
</plugin>
</xsl:template>
<!-- HOME -->
<xsl:template match="/container[text() = '/home']">
<container name="NPR">
<container>/live</container>
<container>/podcasts</container>
</container>
</xsl:template>
<!-- LIVE -->
<xsl:template match="/container[text() = '/live']">
<container name="Live Radio">
<xsl:for-each select="document('http://query.yahooapis.com/v1/public/yql?q=select+name+from+geo.states+where+place="United+States"')/query/results/where:place/where:name">
<xsl:sort select="."/>
<container>/state/<xsl:value-of select="." /></container>
</xsl:for-each>
</container>
</xsl:template>
<!-- STATES -->
<xsl:template match="/container[starts-with(text(),'/state')]">
<xsl:variable name="state" select="substring-after(text(),'/state/')" />
<container>
<xsl:attribute name="name"><xsl:value-of select="$state"/></xsl:attribute>
<xsl:variable name="xml">http://api.npr.org/stations.php?state=<xsl:value-of select="$state"/>&apiKey=MDA4MzQxMDI0MDEzMTkwNDkwNzQ4NTc1OQ001</xsl:variable>
<xsl:for-each select="document($xml)/stations/station/url[@typeId='10']">
<item>
<metadatum tag="type">audio</metadatum>
<metadatum tag="a.type">radio</metadatum>
<metadatum tag="a.title">
<xsl:value-of select="../callLetters" /> - <xsl:value-of select="../marketCity" /> - <xsl:value-of select="@title" />
</metadatum>
<metadatum tag="a.description">
<xsl:value-of select="../tagline" />
</metadatum>
<metadatum tag="a.uri">
<xsl:value-of select="." />
</metadatum>
<metadatum tag="a.artwork">
<xsl:value-of select="../image[@type='logo']"/>
</metadatum>
<metadatum tag="a.channels">2</metadatum>
<metadatum tag="a.codec">mp3</metadatum>
</item>
</xsl:for-each>
</container>
</xsl:template>
<!-- PODCASTS -->
<xsl:template match="/container[text() = '/podcasts']">
<container name="Podcasts">
<xsl:for-each select="document('http://api.npr.org/stations.php?id=1&apiKey=MDA4MzQxMDI0MDEzMTkwNDkwNzQ4NTc1OQ001')/stations/station/url[@typeId='9']">
<xsl:variable name="link" select="." />
<xsl:if test="contains($link, 'podcast.php?id=')">
<xsl:variable name="id" select="substring-after($link,'podcast.php?id=')" />
<container>/rss/<xsl:value-of select="$id" /></container>
</xsl:if>
</xsl:for-each>
</container>
</xsl:template>
<!-- RSS -->
<xsl:template match="/container[starts-with(text(),'/rss')]">
<xsl:variable name="id" select="substring-after(text(),'/rss/')" />
<xsl:variable name="rss">http://www.npr.org/rss/podcast.php?id=<xsl:value-of select="$id"/></xsl:variable>
<xsl:for-each select="document($rss)/rss/channel">
<xsl:variable name="artwork" select="itunes:image/@href" />
<container>
<xsl:attribute name="name">
<xsl:value-of select="image/title"/>
</xsl:attribute>
<xsl:attribute name="artwork">
<xsl:value-of select="$artwork"/>
</xsl:attribute>
<xsl:for-each select="item/enclosure">
<item>
<metadatum tag="type">audio</metadatum>
<metadatum tag="a.type">podcast</metadatum>
<metadatum tag="a.title">
<xsl:value-of select="../title" />
</metadatum>
<metadatum tag="a.description">
<xsl:value-of select="../description" />
</metadatum>
<metadatum tag="a.uri">
<xsl:value-of select="@url" />
</metadatum>
<metadatum tag="a.channels">2</metadatum>
<metadatum tag="a.codec">mp3</metadatum>
</item>
</xsl:for-each>
</container>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>