Skip to content

Commit

Permalink
Artist Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
troysandal committed Dec 19, 2023
1 parent e76dd3e commit af19eaa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export function format(playList:Playlist, trackIndex:number, formatString:string
return formatString
}

export function buildTags(playlist: Playlist): string[] {
const tags = playlist.tracks
.map((track) => track.collectionEntry.artist)
.map((artist) => artist.split(','))
.flat()
.map((artist) => artist.replace(/\(.*$/g, ''))
.map((artist) => artist.split('&'))
.flat()
.map((artist) => artist.trim().replace(/\s+/g, ''))
.map((artist) => `#${artist.toLocaleLowerCase()}`)

return [...new Set(tags)]
}

/**
* Converts a playlist to a human readable form.
Expand All @@ -38,6 +51,10 @@ export function format(playList:Playlist, trackIndex:number, formatString:string
export function playlistToReadable(playlist:Playlist, FORMAT_STRING:string): string {
const result = []

result.push('Artist Tags')
result.push(buildTags(playlist).join(' '))
result.push('')

result.push(playlist.name)

playlist.tracks
Expand Down
21 changes: 21 additions & 0 deletions test/specs/test.tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from 'chai'
import * as fs from 'fs'
import { Archive, Playlist } from '../../src/parsers/archive'
import { TraktorParser } from '../../src/parsers/traktor'
import { buildTags } from '../../src/formatter'
require('jsdom-global')()
global.DOMParser = window.DOMParser

describe('Track Tags', () => {
it('are generated', () => {
const p = `${__dirname}/../files/Rezidence28.nml`;
const fileContents = fs.readFileSync(p, 'utf8')
const parser = new TraktorParser(fileContents)
const archive:Archive = parser.parse() as Archive

let playlist = archive.playlists[0] as Playlist
const tags = buildTags(playlist)
expect(tags.length).to.eq(24)
expect(tags.indexOf('#marsh')).to.not.eq(-1)
})
})

0 comments on commit af19eaa

Please sign in to comment.