Update dinosaurwet
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Controller, Get, Res } from '@nestjs/common';
|
import { Controller, Get, Res } from '@nestjs/common';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
|
import { identity } from 'ramda';
|
||||||
import * as xml from 'xml';
|
import * as xml from 'xml';
|
||||||
|
|
||||||
const episodeFiles: [number, string][] = [
|
const episodeFiles: [number, string][] = [
|
||||||
@@ -27,7 +28,16 @@ const episodeFiles: [number, string][] = [
|
|||||||
|
|
||||||
const startDate = new Date('2023-10-02');
|
const startDate = new Date('2023-10-02');
|
||||||
|
|
||||||
const episodes = episodeFiles.map((file, i) => {
|
type Episode = {
|
||||||
|
filename: string;
|
||||||
|
length: number;
|
||||||
|
url: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
fakeReleaseDate: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
const episodes: Episode[] = episodeFiles.map((file, i) => {
|
||||||
const [length, filename] = file;
|
const [length, filename] = file;
|
||||||
return {
|
return {
|
||||||
filename,
|
filename,
|
||||||
@@ -40,69 +50,79 @@ const episodes = episodeFiles.map((file, i) => {
|
|||||||
.trim(),
|
.trim(),
|
||||||
description:
|
description:
|
||||||
'A bootleg-ish of Dinosar Wet, making the downloaded files more like and RSS feed',
|
'A bootleg-ish of Dinosar Wet, making the downloaded files more like and RSS feed',
|
||||||
fakeReleaseDate: new Date(startDate).setDate(startDate.getDate() + i * 7),
|
fakeReleaseDate: new Date(
|
||||||
|
new Date(startDate).setDate(startDate.getDate() + i * 7),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const buildFeeds = (
|
||||||
|
episodes: Episode[],
|
||||||
|
dateFn: (date: Date) => Date = identity,
|
||||||
|
) => {
|
||||||
|
const feedObject = {
|
||||||
|
rss: [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
version: '2.0',
|
||||||
|
'xmlns:atom': 'http://www.w3.org/2005/Atom',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
channel: [
|
||||||
|
{
|
||||||
|
'atom:link': {
|
||||||
|
_attr: {
|
||||||
|
href: 'https://api.us.dev/dinosaurwet',
|
||||||
|
rel: 'self',
|
||||||
|
type: 'application/rss+xml',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Dinosaur Wet - All At Once',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
link: 'https://sanspantsradio.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description:
|
||||||
|
'A recreation of Dinosaur Wet as an RSS feed for listeners-with-licenses enjoyment.',
|
||||||
|
},
|
||||||
|
{ language: 'en-US' },
|
||||||
|
...episodes.map(({ title, url, length }) => ({
|
||||||
|
item: [
|
||||||
|
{ title },
|
||||||
|
{ guid: url },
|
||||||
|
{ pubDate: startDate.toUTCString() },
|
||||||
|
{
|
||||||
|
enclosure: [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
url,
|
||||||
|
type: 'audio/mpeg',
|
||||||
|
length,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const feed = '<?xml version="1.0" encoding="UTF-8"?>' + xml(feedObject);
|
||||||
|
return feed;
|
||||||
|
};
|
||||||
|
|
||||||
@Controller('dinosaurwet')
|
@Controller('dinosaurwet')
|
||||||
export class DinosaurwetController {
|
export class DinosaurwetController {
|
||||||
@Get('')
|
@Get('')
|
||||||
getAllAtOnce(@Res() response: Response) {
|
getAllAtOnce(@Res() response: Response) {
|
||||||
response.header('Content-Type', 'application/xml');
|
response.header('Content-Type', 'application/xml');
|
||||||
const feedObject = {
|
const feed = buildFeeds(episodes);
|
||||||
rss: [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
version: '2.0',
|
|
||||||
'xmlns:atom': 'http://www.w3.org/2005/Atom',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
channel: [
|
|
||||||
{
|
|
||||||
'atom:link': {
|
|
||||||
_attr: {
|
|
||||||
href: 'https://api.us.dev/dinosaurwet',
|
|
||||||
rel: 'self',
|
|
||||||
type: 'application/rss+xml',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Dinosaur Wet - All At Once',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
link: 'https://sanspantsradio.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description:
|
|
||||||
'A recreation of Dinosaur Wet as an RSS feed for listeners-with-licenses enjoyment.',
|
|
||||||
},
|
|
||||||
{ language: 'en-US' },
|
|
||||||
...episodes.map(({ title, url, length }) => ({
|
|
||||||
item: [
|
|
||||||
{ title },
|
|
||||||
{ guid: url },
|
|
||||||
{ pubDate: startDate.toUTCString() },
|
|
||||||
{
|
|
||||||
enclosure: [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
url,
|
|
||||||
type: 'audio/mpeg',
|
|
||||||
length,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const feed = '<?xml version="1.0" encoding="UTF-8"?>' + xml(feedObject);
|
|
||||||
return response.send(feed);
|
return response.send(feed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user