@sequencemedia/music-library-parser 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/babel.config.cjs +24 -0
- package/index.mjs +4 -0
- package/package.json +70 -0
- package/src/js/index.mjs +10 -0
- package/src/js/library/index.mjs +122 -0
- package/src/js/library/playlists/index.mjs +120 -0
- package/src/js/library/playlists/transform/index.mjs +82 -0
- package/src/js/library/tracks/index.mjs +121 -0
- package/src/js/library/tracks/transform/index.mjs +82 -0
- package/src/js/library/transform/index.mjs +82 -0
- package/src/js/transform/index.mjs +28 -0
- package/src/xsl/library/playlists/to-json.xsl +14 -0
- package/src/xsl/library/playlists.xsl +187 -0
- package/src/xsl/library/to-json.xsl +12 -0
- package/src/xsl/library/tracks/to-json.xsl +14 -0
- package/src/xsl/library/tracks.xsl +201 -0
- package/src/xsl/library.xsl +15 -0
- package/src/xsl/to-json.xsl +67 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exec
|
|
3
|
+
} from 'child_process'
|
|
4
|
+
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
fileURLToPath
|
|
9
|
+
} from 'url'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
readFile
|
|
13
|
+
} from 'fs/promises'
|
|
14
|
+
|
|
15
|
+
import debug from 'debug'
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
transform
|
|
19
|
+
} from '#music-library-parser/transform'
|
|
20
|
+
|
|
21
|
+
const error = debug('@sequencemedia/music-library-parser:to-json:error')
|
|
22
|
+
|
|
23
|
+
const cwd = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../..')
|
|
24
|
+
const xsl = path.resolve(cwd, 'src/xsl/library/tracks/to-json.xsl')
|
|
25
|
+
const DESTINATION = path.resolve(cwd, '.music-library/tracks.json')
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `maxBuffer`
|
|
29
|
+
*/
|
|
30
|
+
export function parse (jar, xml, destination = DESTINATION) {
|
|
31
|
+
return (
|
|
32
|
+
new Promise((resolve, reject) => {
|
|
33
|
+
exec(`java -jar "${path.resolve(jar)}" -s:"${path.resolve(xml)}" -xsl:"${xsl}" -o:"${destination}"`, { cwd }, (e) => (!e) ? resolve() : reject(e))
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function execute (jar, xml) {
|
|
39
|
+
await parse(jar, xml, DESTINATION)
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
await readFile(DESTINATION, 'utf8')
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function toJSON (jar, xml) {
|
|
47
|
+
try {
|
|
48
|
+
const fileData = await execute(jar, xml)
|
|
49
|
+
|
|
50
|
+
return fileData.toString('utf8')
|
|
51
|
+
} catch ({ message }) {
|
|
52
|
+
error(message)
|
|
53
|
+
|
|
54
|
+
throw new Error('Failed to process XML to JSON')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function toJS (jar, xml) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(await toJSON(jar, xml))
|
|
61
|
+
} catch ({ message }) {
|
|
62
|
+
error(message)
|
|
63
|
+
|
|
64
|
+
throw new Error('Failed to process XML to JS')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function toES (jar, xml) {
|
|
69
|
+
try {
|
|
70
|
+
return transform(JSON.parse(await toJSON(jar, xml)))
|
|
71
|
+
} catch ({ message }) {
|
|
72
|
+
error(message)
|
|
73
|
+
|
|
74
|
+
throw new Error('Failed to process XML to ES')
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default {
|
|
79
|
+
toJSON,
|
|
80
|
+
toJS,
|
|
81
|
+
toES
|
|
82
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exec
|
|
3
|
+
} from 'child_process'
|
|
4
|
+
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
fileURLToPath
|
|
9
|
+
} from 'url'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
readFile
|
|
13
|
+
} from 'fs/promises'
|
|
14
|
+
|
|
15
|
+
import debug from 'debug'
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
transform
|
|
19
|
+
} from '#music-library-parser/transform'
|
|
20
|
+
|
|
21
|
+
const error = debug('@sequencemedia/music-library-parser:to-json:error')
|
|
22
|
+
|
|
23
|
+
const cwd = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../..')
|
|
24
|
+
const xsl = path.resolve(cwd, 'src/xsl/library/to-json.xsl')
|
|
25
|
+
const DESTINATION = path.resolve(cwd, '.music-library.json')
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `maxBuffer`
|
|
29
|
+
*/
|
|
30
|
+
export function parse (jar, xml, destination = DESTINATION) {
|
|
31
|
+
return (
|
|
32
|
+
new Promise((resolve, reject) => {
|
|
33
|
+
exec(`java -jar "${path.resolve(jar)}" -s:"${path.resolve(xml)}" -xsl:"${xsl}" -o:"${destination}"`, { cwd }, (e) => (!e) ? resolve() : reject(e))
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function execute (jar, xml) {
|
|
39
|
+
await parse(jar, xml, DESTINATION)
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
await readFile(DESTINATION, 'utf8')
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function toJSON (jar, xml) {
|
|
47
|
+
try {
|
|
48
|
+
const fileData = await execute(jar, xml)
|
|
49
|
+
|
|
50
|
+
return fileData.toString('utf8')
|
|
51
|
+
} catch ({ message }) {
|
|
52
|
+
error(message)
|
|
53
|
+
|
|
54
|
+
throw new Error('Failed to process XML to JSON')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function toJS (jar, xml) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(await toJSON(jar, xml))
|
|
61
|
+
} catch ({ message }) {
|
|
62
|
+
error(message)
|
|
63
|
+
|
|
64
|
+
throw new Error('Failed to process XML to JS')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function toES (jar, xml) {
|
|
69
|
+
try {
|
|
70
|
+
return transform(JSON.parse(await toJSON(jar, xml)))
|
|
71
|
+
} catch ({ message }) {
|
|
72
|
+
error(message)
|
|
73
|
+
|
|
74
|
+
throw new Error('Failed to process XML to ES')
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default {
|
|
79
|
+
toJSON,
|
|
80
|
+
toJS,
|
|
81
|
+
toES
|
|
82
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const transformObjectToMap = (o, m) => {
|
|
2
|
+
Object.entries(o)
|
|
3
|
+
.forEach(([key, value] = []) => {
|
|
4
|
+
switch ((value || false).constructor) {
|
|
5
|
+
case Object:
|
|
6
|
+
m.set(key, transformObjectToMap(value, new Map()))
|
|
7
|
+
break
|
|
8
|
+
|
|
9
|
+
case Array:
|
|
10
|
+
m.set(key, transformArrayToSet(value, new Set()))
|
|
11
|
+
break
|
|
12
|
+
|
|
13
|
+
default:
|
|
14
|
+
m.set(key, /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/.test(value) ? new Date(value) : value)
|
|
15
|
+
break
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
return m
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const transformArrayToSet = (a, s) => {
|
|
22
|
+
a.forEach((o) => {
|
|
23
|
+
s.add(transform(o))
|
|
24
|
+
})
|
|
25
|
+
return s
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const transform = (v) => Array.isArray(v) ? transformArrayToSet(v, new Set()) : transformObjectToMap(v, new Map())
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsl:stylesheet version="2.0"
|
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4
|
+
exclude-result-prefixes="xsl">
|
|
5
|
+
<xsl:output encoding="UTF-8" method="text" omit-xml-declaration="yes" indent="no" />
|
|
6
|
+
|
|
7
|
+
<xsl:import href="../../to-json.xsl" />
|
|
8
|
+
|
|
9
|
+
<xsl:template match="/">
|
|
10
|
+
<xsl:text>{</xsl:text>
|
|
11
|
+
<xsl:apply-templates select="plist/dict/key[. = 'Playlists']" />
|
|
12
|
+
<xsl:text>}</xsl:text>
|
|
13
|
+
</xsl:template>
|
|
14
|
+
</xsl:stylesheet>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsl:stylesheet version="2.0"
|
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4
|
+
xmlns:seq="http://sequencemedia.net"
|
|
5
|
+
xmlns:url-decoder="java:java.net.URLDecoder"
|
|
6
|
+
exclude-result-prefixes="xsl seq url-decoder">
|
|
7
|
+
<xsl:output encoding="UTF-8" method="text" omit-xml-declaration="yes" indent="no" />
|
|
8
|
+
|
|
9
|
+
<xsl:param name="destination" />
|
|
10
|
+
|
|
11
|
+
<xsl:variable name="tracks" select="/plist/dict/key[. = 'Tracks']/following-sibling::dict" />
|
|
12
|
+
<xsl:variable name="playlists" select="/plist/dict/key[. = 'Playlists']/following-sibling::array/dict" />
|
|
13
|
+
|
|
14
|
+
<!-- https://en.wikipedia.org/wiki/Combining_character -->
|
|
15
|
+
<xsl:function name="seq:remove-combining-characters">
|
|
16
|
+
<xsl:param name="s" />
|
|
17
|
+
|
|
18
|
+
<xsl:value-of
|
|
19
|
+
select="
|
|
20
|
+
translate(translate(translate(translate(translate(translate(translate($s,
|
|
21
|
+
'̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏', ''),
|
|
22
|
+
'̛̖̗̘̙̜̝̞̟̐̑̒̓̔̕̚', ''),
|
|
23
|
+
'̡̢̧̨̠̣̤̥̦̩̪̫̬̭̮̯', ''),
|
|
24
|
+
'̴̵̶̷̸̰̱̲̳̹̺̻̼̽̾̿', ''),
|
|
25
|
+
'͇͈͉͍͎̀́͂̓̈́͆͊͋͌ͅ͏', ''),
|
|
26
|
+
'͓͔͕͖͙͚͐͑͒͗͛͘͜͟͝͞', ''),
|
|
27
|
+
'ͣͤͥͦͧͨͩͪͫͬͭͮͯ͢͠͡', '')"
|
|
28
|
+
/>
|
|
29
|
+
</xsl:function>
|
|
30
|
+
|
|
31
|
+
<xsl:function name="seq:normalize-for-path">
|
|
32
|
+
<xsl:param name="s" />
|
|
33
|
+
|
|
34
|
+
<xsl:value-of
|
|
35
|
+
select="normalize-space(seq:remove-combining-characters(translate(replace(normalize-unicode($s, 'NFD'), '["%\[\]*?]', '_'), '\/:', '___')))"
|
|
36
|
+
/>
|
|
37
|
+
</xsl:function>
|
|
38
|
+
|
|
39
|
+
<xsl:function name="seq:get-file-path">
|
|
40
|
+
<xsl:param name="playlist" />
|
|
41
|
+
|
|
42
|
+
<xsl:variable name="parentId" select="$playlist/key[. = 'Parent Persistent ID']/following-sibling::*[1]/text()" />
|
|
43
|
+
<xsl:variable name="name" select="$playlist/key[. = 'Name']/following-sibling::*[1]/text()" />
|
|
44
|
+
|
|
45
|
+
<xsl:if test="string-length($parentId)">
|
|
46
|
+
<xsl:value-of select="seq:get-file-path($playlists[
|
|
47
|
+
key[. = 'Playlist Persistent ID']/following-sibling::*[1]/text() eq $parentId
|
|
48
|
+
])" />
|
|
49
|
+
<xsl:text>/</xsl:text>
|
|
50
|
+
</xsl:if>
|
|
51
|
+
|
|
52
|
+
<xsl:value-of select="seq:normalize-for-path($name)" />
|
|
53
|
+
</xsl:function>
|
|
54
|
+
|
|
55
|
+
<xsl:function name="seq:get-href-for-playlist">
|
|
56
|
+
<xsl:param name="parentId" />
|
|
57
|
+
<xsl:param name="name" />
|
|
58
|
+
<xsl:param name="position" />
|
|
59
|
+
|
|
60
|
+
<xsl:variable name="filePath">
|
|
61
|
+
<xsl:if test="string-length($parentId)">
|
|
62
|
+
<xsl:value-of select="seq:get-file-path($playlists[
|
|
63
|
+
key[. = 'Playlist Persistent ID']/following-sibling::*[1]/text() eq $parentId
|
|
64
|
+
])" />
|
|
65
|
+
</xsl:if>
|
|
66
|
+
</xsl:variable>
|
|
67
|
+
|
|
68
|
+
<xsl:variable name="fileName" select="seq:normalize-for-path($name)" />
|
|
69
|
+
|
|
70
|
+
<xsl:choose>
|
|
71
|
+
<xsl:when test="$destination">
|
|
72
|
+
<xsl:value-of select="$destination" />
|
|
73
|
+
<xsl:text>/Playlists/</xsl:text>
|
|
74
|
+
</xsl:when>
|
|
75
|
+
<xsl:otherwise>
|
|
76
|
+
<xsl:text>Music Library/Playlists/</xsl:text>
|
|
77
|
+
</xsl:otherwise>
|
|
78
|
+
</xsl:choose>
|
|
79
|
+
|
|
80
|
+
<xsl:if test="$filePath">
|
|
81
|
+
<xsl:value-of select="$filePath" />
|
|
82
|
+
<xsl:text>/</xsl:text>
|
|
83
|
+
</xsl:if>
|
|
84
|
+
<xsl:value-of select="$fileName" />
|
|
85
|
+
|
|
86
|
+
<xsl:if test="number($position)">
|
|
87
|
+
<xsl:text> (</xsl:text>
|
|
88
|
+
<xsl:value-of select="$position" />
|
|
89
|
+
<xsl:text>)</xsl:text>
|
|
90
|
+
</xsl:if>
|
|
91
|
+
|
|
92
|
+
<xsl:text>.m3u8</xsl:text>
|
|
93
|
+
</xsl:function>
|
|
94
|
+
|
|
95
|
+
<xsl:function name="seq:get-href-for-playlist">
|
|
96
|
+
<xsl:param name="parentId" />
|
|
97
|
+
<xsl:param name="name" />
|
|
98
|
+
<xsl:value-of select="seq:get-href-for-playlist($parentId, $name, 0)" />
|
|
99
|
+
</xsl:function>
|
|
100
|
+
|
|
101
|
+
<xsl:template match="key[. = 'Playlists']">
|
|
102
|
+
<xsl:variable
|
|
103
|
+
name="playlists"
|
|
104
|
+
select="following-sibling::array[1]/dict[
|
|
105
|
+
key[. = 'Playlist Items'] and
|
|
106
|
+
key[. = 'Playlist Items']/following-sibling::array[1]/* and
|
|
107
|
+
not(key[. = 'Distinguished Kind']) and
|
|
108
|
+
not(key[. = 'Smart Info']) and
|
|
109
|
+
not(local-name(key[. = 'Folder']/following-sibling::*[1]) eq 'true') and
|
|
110
|
+
not(local-name(key[. = 'Visible']/following-sibling::*[1]) eq 'false')
|
|
111
|
+
]"
|
|
112
|
+
/>
|
|
113
|
+
|
|
114
|
+
<xsl:for-each select="$playlists">
|
|
115
|
+
<xsl:variable name="parentId" select="key[. = 'Parent Persistent ID']/following-sibling::*[1]/text()" />
|
|
116
|
+
<xsl:variable name="name" select="key[. = 'Name']/following-sibling::*[1]/text()" />
|
|
117
|
+
|
|
118
|
+
<xsl:variable name="instances" select="$playlists[
|
|
119
|
+
key[. = 'Parent Persistent ID']/following-sibling::*[1]/text() eq $parentId and key[. = 'Name']/following-sibling::*[1]/text() eq $name
|
|
120
|
+
]" />
|
|
121
|
+
|
|
122
|
+
<xsl:choose>
|
|
123
|
+
<xsl:when test="count($instances) gt 1">
|
|
124
|
+
<xsl:variable name="playlist" select="." />
|
|
125
|
+
|
|
126
|
+
<xsl:for-each select="$instances">
|
|
127
|
+
<xsl:if test=". = $playlist">
|
|
128
|
+
<xsl:result-document href="{seq:get-href-for-playlist($parentId, $name, position())}" method="text">
|
|
129
|
+
<xsl:apply-templates mode="playlist" select="array" />
|
|
130
|
+
</xsl:result-document>
|
|
131
|
+
</xsl:if>
|
|
132
|
+
</xsl:for-each>
|
|
133
|
+
</xsl:when>
|
|
134
|
+
<xsl:otherwise>
|
|
135
|
+
<xsl:result-document href="{seq:get-href-for-playlist($parentId, $name)}" method="text">
|
|
136
|
+
<xsl:apply-templates mode="playlist" select="array" />
|
|
137
|
+
</xsl:result-document>
|
|
138
|
+
</xsl:otherwise>
|
|
139
|
+
</xsl:choose>
|
|
140
|
+
</xsl:for-each>
|
|
141
|
+
</xsl:template>
|
|
142
|
+
|
|
143
|
+
<!-- Playlist: #EXTM3U -->
|
|
144
|
+
<xsl:template mode="playlist" match="array">
|
|
145
|
+
<xsl:text>#EXTM3U</xsl:text>
|
|
146
|
+
<xsl:text> </xsl:text>
|
|
147
|
+
|
|
148
|
+
<xsl:for-each select="dict/key[. = 'Track ID']">
|
|
149
|
+
<xsl:variable name="trackId" select="following-sibling::*[1]/text()" />
|
|
150
|
+
<xsl:apply-templates mode="playlist-track" select="$tracks[1]/key[. = $trackId]/following-sibling::dict[1]" />
|
|
151
|
+
</xsl:for-each>
|
|
152
|
+
</xsl:template>
|
|
153
|
+
|
|
154
|
+
<!-- Playlist track: #EXTINF -->
|
|
155
|
+
<xsl:template mode="playlist-track" match="dict">
|
|
156
|
+
<xsl:variable name="totalTime" select="floor(number(key[. = 'Total Time']/following-sibling::*[1]/text()) div 1000)" />
|
|
157
|
+
<xsl:variable name="location" select="url-decoder:decode(replace(key[. = 'Location']/following-sibling::*[1]/text(), '[+]', '%2b'))" />
|
|
158
|
+
|
|
159
|
+
<xsl:text>#EXTINF:</xsl:text>
|
|
160
|
+
<xsl:choose>
|
|
161
|
+
<xsl:when test="number($totalTime)">
|
|
162
|
+
<xsl:value-of select="$totalTime" />
|
|
163
|
+
</xsl:when>
|
|
164
|
+
<xsl:otherwise>
|
|
165
|
+
<xsl:text>-1</xsl:text>
|
|
166
|
+
</xsl:otherwise>
|
|
167
|
+
</xsl:choose>
|
|
168
|
+
<xsl:text>,</xsl:text>
|
|
169
|
+
<xsl:value-of select="normalize-space(key[. = 'Name']/following-sibling::*[1]/text())" />
|
|
170
|
+
<xsl:text> - </xsl:text>
|
|
171
|
+
<xsl:value-of select="normalize-space(key[. = 'Artist']/following-sibling::*[1]/text())" />
|
|
172
|
+
<xsl:text> </xsl:text>
|
|
173
|
+
<xsl:choose>
|
|
174
|
+
<xsl:when test="starts-with($location, 'file://')">
|
|
175
|
+
<xsl:value-of select="substring($location, 8)" />
|
|
176
|
+
</xsl:when>
|
|
177
|
+
<xsl:otherwise>
|
|
178
|
+
<xsl:value-of select="$location" />
|
|
179
|
+
</xsl:otherwise>
|
|
180
|
+
</xsl:choose>
|
|
181
|
+
<xsl:text> </xsl:text>
|
|
182
|
+
</xsl:template>
|
|
183
|
+
|
|
184
|
+
<xsl:template match="/">
|
|
185
|
+
<xsl:apply-templates select="plist/dict/key[. = 'Playlists']" />
|
|
186
|
+
</xsl:template>
|
|
187
|
+
</xsl:stylesheet>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsl:stylesheet version="2.0"
|
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4
|
+
exclude-result-prefixes="xsl">
|
|
5
|
+
<xsl:output encoding="UTF-8" method="text" omit-xml-declaration="yes" indent="no" />
|
|
6
|
+
|
|
7
|
+
<xsl:import href="../to-json.xsl" />
|
|
8
|
+
|
|
9
|
+
<xsl:template match="/">
|
|
10
|
+
<xsl:apply-templates select="plist/dict" />
|
|
11
|
+
</xsl:template>
|
|
12
|
+
</xsl:stylesheet>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsl:stylesheet version="2.0"
|
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4
|
+
exclude-result-prefixes="xsl">
|
|
5
|
+
<xsl:output encoding="UTF-8" method="text" omit-xml-declaration="yes" indent="no" />
|
|
6
|
+
|
|
7
|
+
<xsl:import href="../../to-json.xsl" />
|
|
8
|
+
|
|
9
|
+
<xsl:template match="/">
|
|
10
|
+
<xsl:text>{</xsl:text>
|
|
11
|
+
<xsl:apply-templates select="plist/dict/key[. = 'Tracks']" />
|
|
12
|
+
<xsl:text>}</xsl:text>
|
|
13
|
+
</xsl:template>
|
|
14
|
+
</xsl:stylesheet>
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsl:stylesheet version="2.0"
|
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4
|
+
xmlns:seq="http://sequencemedia.net"
|
|
5
|
+
xmlns:url-decoder="java:java.net.URLDecoder"
|
|
6
|
+
exclude-result-prefixes="xsl seq url-decoder">
|
|
7
|
+
<xsl:output encoding="UTF-8" method="text" omit-xml-declaration="yes" indent="no" />
|
|
8
|
+
|
|
9
|
+
<xsl:param name="destination" />
|
|
10
|
+
|
|
11
|
+
<xsl:variable name="tracks" select="/plist/dict/key[. = 'Tracks']/following-sibling::dict" />
|
|
12
|
+
|
|
13
|
+
<!-- https://en.wikipedia.org/wiki/Combining_character -->
|
|
14
|
+
<xsl:function name="seq:remove-combining-characters">
|
|
15
|
+
<xsl:param name="s" />
|
|
16
|
+
|
|
17
|
+
<xsl:value-of
|
|
18
|
+
select="
|
|
19
|
+
translate(translate(translate(translate(translate(translate(translate($s,
|
|
20
|
+
'̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏', ''),
|
|
21
|
+
'̛̖̗̘̙̜̝̞̟̐̑̒̓̔̕̚', ''),
|
|
22
|
+
'̡̢̧̨̠̣̤̥̦̩̪̫̬̭̮̯', ''),
|
|
23
|
+
'̴̵̶̷̸̰̱̲̳̹̺̻̼̽̾̿', ''),
|
|
24
|
+
'͇͈͉͍͎̀́͂̓̈́͆͊͋͌ͅ͏', ''),
|
|
25
|
+
'͓͔͕͖͙͚͐͑͒͗͛͘͜͟͝͞', ''),
|
|
26
|
+
'ͣͤͥͦͧͨͩͪͫͬͭͮͯ͢͠͡', '')"
|
|
27
|
+
/>
|
|
28
|
+
</xsl:function>
|
|
29
|
+
|
|
30
|
+
<xsl:function name="seq:normalize-for-path">
|
|
31
|
+
<xsl:param name="s" />
|
|
32
|
+
|
|
33
|
+
<xsl:value-of
|
|
34
|
+
select="normalize-space(seq:remove-combining-characters(translate(replace(normalize-unicode($s, 'NFD'), '[%\[\]*?]', '_'), '\/:', '___')))"
|
|
35
|
+
/>
|
|
36
|
+
</xsl:function>
|
|
37
|
+
|
|
38
|
+
<xsl:function name="seq:get-href-for-album">
|
|
39
|
+
<xsl:param name="albumArtist" />
|
|
40
|
+
<xsl:param name="album" />
|
|
41
|
+
|
|
42
|
+
<xsl:variable name="filePath" select="seq:normalize-for-path($albumArtist)" />
|
|
43
|
+
<xsl:variable name="fileName" select="seq:normalize-for-path($album)" />
|
|
44
|
+
|
|
45
|
+
<xsl:choose>
|
|
46
|
+
<xsl:when test="$destination">
|
|
47
|
+
<xsl:value-of select="$destination" />
|
|
48
|
+
<xsl:text>/Tracks/</xsl:text>
|
|
49
|
+
</xsl:when>
|
|
50
|
+
<xsl:otherwise>
|
|
51
|
+
<xsl:text>Music Library/Tracks/</xsl:text>
|
|
52
|
+
</xsl:otherwise>
|
|
53
|
+
</xsl:choose>
|
|
54
|
+
|
|
55
|
+
<xsl:value-of select="$filePath" />
|
|
56
|
+
<xsl:text>/</xsl:text>
|
|
57
|
+
<xsl:value-of select="$fileName" />
|
|
58
|
+
<xsl:text>.m3u8</xsl:text>
|
|
59
|
+
</xsl:function>
|
|
60
|
+
|
|
61
|
+
<xsl:function name="seq:get-href-for-album">
|
|
62
|
+
<xsl:param name="album" />
|
|
63
|
+
|
|
64
|
+
<xsl:variable name="fileName" select="seq:normalize-for-path($album)" />
|
|
65
|
+
|
|
66
|
+
<xsl:choose>
|
|
67
|
+
<xsl:when test="$destination">
|
|
68
|
+
<xsl:value-of select="$destination" />
|
|
69
|
+
<xsl:text>/Tracks/Compilations/</xsl:text>
|
|
70
|
+
</xsl:when>
|
|
71
|
+
|
|
72
|
+
<xsl:otherwise>
|
|
73
|
+
<xsl:text>Music Library/Tracks/Compilations/</xsl:text>
|
|
74
|
+
</xsl:otherwise>
|
|
75
|
+
</xsl:choose>
|
|
76
|
+
|
|
77
|
+
<xsl:value-of select="$fileName" />
|
|
78
|
+
<xsl:text>.m3u8</xsl:text>
|
|
79
|
+
</xsl:function>
|
|
80
|
+
|
|
81
|
+
<xsl:template match="key[. = 'Tracks']">
|
|
82
|
+
<!-- Albums: 'Album Artist' -->
|
|
83
|
+
<xsl:for-each-group
|
|
84
|
+
group-by="key[. = 'Album Artist']/following-sibling::*[1]/text()"
|
|
85
|
+
select="following-sibling::dict[1]/dict[
|
|
86
|
+
key[. = 'Album Artist']/following-sibling::*[1]/text() and
|
|
87
|
+
key[. = 'Track Type']/following-sibling::*[1]/text() eq 'File' and
|
|
88
|
+
key[. = 'Album'] and
|
|
89
|
+
contains(lower-case(key[. = 'Kind']/following-sibling::*[1]/text()), 'audio') and
|
|
90
|
+
not(local-name(key[. = 'Podcast']/following-sibling::*[1]) eq 'true') and
|
|
91
|
+
(
|
|
92
|
+
not(key[. = 'Compilation']) or not(local-name(key[. = 'Compilation']/following-sibling::*[1]) eq 'true')
|
|
93
|
+
)
|
|
94
|
+
]">
|
|
95
|
+
<xsl:variable name="albumArtist" select="current-grouping-key()" />
|
|
96
|
+
|
|
97
|
+
<xsl:for-each-group group-by="key[. = 'Album']/following-sibling::*[1]/text()" select="current-group()">
|
|
98
|
+
<xsl:result-document href="{seq:get-href-for-album($albumArtist, current-grouping-key())}" method="text">
|
|
99
|
+
<xsl:call-template name="album">
|
|
100
|
+
<xsl:with-param name="current-group" select="current-group()" />
|
|
101
|
+
</xsl:call-template>
|
|
102
|
+
</xsl:result-document>
|
|
103
|
+
</xsl:for-each-group>
|
|
104
|
+
</xsl:for-each-group>
|
|
105
|
+
|
|
106
|
+
<!-- Albums: 'Artist' not 'Album Artist' -->
|
|
107
|
+
<xsl:for-each-group
|
|
108
|
+
group-by="key[. = 'Artist']/following-sibling::*[1]/text()"
|
|
109
|
+
select="following-sibling::dict[1]/dict[
|
|
110
|
+
(
|
|
111
|
+
not(key[. = 'Album Artist']/following-sibling::*[1]/text())
|
|
112
|
+
) and
|
|
113
|
+
key[. = 'Track Type']/following-sibling::*[1]/text() eq 'File' and
|
|
114
|
+
key[. = 'Album'] and
|
|
115
|
+
contains(lower-case(key[. = 'Kind']/following-sibling::*[1]/text()), 'audio') and
|
|
116
|
+
not(local-name(key[. = 'Podcast']/following-sibling::*[1]) eq 'true') and
|
|
117
|
+
(
|
|
118
|
+
not(key[. = 'Compilation']) or not(local-name(key[. = 'Compilation']/following-sibling::*[1]) eq 'true')
|
|
119
|
+
)
|
|
120
|
+
]">
|
|
121
|
+
<xsl:variable name="artist" select="current-grouping-key()" />
|
|
122
|
+
|
|
123
|
+
<xsl:for-each-group group-by="key[. = 'Album']/following-sibling::*[1]/text()" select="current-group()">
|
|
124
|
+
<xsl:result-document href="{seq:get-href-for-album($artist, current-grouping-key())}" method="text">
|
|
125
|
+
<xsl:call-template name="album">
|
|
126
|
+
<xsl:with-param name="current-group" select="current-group()" />
|
|
127
|
+
</xsl:call-template>
|
|
128
|
+
</xsl:result-document>
|
|
129
|
+
</xsl:for-each-group>
|
|
130
|
+
</xsl:for-each-group>
|
|
131
|
+
|
|
132
|
+
<!-- Compilation albums -->
|
|
133
|
+
<xsl:for-each-group
|
|
134
|
+
group-by="key[. = 'Album']/following-sibling::*[1]/text()"
|
|
135
|
+
select="following-sibling::dict[1]/dict[
|
|
136
|
+
key[. = 'Track Type']/following-sibling::*[1]/text() eq 'File' and
|
|
137
|
+
key[. = 'Album'] and
|
|
138
|
+
contains(lower-case(key[. = 'Kind']/following-sibling::*[1]/text()), 'audio') and
|
|
139
|
+
not(local-name(key[. = 'Podcast']/following-sibling::*[1]) eq 'true') and
|
|
140
|
+
(
|
|
141
|
+
key[. = 'Compilation'] and local-name(key[. = 'Compilation']/following-sibling::*[1]) eq 'true'
|
|
142
|
+
)
|
|
143
|
+
]">
|
|
144
|
+
<xsl:result-document href="{seq:get-href-for-album(current-grouping-key())}" method="text">
|
|
145
|
+
<xsl:call-template name="album">
|
|
146
|
+
<xsl:with-param name="current-group" select="current-group()" />
|
|
147
|
+
</xsl:call-template>
|
|
148
|
+
</xsl:result-document>
|
|
149
|
+
</xsl:for-each-group>
|
|
150
|
+
</xsl:template>
|
|
151
|
+
|
|
152
|
+
<!-- Album: #EXTM3U -->
|
|
153
|
+
<xsl:template name="album">
|
|
154
|
+
<xsl:param name="current-group" />
|
|
155
|
+
|
|
156
|
+
<xsl:text>#EXTM3U</xsl:text>
|
|
157
|
+
<xsl:text> </xsl:text>
|
|
158
|
+
|
|
159
|
+
<xsl:for-each select="$current-group">
|
|
160
|
+
<xsl:sort select="number(key[. = 'Disc Number']/following-sibling::*[1]/text())" />
|
|
161
|
+
<xsl:sort select="number(key[. = 'Track Number']/following-sibling::*[1]/text())" />
|
|
162
|
+
|
|
163
|
+
<xsl:apply-templates mode="album-track" select="." />
|
|
164
|
+
</xsl:for-each>
|
|
165
|
+
</xsl:template>
|
|
166
|
+
|
|
167
|
+
<!-- Album track: #EXTINF -->
|
|
168
|
+
<xsl:template mode="album-track" match="dict">
|
|
169
|
+
<xsl:variable name="totalTime" select="floor(number(key[. = 'Total Time']/following-sibling::*[1]/text()) div 1000)" />
|
|
170
|
+
<xsl:variable name="location" select="url-decoder:decode(replace(key[. = 'Location']/following-sibling::*[1]/text(), '[+]', '%2b'))" />
|
|
171
|
+
|
|
172
|
+
<xsl:text>#EXTINF:</xsl:text>
|
|
173
|
+
<xsl:choose>
|
|
174
|
+
<xsl:when test="number($totalTime)">
|
|
175
|
+
<xsl:value-of select="$totalTime" />
|
|
176
|
+
</xsl:when>
|
|
177
|
+
<xsl:otherwise>
|
|
178
|
+
<xsl:text>-1</xsl:text>
|
|
179
|
+
</xsl:otherwise>
|
|
180
|
+
</xsl:choose>
|
|
181
|
+
<xsl:text>,</xsl:text>
|
|
182
|
+
<xsl:value-of select="normalize-space(key[. = 'Name']/following-sibling::*[1]/text())" />
|
|
183
|
+
<xsl:text> - </xsl:text>
|
|
184
|
+
<xsl:value-of select="normalize-space(key[. = 'Artist']/following-sibling::*[1]/text())" />
|
|
185
|
+
<xsl:text> </xsl:text>
|
|
186
|
+
|
|
187
|
+
<xsl:choose>
|
|
188
|
+
<xsl:when test="starts-with($location, 'file://')">
|
|
189
|
+
<xsl:value-of select="substring($location, 8)" />
|
|
190
|
+
</xsl:when>
|
|
191
|
+
<xsl:otherwise>
|
|
192
|
+
<xsl:value-of select="$location" />
|
|
193
|
+
</xsl:otherwise>
|
|
194
|
+
</xsl:choose>
|
|
195
|
+
<xsl:text> </xsl:text>
|
|
196
|
+
</xsl:template>
|
|
197
|
+
|
|
198
|
+
<xsl:template match="/">
|
|
199
|
+
<xsl:apply-templates select="plist/dict/key[. = 'Tracks']" />
|
|
200
|
+
</xsl:template>
|
|
201
|
+
</xsl:stylesheet>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<xsl:stylesheet version="2.0"
|
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4
|
+
exclude-result-prefixes="xsl">
|
|
5
|
+
<xsl:output encoding="UTF-8" method="text" omit-xml-declaration="yes" indent="no" />
|
|
6
|
+
|
|
7
|
+
<xsl:import href="library/tracks.xsl" />
|
|
8
|
+
<xsl:import href="library/playlists.xsl" />
|
|
9
|
+
|
|
10
|
+
<xsl:template match="/">
|
|
11
|
+
<xsl:apply-templates select="plist/dict/key[. = 'Tracks']" />
|
|
12
|
+
|
|
13
|
+
<xsl:apply-templates select="plist/dict/key[. = 'Playlists']" />
|
|
14
|
+
</xsl:template>
|
|
15
|
+
</xsl:stylesheet>
|