diff --git a/lib/middleware/template.js b/lib/middleware/template.js
index 6b361f05d1..3e226dcdc5 100644
--- a/lib/middleware/template.js
+++ b/lib/middleware/template.js
@@ -45,7 +45,8 @@ module.exports = async (ctx, next) => {
}
if (item.enclosure_length) {
- const itunes_duration = Math.floor(item.enclosure_length / 3600) + ':' + Math.floor((item.enclosure_length % 3600) / 60) + ':' + (((item.enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2);
+ const itunes_duration =
+ Math.floor(item.enclosure_length / 3600) + ':' + (Math.floor((item.enclosure_length % 3600) / 60) / 100).toFixed(2).slice(-2) + ':' + (((item.enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2);
item.itunes_duration = itunes_duration;
}
});
diff --git a/lib/routes/test/index.js b/lib/routes/test/index.js
index a118408c07..794bc681f2 100644
--- a/lib/routes/test/index.js
+++ b/lib/routes/test/index.js
@@ -49,6 +49,17 @@ module.exports = async (ctx) => {
item = null;
}
+ if (ctx.params.id === 'enclosure') {
+ item = [
+ {
+ title: '',
+ link: 'https://github.com/DIYgod/RSSHub/issues/1',
+ enclosure_url: 'https://github.com/DIYgod/RSSHub/issues/1',
+ enclosure_length: 3661,
+ },
+ ];
+ }
+
if (ctx.query.mode === 'fulltext') {
item = [
{
@@ -60,6 +71,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `Test ${ctx.params.id}`,
+ itunes_author: ctx.params.id === 'enclosure' ? 'DIYgod' : null,
link: 'https://github.com/DIYgod/RSSHub',
item,
allowEmpty: ctx.params.id === 'allow_empty',
diff --git a/lib/views/rss.art b/lib/views/rss.art
index 8b8475eba7..6307901a4a 100644
--- a/lib/views/rss.art
+++ b/lib/views/rss.art
@@ -32,7 +32,7 @@
{{ $value.link }}
{{ if $value.itunes_item_image }}{{ /if }}
{{ if $value.enclosure_url }}{{ /if }}
- {{ if $value.itunes_duration }}{{ $value.itunes_duration }} {{ /if }}
+ {{ if itunes_author && $value.itunes_duration }}{{ $value.itunes_duration }} {{ /if }}
{{ if $value.author }}{{ /if }}
{{ if typeof $value.category === 'string' }}
{{ $value.category }}
diff --git a/test/middleware/template.js b/test/middleware/template.js
index 9d90c4f715..b93b37a7c1 100644
--- a/test/middleware/template.js
+++ b/test/middleware/template.js
@@ -68,4 +68,13 @@ describe('template', () => {
const parsed = await parser.parseString(response.text);
expect(parsed.items[0].title.length).toBe(103);
});
+
+ it(`enclosure`, async () => {
+ const response = await request.get('/test/enclosure');
+ const parsed = await parser.parseString(response.text);
+ expect(parsed.itunes.author).toBe('DIYgod');
+ expect(parsed.items[0].enclosure.url).toBe('https://github.com/DIYgod/RSSHub/issues/1');
+ expect(parsed.items[0].enclosure.length).toBe('3661');
+ expect(parsed.items[0].itunes.duration).toBe('1:01:01');
+ });
});