2021-08-23 21:08:54 +02:00
|
|
|
const Podcast = require('podcast')
|
|
|
|
const express = require('express')
|
|
|
|
const ip = require('ip')
|
|
|
|
const Logger = require('./Logger')
|
|
|
|
|
2021-09-01 20:47:18 +02:00
|
|
|
// Not functional at the moment - just an idea
|
2021-08-23 21:08:54 +02:00
|
|
|
class RssFeeds {
|
|
|
|
constructor(Port, db) {
|
|
|
|
this.Port = Port
|
|
|
|
this.db = db
|
|
|
|
this.feeds = {}
|
|
|
|
|
|
|
|
this.router = express()
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.router.get('/:id', this.getFeed.bind(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
getFeed(req, res) {
|
2021-10-31 02:12:36 +01:00
|
|
|
Logger.info('Get Feed', req.params.id, this.feeds[req.params.id])
|
|
|
|
|
2021-08-23 21:08:54 +02:00
|
|
|
var feed = this.feeds[req.params.id]
|
|
|
|
if (!feed) return null
|
|
|
|
var xml = feed.buildXml()
|
|
|
|
res.set('Content-Type', 'text/xml')
|
|
|
|
res.send(xml)
|
|
|
|
}
|
|
|
|
|
|
|
|
openFeed(audiobook) {
|
2021-10-31 02:12:36 +01:00
|
|
|
var ipAddress = ip.address('public', 'ipv4')
|
|
|
|
var serverAddress = 'http://' + ipAddress + ':' + this.Port
|
2021-08-23 21:08:54 +02:00
|
|
|
Logger.info('Open RSS Feed', 'Server address', serverAddress)
|
|
|
|
|
|
|
|
var feedId = (Date.now() + Math.floor(Math.random() * 1000)).toString(36)
|
|
|
|
const feed = new Podcast({
|
|
|
|
title: audiobook.title,
|
|
|
|
description: 'AudioBookshelf RSS Feed',
|
2021-10-31 02:12:36 +01:00
|
|
|
feed_url: `${serverAddress}/feeds/${feedId}`,
|
|
|
|
image_url: `${serverAddress}/Logo.png`,
|
2021-08-23 21:08:54 +02:00
|
|
|
author: 'advplyr',
|
|
|
|
language: 'en'
|
|
|
|
})
|
|
|
|
audiobook.tracks.forEach((track) => {
|
|
|
|
feed.addItem({
|
|
|
|
title: `Track ${track.index}`,
|
|
|
|
description: `AudioBookshelf Audiobook Track #${track.index}`,
|
|
|
|
url: `${serverAddress}/feeds/${feedId}?track=${track.index}`,
|
|
|
|
author: 'advplyr'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.feeds[feedId] = feed
|
|
|
|
return feed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = RssFeeds
|