Hello, Nick and Götz!

On Mon, 2007-08-06 at 22:59 -0400, nikosapi wrote:
> On August 6, 2007 15:01:17 Thomas Perl wrote:
> > On Mon, 2007-08-06 at 20:30 +0200, Götz Waschk wrote:
> > detection have previously been because of enhanced AAC files. Does libmad
> > always provide the correct length for MP3 files? If so, maybe using libmad
> > for MP3 files and mplayer for everything else would fix your problem?
> 
> Ok, here's the promissed patch :)
> 
> If mplayer is available, it will use it for all media files. If the file is 
> an 
> mp3 and pymad is installed it will get the length reported by pymad and 
> compare it to the length from mplayer and use the longer of the two (this 
> works great btw). And of course, worst case eyed3 is still available if all 
> else fails.

I've revisited your patch for the latest SVN trunk head (I've done some
restructuring of the code during the weekend, because I want to clean up the 
codebase a bit to get ready for the "gPodder API" ;).

Maybe we should try out all possible ways to detect the file length (including
eyed3) and use the maximum reported time? Or just leave it as it is currently
(default to mplayer, if pymad is here, try and use it if length is bigger, and 
if none of the above is available/working, try eyed3). What do you think?

> Oh and btw, about Cory Doctorow's podcasts. The mp3s are borked, all the 
> media 
> players I tried them with gave different play times. Pymad gets close to the 
> right time but is off by ~10sec. Email Cory and tell him to use a better mp3 
> encoder (he still reads all his emails right?).

I think we're way too cool to support even broken podcasts, hehe :) I'm
glad we have motivated contributors and bug reporters that help us make
gPodder so great in this respect (file length detection is quite
sophisticated already, and as we saw, "valid" MP3 files are not always
the reality in the cruel, dark podcast world :).


Thomas

Index: src/gpodder/util.py
===================================================================
--- src/gpodder/util.py	(revision 363)
+++ src/gpodder/util.py	(working copy)
@@ -195,3 +195,15 @@
     return stripstr
 
 
+def file_has_extension( filename, ext):
+    """
+    Checks if the supplied file name has the corresponding
+    file name extension, ignoring case. Returns True if the 
+    file's extension is the same as the supplied extension,
+    False otherwise.
+    """
+    (filename, extension) = os.path.splitext( filename)
+    
+    return extension.lower() == ext.lower()
+
+
Index: src/gpodder/libipodsync.py
===================================================================
--- src/gpodder/libipodsync.py	(revision 363)
+++ src/gpodder/libipodsync.py	(working copy)
@@ -31,8 +31,8 @@
 enable_ipod_functions = True
 
 # possible mp3 length detection mechanisms
-MAD = 1
-EYED3 = 2
+use_mad = False
+use_eyed3 = False
 
 # default length (our "educated guess") is 60 minutes
 DEFAULT_LENGTH = 60*60*1000
@@ -54,12 +54,14 @@
 try:
     import mad
     log( '(ipodsync) Found pymad')
+    use_mad = True
 except:
     log( '(ipodsync) Could not find pymad.')
 
 try:
     import eyeD3
     log( '(ipodsync) Found eyeD3')
+    use_eyed3 = True
 except:
     log( '(ipodsync) Coulld not find eyeD3.')
 
@@ -397,8 +399,7 @@
                 log('(ipodsync) Error while converting file %s', original_filename)
                 return False
 
-        # if we cannot get the track length, make an educated guess (default value)
-        track_length = DEFAULT_LENGTH
+        track_length = 0
         track_length_found = False
 
         if use_mplayer:
@@ -412,16 +413,17 @@
         else:
             log( 'Please try installing the "mplayer" package for track length detection.', sender = self)
 
-        if not track_length_found:
+        if use_mad and util.file_has_extension( local_filename, 'mp3'):
             try:
                 log( 'Using pymad to get file length', sender = self)
                 mad_info = mad.MadFile( local_filename)
-                track_length = mad_info.total_time()
+                # go for the longest reported time
+                track_length = max( track_length, mad_info.total_time())
                 track_length_found = True
             except:
                 log( 'Warning: cannot get length for %s', episode.title, sender = self)
-        
-        if not track_length_found:
+
+        if use_eyed3 and not track_length_found and util.file_has_extension( local_filename, 'mp3'):
             try:
                 log( 'Using eyeD3 to get file length', sender = self)
                 eyed3_info = eyeD3.Mp3AudioFile( local_filename)
@@ -431,6 +433,7 @@
                 log( 'Warning: cannot get length for %s', episode.title, sender = self)
 
         if not track_length_found:
+            track_length = DEFAULT_LENGTH
             log( 'I was not able to find a correct track length, defaulting to %d', track_length, sender = self)
         
         track = gpod.itdb_track_new()
_______________________________________________
gpodder-devel mailing list
gpodder-devel@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/gpodder-devel

Reply via email to