|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import eyed3
- import os
- import sys
- import shutil
- from html_writer import Html
-
-
- # TracksDir class definition
- class TracksDir:
- def __init__(self, track_files):
- self.trackFiles = track_files
-
- # HTML Output
- def to_html(self):
- head = Html()
- head.self_close_tag('meta', attributes=dict(charset='utf-8'))
- head.self_close_tag('link', attributes=dict(href='assets/labelize.css', rel='stylesheet'))
- body = Html()
- track_number = 0
- with body.tag('div', classes=['track-list']):
- # body.tag_with_content('Track List', name='h2')
- with body.tag('div', attributes=dict(id='player-toggler')):
- body.self_close_tag('img', attributes=dict(src='assets/labelize.png'))
- with body.tag('ul') as list:
- for t in self.trackFiles:
- track_number = track_number + 1
- track_id = 'track-' + str(track_number)
- audio_file = eyed3.load("build/" + t)
- with body.tag('li') as li:
- print(audio_file.tag.title)
- li += str(audio_file.tag.title or 'untitled') + ' - '
- li += str(audio_file.tag.album or 'untitled') + ' - '
- li += audio_file.tag.artist
- with body.tag('button', attributes=dict(onclick="togglePlay(this)")):
- body.self_close_tag('img', attributes=dict(src='assets/play.png'))
- with body.tag('audio', attributes=dict(src=t, id=track_id,
- ontimeupdate="updateProgress(this)")) as audio:
- audio += "Your browser does not support the audio element"
-
- # with body.tag('canvas',attributes=dict(id='player-progress')) as canvas:
- # canvas += "player's progress bar"
- with body.tag('progress', attributes=dict(id='player-progress', value='0')) as canvas:
- canvas += "player's progress bar"
- with body.tag('div', attributes=dict(id='time-info')) as timeInfo:
- timeInfo += '00:00'
- with body.tag('script', attributes=dict(src='assets/labelize.js')) as script:
- script += "" # script tag is not added without that trick
-
- return Html.html_template(head, body).to_raw_html(indent_size=2)
-
-
- # script usage function
- def usage():
- print('USAGE : labelize.py [inputDirectory] [outputDirectory]')
-
-
- # script beginning
- arguments = len(sys.argv) - 1
- if arguments != 2:
- usage()
- sys.exit(2)
-
- input_directory = sys.argv[1]
- output_directory = sys.argv[2]
-
-
- def copy_directory(src, dest):
- try:
- shutil.copytree(src, dest)
- except shutil.Error as e:
- print('Directory not copied. Error: %s' % e)
- except OSError as e:
- print('Directory not copied. Error: %s' % e)
-
-
- # removes existing build directory if exists
- if os.path.isdir(output_directory):
- shutil.rmtree(output_directory)
-
- # copies source files in the build directory
- copy_directory(input_directory, 'build')
-
- # copies assets in the build directory
- copy_directory('assets', output_directory + '/assets')
-
- for root, dirs, files in os.walk(input_directory):
- trackFiles = []
- for f in files:
- if f.lower().endswith(('.mp3', '.wav', '.ogg')):
- trackFiles.append(f)
-
- td = TracksDir(trackFiles)
- f = open(output_directory + "/index.html", "w+")
- f.write(td.to_html())
- f.close()
|