Music album web page generator
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

81 行
2.0 KiB

  1. import eyed3
  2. import os
  3. import sys
  4. import shutil
  5. import yaml
  6. from mako.template import Template
  7. # TracksDir class definition
  8. class Album:
  9. def __init__(self, track_files):
  10. self.trackFiles = track_files
  11. # script usage function
  12. def usage():
  13. print('USAGE : labelize.py [inputDirectory] [outputDirectory]')
  14. # script beginning
  15. arguments = len(sys.argv) - 1
  16. if arguments != 2:
  17. usage()
  18. sys.exit(2)
  19. input_directory = sys.argv[1]
  20. output_directory = sys.argv[2]
  21. def copy_directory(src, dest):
  22. try:
  23. shutil.copytree(src, dest)
  24. except shutil.Error as e:
  25. print('Directory not copied. Error: %s' % e)
  26. except OSError as e:
  27. print('Directory not copied. Error: %s' % e)
  28. # removes existing build directory if exists
  29. if os.path.isdir(output_directory):
  30. shutil.rmtree(output_directory)
  31. #
  32. # copies source files in the build directory
  33. copy_directory(input_directory, output_directory + '/audio')
  34. # copies assets in the build directory
  35. copy_directory('assets', output_directory + '/assets')
  36. with open('labelize.yaml') as f:
  37. data = yaml.load(f, Loader=yaml.FullLoader)
  38. title = data['band']
  39. cover_img = data['images']['cover']
  40. contact_img = data['images']['contact']
  41. shutil.copyfile(input_directory + '/' + cover_img, output_directory + '/assets/images/cover.png');
  42. shutil.copyfile(input_directory + '/' + contact_img, output_directory + '/assets/images/contact.png');
  43. track_files = []
  44. for root, dirs, files in os.walk(input_directory):
  45. for f in sorted(files):
  46. if f.lower().endswith(('.mp3', '.wav', '.ogg')):
  47. track_files.append(f)
  48. print(f)
  49. # td = TracksDir(trackFiles)
  50. # f = open(output_directory + "/index.html", "w+")
  51. # f.write(td.to_html())
  52. # f.close()
  53. my_template = Template(filename='template.html')
  54. f = open(output_directory + "/index.html", "w+")
  55. # Write template data to the file created
  56. f.write(my_template.render(
  57. title=title,
  58. tracks=track_files,
  59. albums_section=data['albums_section']))
  60. # Close file
  61. f.close()