Music album web page generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

96 line
3.4 KiB

  1. import eyed3
  2. import os
  3. import sys
  4. import shutil
  5. from html_writer import Html
  6. # TracksDir class definition
  7. class TracksDir:
  8. def __init__(self, track_files):
  9. self.trackFiles = track_files
  10. # HTML Output
  11. def to_html(self):
  12. head = Html()
  13. head.self_close_tag('meta', attributes=dict(charset='utf-8'))
  14. head.self_close_tag('link', attributes=dict(href='assets/labelize.css', rel='stylesheet'))
  15. body = Html()
  16. track_number = 0
  17. with body.tag('div', classes=['track-list']):
  18. # body.tag_with_content('Track List', name='h2')
  19. with body.tag('div', attributes=dict(id='player-toggler')):
  20. body.self_close_tag('img', attributes=dict(src='assets/labelize.png'))
  21. with body.tag('ul') as list:
  22. for t in self.trackFiles:
  23. track_number = track_number + 1
  24. track_id = 'track-' + str(track_number)
  25. audio_file = eyed3.load("build/" + t)
  26. with body.tag('li') as li:
  27. print(audio_file.tag.title)
  28. li += str(audio_file.tag.title or 'untitled') + ' - '
  29. li += str(audio_file.tag.album or 'untitled') + ' - '
  30. li += audio_file.tag.artist
  31. with body.tag('button', attributes=dict(onclick="togglePlay(this)")):
  32. body.self_close_tag('img', attributes=dict(src='assets/play.png'))
  33. with body.tag('audio', attributes=dict(src=t, id=track_id,
  34. ontimeupdate="updateProgress(this)")) as audio:
  35. audio += "Your browser does not support the audio element"
  36. # with body.tag('canvas',attributes=dict(id='player-progress')) as canvas:
  37. # canvas += "player's progress bar"
  38. with body.tag('progress', attributes=dict(id='player-progress', value='0')) as canvas:
  39. canvas += "player's progress bar"
  40. with body.tag('div', attributes=dict(id='time-info')) as timeInfo:
  41. timeInfo += '00:00'
  42. with body.tag('script', attributes=dict(src='assets/labelize.js')) as script:
  43. script += "" # script tag is not added without that trick
  44. return Html.html_template(head, body).to_raw_html(indent_size=2)
  45. # script usage function
  46. def usage():
  47. print('USAGE : labelize.py [inputDirectory] [outputDirectory]')
  48. # script beginning
  49. arguments = len(sys.argv) - 1
  50. if arguments != 2:
  51. usage()
  52. sys.exit(2)
  53. input_directory = sys.argv[1]
  54. output_directory = sys.argv[2]
  55. def copy_directory(src, dest):
  56. try:
  57. shutil.copytree(src, dest)
  58. except shutil.Error as e:
  59. print('Directory not copied. Error: %s' % e)
  60. except OSError as e:
  61. print('Directory not copied. Error: %s' % e)
  62. # removes existing build directory if exists
  63. if os.path.isdir(output_directory):
  64. shutil.rmtree(output_directory)
  65. # copies source files in the build directory
  66. copy_directory(input_directory, 'build')
  67. # copies assets in the build directory
  68. copy_directory('assets', output_directory + '/assets')
  69. for root, dirs, files in os.walk(input_directory):
  70. trackFiles = []
  71. for f in files:
  72. if f.lower().endswith(('.mp3', '.wav', '.ogg')):
  73. trackFiles.append(f)
  74. td = TracksDir(trackFiles)
  75. f = open(output_directory + "/index.html", "w+")
  76. f.write(td.to_html())
  77. f.close()