1 # -*- coding: utf-8 -*-
3 # This file is part of Panucci.
4 # Copyright (c) 2008-2010 The Panucci Audiobook and Podcast Player Project
6 # Panucci is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # Panucci is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Panucci. If not, see <http://www.gnu.org/licenses/>.
20 from __future__
import absolute_import
25 def convert_ns(time_int
):
26 """Convert nanosecond values into strings
28 This function should be used to generate
29 a string suitable for display in the UI.
31 time_int
= max( 0, int(time_int
) )
32 time_int
= time_int
/ 10**9
35 _hours
= time_int
/ 3600
36 time_int
= time_int
- (_hours
* 3600)
37 time_str
= str(_hours
) + ":"
40 time_int
= time_int
- (_mins
* 60)
41 time_str
= time_str
+ str(_mins
) + ":"
44 time_int
= time_int
- (_mins
* 60)
45 time_str
= time_str
+ "0" + str(_mins
) + ":"
47 time_str
= time_str
+ "00:"
49 time_str
= time_str
+ str(time_int
)
51 time_str
= time_str
+ "0" + str(time_int
)
56 def detect_filetype(filepath
):
57 """Return the file type (extension) of a file path
59 This returns something like "ogg", "mp3", etc..
61 filename
, extension
= os
.path
.splitext(filepath
)
62 if extension
.startswith('.'):
63 extension
= extension
[1:]
64 return extension
.lower()
67 def pretty_filename(filename
):
68 """Return a prettified version of a filename
70 Currently, this removes the extension and
71 replaces underscores with spaces.
73 filename
, extension
= os
.path
.splitext(filename
)
74 basename
= os
.path
.basename(filename
)
75 return filename
.replace('_', ' ')