mplayer support for video length
git-svn-id: svn://svn.berlios.de/gpodder/trunk@226 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
parent
97d3e010e7
commit
704cb79606
2
AUTHORS
2
AUTHORS
|
@ -13,7 +13,7 @@ Thanks to all the other patch writers:
|
|||
Stylianos Papanastasiou <stelios@dcs.gla.ac.uk> (patch for "downloaded move")
|
||||
Ortwin Forster <ortwin@videotron.ca> (patch for saxutils.escape in localdb)
|
||||
Camille Moncelier <pix@devlife.org> (patch for iPod video device support)
|
||||
Nick <nikosapi@gmail.com> (many patches for iPod 5G support)
|
||||
Nick <nikosapi@gmail.com> (many patches for iPod 5G support + mplayer-length)
|
||||
Seth Remington <sremington@saberlogic.com> (several important bugfixes)
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
Thu, 28 Dec 2006 14:39:06 +0100 <thp@perli.net>
|
||||
* src/gpodder/libipodsync.py: Add support for non-mp3 file
|
||||
length detection using mplayer if available (thanks to
|
||||
Nick <nikosapi gmail com> for the patch)
|
||||
* bin/gpodder: bumped version + release date
|
||||
|
||||
Wed, 20 Dec 2006 20:43:02 +0100 <thp@perli.net>
|
||||
* src/gpodder/gpodder.py: Added modified patch from Seth
|
||||
Remington to add support for a "download new episodes from
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
# PLEASE DO NOT CHANGE FORMAT OF __version__ LINE (setup.py reads this)
|
||||
|
||||
__author__ = "Thomas Perl <thp@perli.net>"
|
||||
__version__ = "0.8.0+svn20061220"
|
||||
__date__ = "2006-12-20"
|
||||
__version__ = "0.8.0+svn20061228"
|
||||
__date__ = "2006-12-28"
|
||||
__copyright__ = "Copyright (c) 2005-2006 %s. All rights reserved." % __author__
|
||||
__licence__ = "GPL"
|
||||
|
||||
|
|
|
@ -34,6 +34,12 @@ enable_ipod_functions = True
|
|||
MAD = 1
|
||||
EYED3 = 2
|
||||
|
||||
# default length (our "educated guess") is 60 minutes
|
||||
DEFAULT_LENGTH = 60*60*1000
|
||||
|
||||
# command line for mplayer
|
||||
MPLAYER_COMMAND = 'mplayer -msglevel all=-1 -identify -vo null -ao null -frames 0 "%s" 2>/dev/null'
|
||||
|
||||
# which detection mechanism are we going to use?
|
||||
use_mechanism = 0
|
||||
|
||||
|
@ -88,6 +94,13 @@ def ipod_supported():
|
|||
# file extensions that are handled as video
|
||||
video_extensions = [ "mov", "mp4", "m4v" ]
|
||||
|
||||
# is mplayer available for finding track length?
|
||||
use_mplayer = False
|
||||
if not os.system("which mplayer > /dev/null 2>&1"):
|
||||
use_mplayer = True
|
||||
log('(ipodsync) Found mplayer, using it to find track length of video files')
|
||||
else:
|
||||
log('(ipodsync) mplayer not found - length of video files will be guessed')
|
||||
|
||||
class gPodderSyncMethod:
|
||||
def __init__( self, callback_progress = None, callback_status = None, callback_done = None):
|
||||
|
@ -283,6 +296,9 @@ class gPodder_iPodSync( gPodderSyncMethod):
|
|||
return self.set_channel_art( track, local_filename)
|
||||
|
||||
def add_episode_from_channel( self, channel, episode):
|
||||
global DEFAULT_LENGTH
|
||||
global MPLAYER_COMMAND
|
||||
|
||||
if not ipod_supported():
|
||||
return False
|
||||
|
||||
|
@ -293,6 +309,10 @@ class gPodder_iPodSync( gPodderSyncMethod):
|
|||
|
||||
log( '(ipodsync) Adding item: %s from %s', episode.title, channel.title)
|
||||
local_filename = str(channel.getPodcastFilename( episode.url))
|
||||
|
||||
# if we cannot get the track length, make an educated guess (default value)
|
||||
track_length = DEFAULT_LENGTH
|
||||
|
||||
try:
|
||||
if use_mechanism == MAD:
|
||||
log( '(ipodsync) Using pymad to get file length')
|
||||
|
@ -302,10 +322,17 @@ class gPodder_iPodSync( gPodderSyncMethod):
|
|||
log( '(ipodsync) Using eyeD3 to get file length')
|
||||
eyed3_info = eyeD3.Mp3AudioFile( local_filename)
|
||||
track_length = eyed3_info.getPlayTime() * 1000
|
||||
# TODO: how to get length of video (mov, mp4, m4v) files??
|
||||
# TODO: Find python module to get length of video (mov, mp4, m4v) files, instead of using mplayer.
|
||||
except:
|
||||
print '(ipodsync) Warning: cannot get length for %s, will use 1 hour' % episode.title
|
||||
track_length = 20*60*1000 # hmm.. (20m so we can skip on video/audio with unknown length)
|
||||
if use_mplayer:
|
||||
try:
|
||||
log('(ipodsync) eyeD3 failed, using mplayer to get track length')
|
||||
mplayer_output = os.popen( MPLAYER_COMMAND % local_filename).read()
|
||||
track_length = int(float(mplayer_output[mplayer_output.index('ID_LENGTH'):].splitlines()[0][10:]) * 1000)
|
||||
except:
|
||||
log('(ipodsync) Warning: cannot get length for %s', episode.title)
|
||||
else:
|
||||
log('(ipodsync) Warning: cannot get length for %s; try installing mplayer', episode.title)
|
||||
|
||||
track = gpod.itdb_track_new()
|
||||
|
||||
|
@ -339,7 +366,12 @@ class gPodder_iPodSync( gPodderSyncMethod):
|
|||
# dirty hack to get video working, seems to work
|
||||
for ext in video_extensions:
|
||||
if local_filename.lower().endswith( '.%s' % ext):
|
||||
track.unk208 = 0x00000002 # documented on http://ipodlinux.org/ITunesDB
|
||||
try:
|
||||
# documented on http://ipodlinux.org/ITunesDB
|
||||
track.mediatype = 0x00000002
|
||||
except:
|
||||
# for old libgpod versions, "mediatype" is "unk208"
|
||||
track.unk208 = 0x00000002
|
||||
|
||||
# if it's a music channel, also sync to master playlist
|
||||
if channel.is_music_channel:
|
||||
|
|
Loading…
Reference in New Issue