#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import json
from template import template
def gen_list(music, ext):
items = ""
for track in music:
track["template"] = "track_preview"
track["file_size"] = str(os.path.getsize("music/"+track["id"]+".mp3"))
if "group" in track:
track["group_text"] = "Part of "+track["group"]+"
"
items += template("", sys.argv[2], ext, track)
return items
def main():
meta = {"template": "music_list"}
ext = "."+sys.argv[2].split(".")[-1]
with open(sys.argv[1], "r", encoding="utf-8") as file_in:
music = json.loads(file_in.read())
output = template(gen_list(music, ext), sys.argv[2], ext, meta)
with open(sys.argv[2], "w+", encoding="utf-8") as file_out:
file_out.write(output)
if __name__ == "__main__":
main()