summaryrefslogtreecommitdiff
path: root/directory.py
diff options
context:
space:
mode:
Diffstat (limited to 'directory.py')
-rw-r--r--directory.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/directory.py b/directory.py
index 6860155..79024f4 100644
--- a/directory.py
+++ b/directory.py
@@ -1,12 +1,13 @@
-import os, mimetypes, recode, events
+import os, mimetypes, recode, events, cuesheet
from config import config
class DirectoryEntry(object):
'''Base class for directory entries.'''
- def __init__(self, path, isabs = False):
+ def __init__(self, path, isabs = False, track = None):
self.path = path
+ self.track = track
if isabs:
self.abs_path = path
@@ -27,7 +28,7 @@ class DirectoryEntry(object):
return '<a href="/files/{path}">{name}</a><br />'.format(path = self.path, name = os.path.basename(self.path))
def json(self):
- return {'type': self.entry_type, 'name': self.path}
+ return {'type': self.entry_type, 'name': self.path, 'track': self.track}
class Directory(DirectoryEntry):
'''A directory entry inside a directory.'''
@@ -44,7 +45,12 @@ class Directory(DirectoryEntry):
if os.path.isdir(abs_path):
directories.append(Directory(rel_path))
elif os.path.isfile(abs_path):
- files.append(File(rel_path))
+ if os.path.splitext(f)[1] == '.cue':
+ cue = cuesheet.Cuesheet(abs_path)
+ for t in cue.tracks:
+ files.append(File(rel_path, track = t.track[0]))
+ else:
+ files.append(File(rel_path))
return sorted(directories) + sorted(files)
class File(DirectoryEntry):
@@ -86,13 +92,30 @@ class File(DirectoryEntry):
def get_cache_path(self):
cache_path = os.path.join(config.get('cache_dir'), self.path)
- cache_path = os.path.splitext(cache_path)[0] + '.ogg'
+ cache_path = os.path.splitext(cache_path)[0]
+ if self.track:
+ cache_path += '.' + self.track
+ cache_path += '.ogg'
return cache_path
def get_cache_file(self):
return File(self.get_cache_path(), True)
def recode(self, decoder, encoder, sessionid = None):
+ if self.track:
+ cue = cuesheet.Cuesheet(self.abs_path)
+ t = cue.tracks[int(self.track)-1]
+ start_time = t.get_start_time()
+ next = cue.get_next(t)
+ if next:
+ end_time = next.get_start_time()
+ else:
+ end_time = None
+ path = os.path.join(os.path.dirname(self.abs_path), cue.info[0].file[0])
+ else:
+ path = self.abs_path
+ start_time, end_time = None, None
+
decoder = recode.decoders[decoder]()
encoder = recode.encoders[encoder]()
recoder = recode.Recoder(decoder, encoder)
@@ -104,9 +127,9 @@ class File(DirectoryEntry):
os.makedirs(cache_path_dir)
# check if file is cached
if not os.path.exists(cache_path):
- events.event_pub.recoding(self.path)
- recoder.recode(self.abs_path, cache_path)
- events.event_pub.cached(self.path)
+ events.event_pub.recoding(self.path, self.track)
+ recoder.recode(path, cache_path, start_time = start_time, end_time = end_time)
+ events.event_pub.cached(self.path, self.track)
if sessionid:
events.event_pub.play(sessionid, '/cache/{0}'.format(self.path))