Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added basic header/footer system with imports for JavaScript librarie…

…s. Added validator for import utility and appropriate styling.
  • Loading branch information...
commit 43d8ff13efc1d4e3c8caa356e952da441ada59ab 1 parent 71941d4
@jbillo authored
View
19 musik/library/importer.py
@@ -37,7 +37,12 @@ def run(self):
while self.running:
# find the first unprocessed import task
- task = self.sa_session.query(ImportTask).filter(ImportTask.started == None).order_by(ImportTask.created).first()
+ try:
+ task = self.sa_session.query(ImportTask).filter(ImportTask.started == None).order_by(ImportTask.created).first()
+ except ex as OperationalError:
+ # Ran into this when my SQLite database was locked.
+ self.log.error(u'Operational error accessing database. Ensure it is not open by another process.')
+ break
if task != None:
# start processing it
task.started = datetime.utcnow()
@@ -113,11 +118,13 @@ def importFile(self, uri):
self.log.info(u'ImportFile called with uri %s', uri)
mtype = mimetypes.guess_type(uri)[0]
- if mtype == u'audio/mpeg':
- pass
- else:
+ if mtype != u'audio/mpeg':
self.log.info(u'Unsupported mime type %s. Ignoring file.', mtype)
+ # Try to read the metadata appropriately.
+ metadata = self.readMp3MetaData(uri)
+ print metadata
+
def readMp3MetaData(self, uri):
# TODO: check that the uri doesn't already exist
@@ -152,6 +159,8 @@ def readMp3MetaData(self, uri):
track.album = self.findAlbum(metadata['album'], metadata['albumsort'], metadata['musicbrainz_albumid'], metadata)
if track.album != None:
disc = self.findDisc(track.album, metadata['discnumber'], metadata['discsubtitle'], metadata['musicbrainz_discid'])
+
+ return track
def findArtist(name=None, name_sort=None, musicbrainz_id=None):
@@ -375,4 +384,4 @@ def findDisc(album=None, discnumber=None, discsubtitle=None, musicbrainz_id=None
def stop(self):
"""Cleans up the thread"""
self.log.info(u'%s.stop has been called', self.getName())
- self.running = False
+ self.running = False
View
37 musik/web/application.py
@@ -18,7 +18,7 @@
# A plugin to help SQLAlchemy bind correctly to CherryPy threads
- # See http://www.defuze.org/archives/222-integrating-sqlalchemy-into-a-cherrypy-application.html
+# See http://www.defuze.org/archives/222-integrating-sqlalchemy-into-a-cherrypy-application.html
class SAEnginePlugin(plugins.SimplePlugin):
def __init__(self, bus):
plugins.SimplePlugin.__init__(self, bus)
@@ -65,14 +65,45 @@ def commit_transaction(self):
# defines the web application that is the default client
class Musik:
api = api.API()
+
+ def _header(self, **kwargs):
+ return templates.get_template('header.html').render(**kwargs)
+
+ def _footer(self, **kwargs):
+ return templates.get_template('footer.html').render(**kwargs)
+
+ def _render(self, template_name, **kwargs):
+ return templates.get_template(template_name).render(**kwargs)
+
+ # Render an entire page with the passed variables
+ def _render_page(self, template_names, **kwargs):
+ result = []
+
+ if type(template_names) != list:
+ # Create one-element list
+ template_names = [template_names]
+
+ result.append(self._header(**kwargs))
+
+ for template in template_names:
+ result.append(self._render(template, **kwargs))
+
+ result.append(self._footer(**kwargs))
+ return result
+
@cherrypy.expose
def index(self):
- return templates.get_template('index.html').render()
+ return self._render_page("index.html", **{
+ "title": "Home"
+ })
@cherrypy.expose
def importmedia(self):
- return templates.get_template('importmedia.html').render()
+ return self._render_page("importmedia.html", **{
+ "title": "Import Media",
+ "js_appends": ['importmedia/validator.js'],
+ })
# starts the web app. this call will block until the server goes down
View
18 static/js/importmedia/validator.js
@@ -0,0 +1,18 @@
+$(document).ready(function() {
+ $('.validate-error').hide();
+});
+
+$('#importmedia-form').submit(function() {
+ $('.validate-error').html('');
+ $('.validate-error').hide();
+
+ // Validate path
+ if ($('#path').val() == '') {
+ $('#validate-error-top').html("Please provide a valid path to continue.");
+ $('.validate-error').show();
+ $('#path').focus();
+ return false;
+ }
+
+ return true;
+});
View
343 static/styles/960gs.css
@@ -0,0 +1,343 @@
+/*
+ Variable Grid System (Fluid Version).
+ Learn more ~ http://www.spry-soft.com/grids/
+ Based on 960 Grid System - http://960.gs/ & 960 Fluid - http://www.designinfluences.com/
+
+ Licensed under GPL and MIT.
+*/
+
+
+/* Containers
+----------------------------------------------------------------------------------------------------*/
+.container_12 {
+ width: 92%;
+ margin-left: 4%;
+ margin-right: 4%;
+}
+
+/* Grid >> Global
+----------------------------------------------------------------------------------------------------*/
+
+.grid_1,
+.grid_2,
+.grid_3,
+.grid_4,
+.grid_5,
+.grid_6,
+.grid_7,
+.grid_8,
+.grid_9,
+.grid_10,
+.grid_11,
+.grid_12 {
+ display:inline;
+ float: left;
+ position: relative;
+ margin-left: 1%;
+ margin-right: 1%;
+}
+
+/* Grid >> Children (Alpha ~ First, Omega ~ Last)
+----------------------------------------------------------------------------------------------------*/
+
+.alpha {
+ margin-left: 0;
+}
+
+.omega {
+ margin-right: 0;
+}
+
+/* Grid >> 12 Columns
+----------------------------------------------------------------------------------------------------*/
+
+
+.container_12 .grid_1 {
+ width:6.333%;
+}
+
+.container_12 .grid_2 {
+ width:14.667%;
+}
+
+.container_12 .grid_3 {
+ width:23.0%;
+}
+
+.container_12 .grid_4 {
+ width:31.333%;
+}
+
+.container_12 .grid_5 {
+ width:39.667%;
+}
+
+.container_12 .grid_6 {
+ width:48.0%;
+}
+
+.container_12 .grid_7 {
+ width:56.333%;
+}
+
+.container_12 .grid_8 {
+ width:64.667%;
+}
+
+.container_12 .grid_9 {
+ width:73.0%;
+}
+
+.container_12 .grid_10 {
+ width:81.333%;
+}
+
+.container_12 .grid_11 {
+ width:89.667%;
+}
+
+.container_12 .grid_12 {
+ width:98.0%;
+}
+
+
+
+/* Prefix Extra Space >> 12 Columns
+----------------------------------------------------------------------------------------------------*/
+
+
+.container_12 .prefix_1 {
+ padding-left:8.333%;
+}
+
+.container_12 .prefix_2 {
+ padding-left:16.667%;
+}
+
+.container_12 .prefix_3 {
+ padding-left:25.0%;
+}
+
+.container_12 .prefix_4 {
+ padding-left:33.333%;
+}
+
+.container_12 .prefix_5 {
+ padding-left:41.667%;
+}
+
+.container_12 .prefix_6 {
+ padding-left:50.0%;
+}
+
+.container_12 .prefix_7 {
+ padding-left:58.333%;
+}
+
+.container_12 .prefix_8 {
+ padding-left:66.667%;
+}
+
+.container_12 .prefix_9 {
+ padding-left:75.0%;
+}
+
+.container_12 .prefix_10 {
+ padding-left:83.333%;
+}
+
+.container_12 .prefix_11 {
+ padding-left:91.667%;
+}
+
+
+
+/* Suffix Extra Space >> 12 Columns
+----------------------------------------------------------------------------------------------------*/
+
+
+.container_12 .suffix_1 {
+ padding-right:8.333%;
+}
+
+.container_12 .suffix_2 {
+ padding-right:16.667%;
+}
+
+.container_12 .suffix_3 {
+ padding-right:25.0%;
+}
+
+.container_12 .suffix_4 {
+ padding-right:33.333%;
+}
+
+.container_12 .suffix_5 {
+ padding-right:41.667%;
+}
+
+.container_12 .suffix_6 {
+ padding-right:50.0%;
+}
+
+.container_12 .suffix_7 {
+ padding-right:58.333%;
+}
+
+.container_12 .suffix_8 {
+ padding-right:66.667%;
+}
+
+.container_12 .suffix_9 {
+ padding-right:75.0%;
+}
+
+.container_12 .suffix_10 {
+ padding-right:83.333%;
+}
+
+.container_12 .suffix_11 {
+ padding-right:91.667%;
+}
+
+
+
+/* Push Space >> 12 Columns
+----------------------------------------------------------------------------------------------------*/
+
+
+.container_12 .push_1 {
+ left:8.333%;
+}
+
+.container_12 .push_2 {
+ left:16.667%;
+}
+
+.container_12 .push_3 {
+ left:25.0%;
+}
+
+.container_12 .push_4 {
+ left:33.333%;
+}
+
+.container_12 .push_5 {
+ left:41.667%;
+}
+
+.container_12 .push_6 {
+ left:50.0%;
+}
+
+.container_12 .push_7 {
+ left:58.333%;
+}
+
+.container_12 .push_8 {
+ left:66.667%;
+}
+
+.container_12 .push_9 {
+ left:75.0%;
+}
+
+.container_12 .push_10 {
+ left:83.333%;
+}
+
+.container_12 .push_11 {
+ left:91.667%;
+}
+
+
+
+/* Pull Space >> 12 Columns
+----------------------------------------------------------------------------------------------------*/
+
+
+.container_12 .pull_1 {
+ left:-8.333%;
+}
+
+.container_12 .pull_2 {
+ left:-16.667%;
+}
+
+.container_12 .pull_3 {
+ left:-25.0%;
+}
+
+.container_12 .pull_4 {
+ left:-33.333%;
+}
+
+.container_12 .pull_5 {
+ left:-41.667%;
+}
+
+.container_12 .pull_6 {
+ left:-50.0%;
+}
+
+.container_12 .pull_7 {
+ left:-58.333%;
+}
+
+.container_12 .pull_8 {
+ left:-66.667%;
+}
+
+.container_12 .pull_9 {
+ left:-75.0%;
+}
+
+.container_12 .pull_10 {
+ left:-83.333%;
+}
+
+.container_12 .pull_11 {
+ left:-91.667%;
+}
+
+
+
+
+/* Clear Floated Elements
+----------------------------------------------------------------------------------------------------*/
+
+/* http://sonspring.com/journal/clearing-floats */
+
+.clear {
+ clear: both;
+ display: block;
+ overflow: hidden;
+ visibility: hidden;
+ width: 0;
+ height: 0;
+}
+
+/* http://perishablepress.com/press/2008/02/05/lessons-learned-concerning-the-clearfix-css-hack */
+
+.clearfix:after {
+ clear: both;
+ content: ' ';
+ display: block;
+ font-size: 0;
+ line-height: 0;
+ visibility: hidden;
+ width: 0;
+ height: 0;
+}
+
+.clearfix {
+ display: inline-block;
+}
+
+* html .clearfix {
+ height: 1%;
+}
+
+.clearfix {
+ display: block;
+}
View
7 static/styles/style.css
@@ -30,3 +30,10 @@ form.importfolder em {
font-style: normal;
color: #f00;
}
+
+div.validate-error {
+ background-color: #FB9C8A;
+ border: 1px solid #EB8C7A;
+ padding: 5px;
+ margin-bottom: 10px;
+}
View
6 templates/footer.html
@@ -0,0 +1,6 @@
+ </div> <!-- end main container -->
+ % for js_file in js_appends:
+ <script type="text/javascript" src="/static/js/${js_file}"></script>
+ % endfor
+ </body>
+</html>
View
12 templates/header.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>${title} - Musik</title>
+ <link rel="stylesheet" href="/static/styles/960gs.css" />
+ <link rel="stylesheet" href="/static/styles/style.css" />
+ </head>
+ <body>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
+ <div class="container_12">
+ <!-- end header -->
View
21 templates/importmedia.html
@@ -1,19 +1,12 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta charset="UTF-8">
- <title>Musik - Import Media</title>
- <link rel="stylesheet" href="/static/styles/style.css" />
- </head>
- <body>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
-
+<div class="grid_12">
<h1>Musik Media Importer</h1>
<p>From this page, you can import all of your precious media files into the musik database. Start by entering a directory below:</p>
+
+ <div class="validate-error" id="validate-error-top"></div>
- <form class="importfolder" action="/api/importmedia/directory" method="post">
+ <form class="importfolder" action="/api/importmedia/directory" method="post" id="importmedia-form">
<fieldset>
- <legend>Enter the path to a directory below:&nbsp</legend>
+ <legend>Enter the path to a directory below:&nbsp;</legend>
<ol>
<li>
<label for="path">Path<em>*</em></label>
@@ -25,5 +18,5 @@
</form>
<a href="/">Back to Home</a>
- </body>
-</html>
+</div>
+<div class="clear"></div>
View
15 templates/index.html
@@ -1,13 +1,4 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta charset="UTF-8">
- <title>Musik - Home</title>
- <link rel="stylesheet" href="/static/styles/style.css" />
- </head>
- <body>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
-
+<div class="grid_12">
<h1>Welcome to Musik!</h1>
<h2>The world's finest web-based music player</h2>
<p>
@@ -18,5 +9,5 @@
<ul>
<li><a href="/importmedia">Import Files</a></li>
</ul>
- </body>
-</html>
+</div>
+<div class="clear"></div>
Please sign in to comment.
Something went wrong with that request. Please try again.