Music album web page generator
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

92 lignes
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, trackFiles):
  9. self.trackFiles = trackFiles
  10. #HTML Output
  11. def toHTML(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. trackNumber = 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. trackNumber = trackNumber + 1
  24. trackId = 'track-' + str(trackNumber)
  25. audiofile = eyed3.load("build/" + t)
  26. with body.tag('li') as li:
  27. print(audiofile.tag.title)
  28. li += str(audiofile.tag.title or 'untitled')+ ' - '
  29. li += str(audiofile.tag.album or 'untitled')+ ' - '
  30. li += audiofile.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=trackId,
  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. inputDirectory = sys.argv[1]
  54. outputDirectory = sys.argv[2]
  55. def copyDirectory(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(outputDirectory):
  64. shutil.rmtree(outputDirectory)
  65. #copies source files in the build directory
  66. copyDirectory(inputDirectory, 'build')
  67. #copies assets in the build directory
  68. copyDirectory('assets', outputDirectory + '/assets')
  69. for root, dirs, files in os.walk(inputDirectory):
  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(outputDirectory + "/index.html","w+")
  76. f.write(td.toHTML())
  77. f.close()