forked from Warblefly/TrackBoundaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertplaylist.py
53 lines (37 loc) · 1.73 KB
/
convertplaylist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
import os, ntpath, sys, pathlib, argparse
def convertfile(infile, mount):
# Takes the DOS input filename including drive, and converts to Posix-style
# together with the mount point added in place of the drive letter.
# Tell the system what kind of path this is
rawFile = pathlib.PureWindowsPath(infile)
# Convert it to Python's Posix-style representation of a DOS pathname
fileName=pathlib.PurePath.as_posix(rawFile)
# Remove the drive letter, intelligently combine what's left with the mount point
# print("Mount point is: %s" % mount)
pathName=os.path.normpath(mount + '/' + ntpath.splitdrive(fileName)[1])
return(pathName)
parser = argparse.ArgumentParser(description='Convert DOS/Windows playlist into Posix playlist.')
parser.add_argument('-i', '--infile', required=True, type=str, help='Filename of DOS/Windows playlist')
parser.add_argument('-o', '--outfile', required=True, type=str, help='Filename of output Posix-style playlist')
parser.add_argument('-r', '--root', required=True, type=str, help='Mount point of DOS/Windows drive letter')
args = parser.parse_args()
print(args)
infile = args.infile
outfile = args.outfile
root = args.root
headerWritten = False
with open(outfile, mode="w", encoding='utf-8') as outfp:
with open(infile, encoding='utf-8-sig') as fp:
for line in fp:
intrack = line.strip()
# print(intrack)
if intrack[0] != "#":
realtrack = convertfile(intrack, root)
outfp.write(realtrack + '\n')
else:
if headerWritten == False:
outfp.write("#EXTM3U\n")
headerWritten = True
else:
pass