Skip to content

Commit 92d191e

Browse files
authored
Ensure playlist starts #EXTM3U
1 parent 8454d4f commit 92d191e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

weedplaylist.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/python3
2+
# Takes a playlist file, and a file with a list of files,
3+
# moves the files in the list of files from the file location into a holding directory
4+
# and cuts the playlist entry corresponding to that file, placing it into a new file.
5+
6+
import checkplaylist
7+
import argparse
8+
import json
9+
10+
parser = argparse.ArgumentParser(description='Removes files in a list of files from a liquidsoap m3u8 playlist,\n '
11+
'then moves them into a new subdirectory,\n '
12+
'then saves both a modified version of the given playlist having had \n'
13+
'the missing files cut out, and saves a new playlist with the missing files.')
14+
parser.add_argument('inputfile', default=None, help='Filename of full m3u8 playlist to be weeded.')
15+
parser.add_argument('filelist', default=None, help='Text file with list of files to be removed and optionally moved.')
16+
parser.add_argument('--move', '-m', default=None, help='Actually move the file, instead of leaving them.')
17+
18+
args = parser.parse_args()
19+
20+
INPUTPLAYLIST = args.inputfile
21+
FILESTOWEED = args.filelist
22+
WEEDEDPLAYLIST = INPUTPLAYLIST + "_weeded.m3u8"
23+
WEEDSPLAYLIST = INPUTPLAYLIST + "_weedsonly.m3u8"
24+
25+
# Need to make a list of all files that need to be weeded
26+
27+
with open(FILESTOWEED, 'r', encoding='utf-8') as fp:
28+
fileslist = [line.rstrip() for line in fp]
29+
30+
weededtuple = checkplaylist.weedplaylist(INPUTPLAYLIST, fileslist)
31+
# Return is a tuple: (m3u8 of removed files, m3u8 of files remaining)
32+
33+
#print("REMOVED FILES:")
34+
#print("\n".join(weededtuple[0]))
35+
#print("RETURNED WEEDED PLAYLIST:")
36+
#print(weededtuple[1].values())
37+
38+
with open(WEEDEDPLAYLIST, mode='w', encoding='utf-8') as wp:
39+
wp.write('#EXTM3U\n')
40+
wp.write('\n'.join(weededtuple[1]))
41+
42+
with open(WEEDSPLAYLIST, mode='w', encoding='utf=8') as wp:
43+
wp.write('#EXTM3U\n')
44+
wp.write('\n'.join(weededtuple[0]))
45+
46+
print("Weeded playlist is %s" % WEEDEDPLAYLIST)
47+
print("Playlist of weeds is %s" % WEEDSPLAYLIST)
48+
49+
50+

0 commit comments

Comments
 (0)