Comparing version 1.0.4 to 1.0.6
import { JspfPlaylistI } from '../../entities/interfaces'; | ||
import { DataConverter } from '../models'; | ||
export default class JspfConverter extends DataConverter { | ||
static readonly types: string[]; | ||
static readonly type = "jspf"; | ||
static readonly contentType = "application/jspf+json;charset=utf-8"; | ||
get(data: string): JspfPlaylistI; | ||
set(playlistData: JspfPlaylistI): string; | ||
} |
@@ -42,5 +42,6 @@ "use strict"; | ||
}; | ||
JspfConverter.types = ['jspf']; | ||
JspfConverter.type = 'jspf'; | ||
JspfConverter.contentType = 'application/jspf+json;charset=utf-8'; | ||
return JspfConverter; | ||
}(models_2.DataConverter)); | ||
exports.default = JspfConverter; |
import { DataConverter } from '../models'; | ||
import { JspfPlaylistI } from '../../entities/interfaces'; | ||
export default class M3u8Converter extends DataConverter { | ||
static readonly types: string[]; | ||
static readonly type = "m3u8"; | ||
static readonly contentType = "application/vnd.apple.mpegurl"; | ||
get(input: string): JspfPlaylistI; | ||
set(dto: JspfPlaylistI): string; | ||
} |
@@ -35,5 +35,6 @@ "use strict"; | ||
}; | ||
M3u8Converter.types = ['m3u', 'm3u8']; | ||
M3u8Converter.type = 'm3u8'; | ||
M3u8Converter.contentType = 'application/vnd.apple.mpegurl'; | ||
return M3u8Converter; | ||
}(models_1.DataConverter)); | ||
exports.default = M3u8Converter; |
import { DataConverter } from '../models'; | ||
import { JspfPlaylistI } from '../../entities/interfaces'; | ||
export default class PlsConverter extends DataConverter { | ||
static readonly types: string[]; | ||
static readonly type = "pls"; | ||
static readonly contentType = "audio/x-scpls"; | ||
get(input: string): JspfPlaylistI; | ||
set(dto: JspfPlaylistI): string; | ||
} |
@@ -35,5 +35,6 @@ "use strict"; | ||
}; | ||
PlsConverter.types = ['pls']; | ||
PlsConverter.type = 'pls'; | ||
PlsConverter.contentType = 'audio/x-scpls'; | ||
return PlsConverter; | ||
}(models_1.DataConverter)); | ||
exports.default = PlsConverter; |
@@ -73,2 +73,4 @@ "use strict"; | ||
function updateSingle(data, type) { | ||
if (!data) | ||
return; | ||
var prop_name = Object.keys(data)[0]; | ||
@@ -75,0 +77,0 @@ var prop_value = data[prop_name]; |
import { DataConverter } from '../models'; | ||
import { JspfPlaylistI } from '../../entities/interfaces'; | ||
export default class XspfConverter extends DataConverter { | ||
static readonly types: string[]; | ||
static readonly type = "xspf"; | ||
static readonly contentType = "application/xspf+xml;charset=utf-8"; | ||
get(data: string): JspfPlaylistI; | ||
set(data: JspfPlaylistI): string; | ||
} |
@@ -35,5 +35,6 @@ "use strict"; | ||
}; | ||
XspfConverter.types = ['xspf']; | ||
XspfConverter.type = 'xspf'; | ||
XspfConverter.contentType = 'application/xspf+xml;charset=utf-8'; | ||
return XspfConverter; | ||
}(models_1.DataConverter)); | ||
exports.default = XspfConverter; |
@@ -0,7 +1,13 @@ | ||
/// <reference types="node" /> | ||
import { JspfPlaylistI } from "../entities/interfaces"; | ||
import JspfConverter from './formats/jspf'; | ||
import M3uConverter from './formats/m3u'; | ||
import M3u8Converter from './formats/m3u8'; | ||
import PlsConverter from './formats/pls'; | ||
import XspfConverter from './formats/xspf'; | ||
import { ConvertOptionsI } from "./interfaces"; | ||
export declare function getConverterTypes(): string[]; | ||
export declare function getConverterByType(type: string): typeof JspfConverter; | ||
export declare function getConverterByType(type: string): typeof JspfConverter | typeof M3uConverter | typeof M3u8Converter | typeof PlsConverter | typeof XspfConverter; | ||
export declare function importPlaylist(data: string, format?: string, options?: ConvertOptionsI): JspfPlaylistI; | ||
export declare function exportPlaylist(dto: JspfPlaylistI, format?: string, options?: ConvertOptionsI): string; | ||
export declare function exportPlaylistAsBlob(dto: JspfPlaylistI, format?: string, options?: ConvertOptionsI): Blob; |
@@ -6,12 +6,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.exportPlaylist = exports.importPlaylist = exports.getConverterByType = exports.getConverterTypes = void 0; | ||
exports.exportPlaylistAsBlob = exports.exportPlaylist = exports.importPlaylist = exports.getConverterByType = exports.getConverterTypes = void 0; | ||
var models_1 = require("../entities/models"); | ||
var jspf_1 = __importDefault(require("./formats/jspf")); | ||
var m3u_1 = __importDefault(require("./formats/m3u")); | ||
var m3u8_1 = __importDefault(require("./formats/m3u8")); | ||
var pls_1 = __importDefault(require("./formats/pls")); | ||
var xspf_1 = __importDefault(require("./formats/xspf")); | ||
var converters = [jspf_1.default, m3u8_1.default, pls_1.default, xspf_1.default]; | ||
var converters = [jspf_1.default, m3u_1.default, m3u8_1.default, pls_1.default, xspf_1.default]; | ||
// Get a flat array of all the converter types | ||
function getConverterTypes() { | ||
return converters.flatMap(function (converter) { return converter.types; }); | ||
return converters.map(function (converter) { return converter.type; }); | ||
} | ||
@@ -21,3 +22,3 @@ exports.getConverterTypes = getConverterTypes; | ||
function getConverterByType(type) { | ||
var converter = converters.find(function (converter) { return converter.types.includes(type); }); | ||
var converter = converters.find(function (converter) { return converter.type === type; }); | ||
if (converter) { | ||
@@ -78,1 +79,12 @@ return converter; | ||
exports.exportPlaylist = exportPlaylist; | ||
function exportPlaylistAsBlob(dto, format, options) { | ||
if (format === void 0) { format = 'jspf'; } | ||
if (options === void 0) { options = { ignoreValidationErrors: false, stripInvalid: true }; } | ||
var converterClass = getConverterByType(format); | ||
var blobString = exportPlaylist(dto, format, options); | ||
var blob = new Blob([blobString], { | ||
type: converterClass.contentType | ||
}); | ||
return blob; | ||
} | ||
exports.exportPlaylistAsBlob = exportPlaylistAsBlob; |
@@ -5,4 +5,5 @@ import { JspfPlaylistI } from '../entities/interfaces'; | ||
static readonly types: string[]; | ||
static readonly contentType: string; | ||
abstract get(data: any): JspfPlaylistI; | ||
abstract set(dto: JspfPlaylistI): string; | ||
} |
@@ -8,3 +8,4 @@ "use strict"; | ||
DataConverter.types = []; | ||
DataConverter.contentType = ''; | ||
return DataConverter; | ||
}()); |
{ | ||
"name": "jspf-cli", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"description": "JSPF CLI is a command line utility (CLI) relying on the JSPF format to convert and validate playlist files.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,3 +7,4 @@ import { classToPlain } from 'class-transformer'; | ||
export default class JspfConverter extends DataConverter { | ||
public static readonly types = ['jspf']; | ||
public static readonly type = 'jspf'; | ||
public static readonly contentType = 'application/jspf+json;charset=utf-8'; | ||
@@ -10,0 +11,0 @@ public get(data:string):JspfPlaylistI{ |
@@ -7,3 +7,4 @@ import { DataConverter } from '../models'; | ||
export default class M3u8Converter extends DataConverter { | ||
public static readonly types = ['m3u','m3u8']; | ||
public static readonly type = 'm3u8'; | ||
public static readonly contentType = 'application/vnd.apple.mpegurl'; | ||
@@ -10,0 +11,0 @@ public get(input:string):JspfPlaylistI{ |
@@ -7,3 +7,4 @@ import { DataConverter } from '../models'; | ||
export default class PlsConverter extends DataConverter { | ||
public static readonly types = ['pls']; | ||
public static readonly type = 'pls'; | ||
public static readonly contentType = 'audio/x-scpls'; | ||
@@ -10,0 +11,0 @@ public get(input:string):JspfPlaylistI{ |
@@ -82,2 +82,4 @@ import { json2xml } from 'xml-js'; | ||
function updateSingle(data:any,type:string){ | ||
if (!data) return; | ||
const prop_name:string = Object.keys(data)[0]; | ||
@@ -84,0 +86,0 @@ const prop_value:any = data[prop_name]; |
@@ -7,3 +7,4 @@ import { DataConverter } from '../models'; | ||
export default class XspfConverter extends DataConverter { | ||
public static readonly types = ['xspf']; | ||
public static readonly type = 'xspf'; | ||
public static readonly contentType = 'application/xspf+xml;charset=utf-8'; | ||
@@ -10,0 +11,0 @@ public get(data:string):JspfPlaylistI{ |
@@ -9,2 +9,3 @@ import * as fs from 'fs'; | ||
import JspfConverter from './formats/jspf'; | ||
import M3uConverter from './formats/m3u'; | ||
import M3u8Converter from './formats/m3u8'; | ||
@@ -15,7 +16,7 @@ import PlsConverter from './formats/pls'; | ||
const converters = [JspfConverter, M3u8Converter, PlsConverter, XspfConverter]; | ||
const converters = [JspfConverter, M3uConverter, M3u8Converter, PlsConverter, XspfConverter]; | ||
// Get a flat array of all the converter types | ||
export function getConverterTypes(): string[] { | ||
return converters.flatMap((converter) => converter.types); | ||
return converters.map((converter) => converter.type); | ||
} | ||
@@ -25,3 +26,3 @@ | ||
export function getConverterByType(type: string) { | ||
const converter = converters.find(converter => converter.types.includes(type)); | ||
const converter = converters.find(converter => converter.type === type); | ||
if (converter) { | ||
@@ -80,1 +81,13 @@ return converter; | ||
} | ||
export function exportPlaylistAsBlob(dto:JspfPlaylistI,format:string='jspf',options: ConvertOptionsI = {ignoreValidationErrors: false,stripInvalid:true}):Blob{ | ||
const converterClass = getConverterByType(format); | ||
let blobString:string = exportPlaylist(dto,format,options); | ||
let blob = new Blob([blobString], { | ||
type: converterClass.contentType | ||
}); | ||
return blob; | ||
} |
@@ -6,2 +6,3 @@ import {JspfPlaylistI} from '../entities/interfaces'; | ||
public static readonly types: string[] = []; | ||
public static readonly contentType: string = ''; | ||
@@ -8,0 +9,0 @@ //get DTO playlist from data |
187296
82
4582