diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-03-20 20:40:26 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-03-20 20:40:26 (GMT) |
commit | cfdf4296fc0a1480e21aa77f64f0acac2f10571a (patch) | |
tree | 2e2f5db9b44c4965e5b849f4a50c4477030b0fd3 | |
parent | 217353beafb61313fb322832d3f42958d0b545f0 (diff) |
Avoid destrying media files writing playlists
If the user opened a media file, and later open more files
we create a playlist. At saving time we need create a different
object in the datastore to avoid writing the playlist over
the first media file opened.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | jukeboxactivity.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/jukeboxactivity.py b/jukeboxactivity.py index 3e609de..cc277b7 100644 --- a/jukeboxactivity.py +++ b/jukeboxactivity.py @@ -385,11 +385,30 @@ class JukeboxActivity(activity.Activity): # is another media file: gobject.idle_add(self._start, self.uri, title, object_id) + def can_close(self): + """Activities should override this function if they want to perform + extra checks before actually closing.""" + if len(self.playlist) > 1 and \ + self.metadata['mime_type'] != 'audio/x-mpegurl': + # if the activity started with a media file and added more later + # need create a new file with the file list to no destroy + # the first opened file + logging.error('need new file') + self._jobject = datastore.create() + self.title_entry.set_text(_('Jukebox playlist')) + self._jobject.metadata['title'] = _('Jukebox playlist') + self._jobject.metadata['title_set_by_user'] = '1' + description = '' + for uri in self.playlist: + description += '%s\n' % uri['title'] + self._jobject.metadata['description'] = description + self._jobject.metadata['mime_type'] = 'audio/x-mpegurl' + datastore.write(self._jobject) + + return True + def write_file(self, file_path): if len(self.playlist) > 1: - # need create a new file with the file list - logging.error('need new file') - self.metadata['mime_type'] = 'audio/x-mpegurl' list_file = open(file_path, 'w') for uri in self.playlist: list_file.write('#EXTINF: %s\n' % uri['title']) |