1
0
flewkey.com/scripts/gen_music.py

33 lines
926 B
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import json
from template import template
def gen_list(music, ext, limit=-1, mini=False):
items = ""
i = 0
for track in music:
track["template"] = "track_preview" if not mini else "track_preview_mini"
track["file_size"] = str(os.path.getsize("music/"+track["id"]+".mp3"))
if "group" in track:
track["group_text"] = "<span>Part of "+track["group"]+"</span><br/>"
items += template("", sys.argv[2], ext, track)
i += 1
if limit >= 0 and i >= limit:
break;
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()