Browse Source

POC commit.

master
Jérôme 5 years ago
parent
commit
8bd2bf9e68
13 changed files with 323 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. BIN
      assets/fonts/noto-sans/NotoSans-Bold.ttf
  3. BIN
      assets/fonts/noto-sans/NotoSans-BoldItalic.ttf
  4. BIN
      assets/fonts/noto-sans/NotoSans-Italic.ttf
  5. BIN
      assets/fonts/noto-sans/NotoSans-Regular.ttf
  6. +43
    -0
      assets/fonts/noto-sans/SIL Open Font License.txt
  7. +124
    -0
      assets/labelize.css
  8. +60
    -0
      assets/labelize.js
  9. BIN
      assets/labelize.png
  10. BIN
      assets/pause.png
  11. BIN
      assets/play.png
  12. +91
    -0
      labelize.py
  13. +4
    -0
      requirements.txt

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
venv

BIN
assets/fonts/noto-sans/NotoSans-Bold.ttf View File


BIN
assets/fonts/noto-sans/NotoSans-BoldItalic.ttf View File


BIN
assets/fonts/noto-sans/NotoSans-Italic.ttf View File


BIN
assets/fonts/noto-sans/NotoSans-Regular.ttf View File


+ 43
- 0
assets/fonts/noto-sans/SIL Open Font License.txt View File

@@ -0,0 +1,43 @@
Copyright 2012 Google Inc. All Rights Reserved.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).

"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.

5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

+ 124
- 0
assets/labelize.css View File

@@ -0,0 +1,124 @@
@font-face {
font-family: "NotoSans";
src: url(./fonts/noto-sans/NotoSans-Regular.ttf);
}

:root {
--main-bg-color: rgba(255,255,255,0.7);
}

*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
html{
font-family: NotoSans;
color: black;
}
html, body{
width: 100vw;
height: 100vh;
background-color: black;
}

body{
display: flex;
align-items: center;
justify-content: center;
}

.track-list{
width: 100vh;
height: 100vh;
background-image: url(../cover.jpg);
background-size: cover;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

ul.invisible{
display: none;
}

ul{
position: fixed;
right:0px;
top:0px;
padding-top: 30px;
list-style-type: none;
background-color: var(--main-bg-color);
height: 100vh;
font-size: 0.75rem;
}

div#player-toggler{
position: fixed;
top: 0px;
right:0px;
margin-top:2px;
margin-right: 2px;
z-index: 10;
cursor: pointer;
}

li{
/*background-color: var(--main-bg-color);*/
padding: 2px;
}
li{
margin-top:2px;
display: flex;
justify-content: center;
align-items: center;
}

button{
background-color: rgba(0,0,0,0);
border: none;
margin-left: 5px;
cursor: pointer;
}

div#player-toggler > img{
width: 24px;
height: 24px;
}
button img{
width: 16px;
height: 16px;
}

progress::-moz-progress-bar {
background-color: black !important;
}
#player-progress{
position: fixed;
left:0;
top:0;
height: 1vw;
width: 100vh;
background-color: var(--main-bg-color);
border: none;
border-top:2px solid var(--main-bg-color);
border-bottom:2px solid var(--main-bg-color);
cursor: pointer;
transform: rotate(90deg);
transform-origin: top left;
margin-left: 1vw;
/* margin-top:calc(50vh - 0.5vw);
margin-left:0; */
}

#time-info{
visibility: hidden;
position: fixed;
bottom: 2px;
left: 1%;
padding-left: 2px;
color:white;
font-size: 0.6rem;
}

+ 60
- 0
assets/labelize.js View File

@@ -0,0 +1,60 @@
var current = undefined
const progressMargin = 50;
var progress = undefined;
window.addEventListener('DOMContentLoaded', (event) => {
progress = document.getElementById('player-progress');
document.getElementById('player-progress').addEventListener('click', (e) => {
if(current){
let media = current.getElementsByTagName('audio')[0];
media.currentTime = e.layerX * media.duration / progress.offsetWidth;

}
});

let toggler = document.getElementById('player-toggler');
toggler.setAttribute('title','afficher/masquer la liste des morceaux');
toggler.addEventListener('click', (e) => {
document.getElementsByTagName('ul')[0].classList.toggle('invisible');
})
});


function togglePlay(src) {
let media = src.getElementsByTagName('audio')[0];
let icon = src.getElementsByTagName('img')[0];
if (current){//stops current media and reset its play icon
pause();
}
if(current != src){
//sets current media icon and plays media
icon.setAttribute('src','assets/pause.png');
media.play();
progress.max = Math.floor(media.duration);
current = src;
document.getElementById('time-info').style.visibility = 'visible';
}
else{
current = undefined;
}
}

function pause(){
current.getElementsByTagName('audio')[0].pause();
current.getElementsByTagName('img')[0].setAttribute('src','assets/play.png');
document.getElementById('time-info').style.visibility = 'hidden';
}

function updateProgress(media){
progress.value = Math.floor(media.currentTime);
document.getElementById('time-info').innerHTML =
prettyDuration(media.currentTime) + ' / ' + prettyDuration(media.duration);
}

function prettyDuration(duration) {
let sec = Math.floor( duration );
let min = Math.floor( sec / 60 );
min = min >= 10 ? min : '0' + min;
sec = Math.floor( sec % 60 );
sec = sec >= 10 ? sec : '0' + sec;
return min + ':' + sec;
}

BIN
assets/labelize.png View File

Before After
Width: 240  |  Height: 240  |  Size: 4.4 KiB

BIN
assets/pause.png View File

Before After
Width: 640  |  Height: 640  |  Size: 17 KiB

BIN
assets/play.png View File

Before After
Width: 640  |  Height: 640  |  Size: 19 KiB

+ 91
- 0
labelize.py View File

@@ -0,0 +1,91 @@

import eyed3
import os
import sys
import shutil
from html_writer import Html

#TracksDir class definition
class TracksDir:
def __init__(self, trackFiles):
self.trackFiles = trackFiles

#HTML Output
def toHTML(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()
trackNumber = 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:
trackNumber = trackNumber + 1
trackId = 'track-' + str(trackNumber)
audiofile = eyed3.load("build/" + t)
with body.tag('li') as li:
print(audiofile.tag.title)
li += str(audiofile.tag.title or 'untitled')+ ' - '
li += str(audiofile.tag.album or 'untitled')+ ' - '
li += audiofile.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=trackId,
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)

inputDirectory = sys.argv[1]
outputDirectory = sys.argv[2]

def copyDirectory(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(outputDirectory):
shutil.rmtree(outputDirectory)

#copies source files in the build directory
copyDirectory(inputDirectory, 'build')

#copies assets in the build directory
copyDirectory('assets', outputDirectory + '/assets')

for root, dirs, files in os.walk(inputDirectory):
trackFiles = []
for f in files:
if f.lower().endswith(('.mp3', '.wav', '.ogg')):
trackFiles.append(f)

td = TracksDir(trackFiles)
f = open(outputDirectory + "/index.html","w+")
f.write(td.toHTML())
f.close()

+ 4
- 0
requirements.txt View File

@@ -0,0 +1,4 @@
eyeD3==0.8.10
html-writer==1.1.1
python-magic==0.4.15
six==1.12.0

Loading…
Cancel
Save