Skip to content

Commit 449ec16

Browse files
committed
Implement audio and video playback
1 parent d934aec commit 449ec16

File tree

9 files changed

+55
-35
lines changed

9 files changed

+55
-35
lines changed

www/assets/css/common.css

+6
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ header .title {
214214
visually shown) */
215215
}
216216

217+
#itemViewContent video {
218+
max-width: 100%;
219+
height: auto;
220+
display: block;
221+
}
222+
217223
/* feed fetch error warning */
218224

219225
.feedInfoErrorBox {

www/assets/js/dialogs/simpleSubscription.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SimpleSubscriptionDialog extends Dialog {
3737
}
3838

3939
// First check if the URL is a real feed
40-
if(parserAutoDiscover(str)) {
40+
if(parserAutoDiscover(str, result.url)) {
4141
// If this is the case just use the URL
4242
links.push(result.url);
4343
} else {

www/assets/js/feedupdater.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class FeedUpdater {
1717
return response.text()
1818
})
1919
.then(async (str) => {
20-
let parser = parserAutoDiscover(str);
20+
let parser = parserAutoDiscover(str, url);
2121
if(!parser)
2222
return new Feed({ error: Feed.ERROR_DISCOVER });
2323

@@ -38,7 +38,9 @@ export class FeedUpdater {
3838

3939
return feed;
4040
})
41-
.catch(() => {
41+
.catch((e) => {
42+
console.log(e);
43+
4244
// FIXME: provide HTTP status too
4345
return new Feed({ error: Feed.ERROR_NET });
4446
});

www/assets/js/itemview.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ export class ItemView {
2525
<p>{{{item.description}}}</p>
2626
2727
{{#each item.media}}
28-
{{#contains 'audio' this.type }}
29-
<audio controls preload='none' src='{{ this.url }}'></audio>
28+
{{#contains 'audio' mime }}
29+
<audio controls preload='none' src='{{ url }}'></audio>
30+
{{/contains}}
31+
{{#contains 'video' mime }}
32+
<video controls preload='none' src='{{ url }}'></video>
3033
{{/contains}}
3134
{{/each}}
3235
`);

www/assets/js/parsers/atom.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ class AtomParser {
3737
}
3838
}
3939

40-
static parseEntry(node, feed) {
40+
static parseEntry(node, ctxt) {
4141
let item = new Item({
4242
title : XPath.lookup(node, 'ns:title'),
4343
description : XPath.lookup(node, 'ns:summary'),
4444
sourceId : XPath.lookup(node, 'ns:id'),
4545
time : DateParser.parse(XPath.lookup(node, 'ns:updated'))
4646
});
4747

48-
NamespaceParser.parseItem(node, ['dc', 'content', 'media'], feed, item);
48+
NamespaceParser.parseItem(ctxt.root, node, item);
4949

5050
XPath.foreach(node, 'ns:link', AtomParser.parseEntryLink, item);
5151

52-
feed.addItem(item);
52+
ctxt.feed.addItem(item);
5353
}
5454

5555
static parse(str) {
@@ -65,7 +65,7 @@ class AtomParser {
6565
XPath.lookup(root, "/ns:feed/ns:link/@href")
6666
});
6767

68-
XPath.foreach(root, '/ns:feed/ns:entry', this.parseEntry, feed);
68+
XPath.foreach(root, '/ns:feed/ns:entry', this.parseEntry, { root, feed });
6969

7070
return feed;
7171
}

www/assets/js/parsers/autodiscover.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ import { RSSParser } from './rss.js';
1111
import { RDFParser } from './rdf.js';
1212

1313
// Return a parser class matching the given document string or undefined
14-
function parserAutoDiscover(str) {
14+
function parserAutoDiscover(str, url = "") {
1515
let parsers = [AtomParser, RSSParser, RDFParser];
1616
const parser = new DOMParser();
1717
const doc = parser.parseFromString(str, 'application/xml');
1818

19-
console.info(`auto discover`)
19+
console.info(`auto discover ${url}`)
2020
for (let i = 0; i < parsers.length; i++) {
2121
for (let j = 0; j < parsers[i].autoDiscover.length; j++) {
2222
try {
2323
if (XPath.lookup(doc.firstChild, parsers[i].autoDiscover[j])) {
24-
console.info(`... discovered to be ${parsers[i].id}!`);
24+
console.info(`... discovered to be ${parsers[i].id} (${url}!`);
2525
return parsers[i];
2626
}
2727
} catch(e) {
2828
// ignore
2929
}
30-
console.info(`... is not ${parsers[i].id}`);
30+
console.info(`... is not ${parsers[i].id} (${url})`);
3131
}
3232
}
3333
return undefined;

www/assets/js/parsers/namespace.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ export class NamespaceParser {
99
/**
1010
* Parse all RSS namespace childs of a given DOM node
1111
*
12+
* @param {*} root the DOM root
1213
* @param {*} node the item DOM node
13-
* @param {*} nsList an array of namespace identifiers e.g. ["media", "dc"]
14-
* @param {*} feed the feed
1514
* @param {*} item the item
1615
*/
17-
static parseItem(node, nsList, feed, item) {
16+
static parseItem(root, node, item) {
17+
// Make list of all namespaces defined in root node, we must only
18+
// match for present namespaces
19+
const nsList = [];
20+
for (let i = 0; i < root.attributes.length; i++) {
21+
const attr = root.attributes[i];
22+
if (attr.name.startsWith('xmlns:')) {
23+
nsList.push(attr.name.substring(6));
24+
}
25+
}
26+
1827
// Dublin Core support
1928
if (nsList.includes('dc')) {
2029
if (!item.description)

www/assets/js/parsers/rdf.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ class RDFParser {
1313
'/rdf:RDF/ns:channel'
1414
];
1515

16-
static parseItem(node, feed) {
16+
static parseItem(node, ctxt) {
1717
let item = new Item({
18-
title: XPath.lookup(node, 'ns:title'),
19-
description: XPath.lookup(node, 'ns:description'),
20-
source: XPath.lookup(node, 'ns:link'),
18+
title : XPath.lookup(node, 'ns:title'),
19+
description : XPath.lookup(node, 'ns:description'),
20+
source : XPath.lookup(node, 'ns:link'),
2121
});
2222

23-
NamespaceParser.parseItem(node, ['dc', 'content', 'media'], feed, item);
23+
NamespaceParser.parseItem(ctxt.root, node, item);
2424

25-
feed.addItem(item);
25+
ctxt.feed.addItem(item);
2626
}
2727

2828
static parse(str) {
@@ -35,11 +35,11 @@ class RDFParser {
3535

3636
// RSS 1.0
3737
if (doc.firstChild.nodeName === 'rdf:RDF') {
38-
feed.title = XPath.lookup(root, '/rdf:RDF/ns:channel/ns:title');
38+
feed.title = XPath.lookup(root, '/rdf:RDF/ns:channel/ns:title');
3939
feed.description = XPath.lookup(root, '/rdf:RDF/ns:channel/ns:description');
40-
feed.homepage = XPath.lookup(root, '/rdf:RDF/ns:channel/ns:link');
40+
feed.homepage = XPath.lookup(root, '/rdf:RDF/ns:channel/ns:link');
4141

42-
XPath.foreach(root, '/rdf:RDF/ns:item', this.parseItem, feed);
42+
XPath.foreach(root, '/rdf:RDF/ns:item', this.parseItem, { root, feed });
4343
}
4444

4545
return feed;

www/assets/js/parsers/rss.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class RSSParser {
1616
'/Channel/items'
1717
];
1818

19-
static parseItem(node, feed) {
19+
static parseItem(node, ctxt) {
2020
let item = new Item({
21-
title: XPath.lookup(node, 'title'),
22-
description: XPath.lookup(node, 'description'),
23-
source: XPath.lookup(node, 'link'),
21+
title : XPath.lookup(node, 'title'),
22+
description : XPath.lookup(node, 'description'),
23+
source : XPath.lookup(node, 'link'),
2424
// RSS 2.0 only
25-
sourceId: XPath.lookup(node, 'guid'),
26-
time: DateParser.parse(XPath.lookup(node, 'pubDate'))
25+
sourceId : XPath.lookup(node, 'guid'),
26+
time : DateParser.parse(XPath.lookup(node, 'pubDate'))
2727
});
2828

2929
XPath.foreach(node, 'enclosure', (n) =>
@@ -33,9 +33,9 @@ class RSSParser {
3333
)
3434
);
3535

36-
NamespaceParser.parseItem(node, ['dc', 'content', 'media'], feed, item);
36+
NamespaceParser.parseItem(ctxt.root, node, item);
3737

38-
feed.addItem(item);
38+
ctxt.feed.addItem(item);
3939
}
4040

4141
static parse(str) {
@@ -52,7 +52,7 @@ class RSSParser {
5252
feed.description = XPath.lookup(root, '/Channel/description');
5353
feed.homepage = XPath.lookup(root, '/Channel/link');
5454

55-
XPath.foreach(root, '/Channel/items/item', this.parseItem, feed);
55+
XPath.foreach(root, '/Channel/items/item', this.parseItem, { root, feed });
5656
}
5757

5858
// RSS 2.0
@@ -61,7 +61,7 @@ class RSSParser {
6161
feed.description = XPath.lookup(root, '/rss/channel/description');
6262
feed.homepage = XPath.lookup(root, '/rss/channel/link');
6363

64-
XPath.foreach(root, '/rss/channel/item', this.parseItem, feed);
64+
XPath.foreach(root, '/rss/channel/item', this.parseItem, { root, feed });
6565
}
6666

6767
return feed;

0 commit comments

Comments
 (0)