# mediaxml

> A general purpose module for working with XML that includes first class support for media manifests like ADI, mRSS, and SCTE-236.

Latest version **0.6.6** (published 2022-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install mediaxml
pnpm add mediaxml
yarn add mediaxml
bun add mediaxml
```

Provides the commands `mxml`, `mxpkg`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.6 |
| Published | 2022-04-27 |
| First published | 2021-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 36 |
| Unpacked size | 2.5 MB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Joseph Werle |
| Maintainers | bret, werle, 12core-bot, praash74 |
| Keywords | mrss, adi1, adi3, ansi, scte, 236, 2017, cable, labs, content, metadata, media, xml, manifest, package |

## Links

- npm: https://www.npmjs.com/package/mediaxml
- Repository: https://github.com/mediaxml/mediaxml
- Homepage: https://github.com/mediaxml/mediaxml#readme
- Issues: https://github.com/mediaxml/mediaxml/issues
- npm.io page: https://npm.io/package/mediaxml

## Dependencies (36)

- [ora](https://npm.io/package/ora.md) ^5.4.0
- [glob](https://npm.io/package/glob.md) ^7.1.6
- [mime](https://npm.io/package/mime.md) ^2.5.2
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [blake2b](https://npm.io/package/blake2b.md) ^2.1.3
- [defined](https://npm.io/package/defined.md) ^1.0.0
- [get-uri](https://npm.io/package/get-uri.md) ^3.0.2
- [jsonata](https://npm.io/package/jsonata.md) ^1.8.4
- [streamx](https://npm.io/package/streamx.md) ^2.10.3
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.1
- [entities](https://npm.io/package/entities.md) ^2.2.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.5
- [mutexify](https://npm.io/package/mutexify.md) ^1.3.1
- [camelcase](https://npm.io/package/camelcase.md) ^6.2.0
- [env-paths](https://npm.io/package/env-paths.md) ^2.2.1
- [pretty-ms](https://npm.io/package/pretty-ms.md) ^7.0.1
- [map-extend](https://npm.io/package/map-extend.md) ^0.1.0
- [nanoassert](https://npm.io/package/nanoassert.md) ^2.0.0
- [param-case](https://npm.io/package/param-case.md) ^3.0.4
- [chrono-node](https://npm.io/package/chrono-node.md) ^2.2.6
- [htmlparser2](https://npm.io/package/htmlparser2.md) ^6.1.0
- [cli-truncate](https://npm.io/package/cli-truncate.md) ^2.1.0
- [highlight.js](https://npm.io/package/highlight.js.md) ^10.7.0
- [npt-timecode](https://npm.io/package/npt-timecode.md) ^0.1.2
- [tinyduration](https://npm.io/package/tinyduration.md) ^3.2.1
- [date-and-time](https://npm.io/package/date-and-time.md) ^1.0.0
- [is-url-superb](https://npm.io/package/is-url-superb.md) ^5.0.0
- [to-snake-case](https://npm.io/package/to-snake-case.md) ^1.0.0
- [smpte-timecode](https://npm.io/package/smpte-timecode.md) ^1.2.3
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^3.19.0
- [number-to-words](https://npm.io/package/number-to-words.md) ^1.2.4
- [inverted-promise](https://npm.io/package/inverted-promise.md) ^1.0.1
- [@mediaxml/chromafi](https://npm.io/package/@mediaxml/chromafi.md) ^3.1.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.6.6 (latest) — 2022-04-27
- 0.6.5 — 2022-04-27
- 0.6.4 — 2022-04-27
- 0.6.3 — 2021-04-15
- 0.6.2 — 2021-03-20
- 0.6.1 — 2021-03-19
- 0.6.0 — 2021-03-18
- 0.5.6 — 2021-03-16
- 0.5.5 — 2021-03-16
- 0.5.4 — 2021-03-15
- 0.5.3 — 2021-03-15
- 0.5.2 — 2021-03-15
- 0.5.1 — 2021-03-15
- 0.5.0 — 2021-03-15
- 0.4.5 — 2021-03-15
- … 14 more at https://npm.io/package/mediaxml/versions

## README

![MediaXML](https://raw.githubusercontent.com/mediaxml/mediaxml/master/assets/logo-whitebackgroud.png)

> A general purpose module for working with XML that includes first
> class support for media manifests like ADI, mRSS, and SCTE-236.

## Status

> :warning: **_Under active development_**

## Installation

```sh
$ npm install mediaxml
```

## Usage

See the [Usage Guide](https://mediaxml.github.io/mediaxml/#usage).

## API

See the [API Documentation](https://mediaxml.github.io/mediaxml/#api).

## Getting Started

The **mediaxml** module provides various implementations of XML formats
for describing media packages, manifests, and feeds such as
[RSS](#rss-guide), [mRSS](#mrss-guide), [ADI](#adi-guide),
and [XMLTV](#xmltv-guide).

### Simple Example

In the example below, we parse a [rss](#rss-guide) feed and enumerate
all of the items in the document's channel.

```js
const path = require('path')
const rss = require('mediaxml/rss')
const fs = require('fs')

const stream = fs.createReadStream('feed.rss')
const document = rss.createDocument(stream)

document.ready(() => {
  for (const item of document.channel.items) {
    console.log(item.title, item.description, item.link)
  }
})
```

### Parsing Documents

Parsing a XML document using streams:

```js
const { Parser } = require('mediaxml/parser')
const path = require('path')
const fs = require('fs')

const stream = fs.createReadStream('epg.xml')
const parser = new Parser()

stream.pipe(parser.createWriteStream()).on('finish', () => {
  console.log(parser.rootNode.sourceInfoUrl, parser.rootNode.sourceInfoName)
  console.log(parser.rootNode.children)
  parser.createReadStream().pipe(process.stdout)
})
```

#### Querying the Document Object Model

The [query](#query-guide) API is a powerful tool for querying the
document object model produced by the [parser](#parsing-documents)
using [JSONata](https://jsonata.org) query syntax with a [preprocessor
syntax](#query-preprocessor).

```js
const { rootNode } = parser

// query root node decendent nodes with tag name "channel"
const channels = rootNode.query('[name="channel"]')

// query root node decendent nodes with a tag name "programme"
const programmes = rootNode.query('[name="programme"]')

// query all nodes in document with tag name "category"
// and select the text content (selected with the `:text` preprocessor function)
const categories = rootNode.query('**[name="category"]:text')

// query all nodes in document with tag name "programme"
// an `start` attribute (selected with the `attr()` preprocessor function)
// integer value greater than todays
const programmesInFuture = rootNode.query(`[
  name = "programmes" AND
  $int(attr(start)) > $int("${Date()}")
]`)
```

### Creating Documents

```js
const { createDocument } = require('mediaxml/document')

const document = createDocument({ nodeName: 'ADI' })
const metadata = document.createChild('Metadata')

metadata.createChild('AMS', {
  Asset_Class: 'package',
  Provider_ID: 'mylifetime.com',
  Provider: 'LIFETIMEMOVIECLUB_HD_UNIFIED',
  Product: 'SVOD',
  ...
})

metadata.createChild('App_Data', {
  App: 'SVOD',
  Name: 'Metadata_Spec_Version',
  Value: 'CableLabsVOD1'
})

metadata.createChild('App_Data', {
  App: 'SVOD',
  Name: 'Provider_Content_Tier',
  Value: 'LIFETIMEMOVIECLUB_HD_UNIFIED'
})

console.log(document.toString())
// <ADI>
//   <Metadata>
//     <AMS Asset_Class="package" Product="SVOD" Provider="LIFETIMEMOVIECLUB_HD_UNIFIED" Provider_ID="mylifetime.com" Verb="" Version_Major="3" Version_Minor="0" Creation_Date="2020-09-29" Description="AcquiredMovie_FriendsWhoKill_241958-package" Asset_ID="LFHP2419582007240000" Asset_Name="LFHP2419582007240000_AMVE_HD" />
//     <App_Data App="SVOD" Name="Metadata_Spec_Version" Value="CableLabsVOD1.1" />
//     <App_Data App="SVOD" Name="Provider_Content_Tier" Value="LIFETIMEMOVIECLUB_HD_UNIFIED" />
//   </Metadata>
// </ADI>
```

### Query API

Querying XML document nodes:

```js
const { createReadStream } = require('fs')
const { Document } = require('mediaxml/document')

const document = Document.from(createReadStream('file.xml'))
document.ready(() => {
  const textNodes = document.query('**[is text and is not empty]')
})
```

Query mRSS document objects:

```js
const { createReadStream } = require('fs')
const { Document } = require('mediaxml/mrss')

cont document = Document.from(createReadStream('file.rss'))
document.ready(() => {
  const items = document.query('channel.items')
  const titles = items.query('title') // items is a `Fragment` with a `query()` function
  const urls = items.query('mediaContent.url[contains "mp4"]')
})
```

### REPL

A [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) is
provided for interactive querying of data in a XML tree.

The REPL can be started by simply running the `mxml`:

```sh
$ mxml
Welcome to the MediaXML 0.2.0 CLI
Please report bugs to https://github.com/mediaxml/mediaxml/issues
mxml(-)>
```

Importing a file can be done with the `import` keyword. This will import
an XML file into the REPL context.

```js
mxml(-)> import "./example/mrss/feed.xml"
mxml(-)> this
<rss>
  <channel>
    <title>Calm Meditation</title>
    <link>http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com</link>
    <language>en-us</language>
    ...
```

In the REPL, you can use the query syntax (JSONata with sugar) to query
data.

```js
mxml(-)> **[is node and text contains "amazonaws.com"] // searches all nodes with '**' wildcard operator
<link>http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com</link>
<link>http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com</link>
<url>http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com/images/calmmeditationlogo_small.png</url>
<link>http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com/shade/</link>
<guid isPermaLink="false">http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com/shade/</guid>
<link>http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com/spectators/</link>
<guid isPermaLink="false">http://sample-firetv-web-app.s3-website-us-west-2.amazonaws.com/spectators/</guid>
```

### Documentation

See the [Official Documentation](https://mediaxml.github.io/mediaxml) for
more information.

## See Also

  * [Media RSS Specification](https://www.rssboard.org/media-rss)
  * [CableLabs ADI 1 Specification](https://community.cablelabs.com/wiki/plugins/servlet/cablelabs/alfresco/download?id=8f900e8b-d1eb-4834-bd26-f04bd623c3d2)
  * [CableLabs ADI 1 Various Mappings](https://www.w3.org/2008/WebVideo/Annotations/drafts/ontology10/CR/mappings_tested/CableLabs1.htm)
  * [SCTE-236 - Content Metadata Specification](https://scte-cms-resource-storage.s3.amazonaws.com/ANSI_SCTE-35-2019a-1582645390859.pdf)
  * [XMLTV DTD](https://github.com/XMLTV/xmltv/blob/master/xmltv.dtd)
  * [XMLTV Format](http://wiki.xmltv.org/index.php/XMLTVFormat)

## Contributing

For more information, please refer to our [CONTRIBUTING](.github/CONTRIBUTING.md) guide.

## License

MIT

---
_Source: https://npm.io/package/mediaxml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
