Skip to content
Snippets Groups Projects
Verified Commit 4b4ebf03 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Add final functionality (bugfixes from now on really)

parent a7e03c6a
Branches master
No related tags found
No related merge requests found
import argparse import argparse
import json import json
import os import os
import shutil
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Rebuilds an m3u playlist.' description='Rebuilds an m3u playlist.'
...@@ -57,5 +58,27 @@ playlist_lines = [line for line in playlist_lines if line and not line.startswit ...@@ -57,5 +58,27 @@ playlist_lines = [line for line in playlist_lines if line and not line.startswit
# Read the patches file, and store as json object # Read the patches file, and store as json object
with args.patches as f: with args.patches as f:
patches = json.load(f) patches = json.load(f)
patches_map = { patch['source']: patch['target'] for patch in patches }
# Output playlist
output_playlist = []
# Apply the patches to the playlist # Apply the patches to the playlist
for line in playlist_lines:
if line in patches_map:
if not os.path.exists(os.path.join(playlist_dir, patches_map[line])):
print("WARNING: File not found: " + patches_map[line])
line = patches_map[line]
else:
# Copy the file to the output directory
file_path = str(os.path.join(playlist_dir, line.strip()))
new_path = str(os.path.join(str(output_files_dir), os.path.basename(file_path)))
os.makedirs(os.path.dirname(new_path), exist_ok=True)
shutil.copy(file_path, new_path)
line = os.path.join(args.output_dir, os.path.basename(file_path))
# Write the output playlist
with args.output_playlist as f:
f.writelines(output_playlist)
print("Rebuilt playlist written to " + args.output_playlist.name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment