Update of /cvsroot/freevo/freevo/src/audio/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv25645
Modified Files:
cdbackup.py
Log Message:
o use plugin config() function to set defaults to freevo_config.py
o show current ripping status in itemmenu while ripping
o some cleanup and restructuring
Index: cdbackup.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/audio/plugins/cdbackup.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** cdbackup.py 9 Sep 2003 18:54:59 -0000 1.15
--- cdbackup.py 10 Sep 2003 18:15:11 -0000 1.16
***************
*** 29,32 ****
--- 29,37 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.16 2003/09/10 18:15:11 dischi
+ # o use plugin config() function to set defaults to freevo_config.py
+ # o show current ripping status in itemmenu while ripping
+ # o some cleanup and restructuring
+ #
# Revision 1.15 2003/09/09 18:54:59 dischi
# Add some doc
***************
*** 64,107 ****
import time
import string
import config
-
import menu
!
! import rc
from gui.AlertBox import AlertBox
- from gui.PopupBox import PopupBox
- from gui.ConfirmBox import ConfirmBox
! import plugin
! from item import Item
! import util
! import skin
! skin = skin.get_singleton()
- import os
- import sys
! import threading
! import re
! # Included to be able to access the info for Audio CDs
! import mmpython
! # Set to 1 for debug output
! DEBUG = 1 #config.DEBUG
! TRUE = 1
! FALSE = 0
- menuwidget = menu.get_singleton()
! killflag = 0
- song_names = []
--- 69,254 ----
import time
import string
+ import sys
+ import threading
+ import re
import config
import menu
! import util
! import plugin
from gui.AlertBox import AlertBox
! # Included to be able to access the info for Audio CDs
! import mmpython
! # Set to 1 for debug output
! DEBUG = config.DEBUG
! TRUE = 1
! FALSE = 0
! rip_thread = None
! class PluginInterface(plugin.ItemPlugin):
! """
! Backup audio CDs in .mp3, .ogg, or .wav format.
!
! The following variables are needed by this plugin. Please set them in
! your local_conf.py:
!
! Directory that you want to backup your audio CD to.
! AUDIO_BACKUP_DIR = '/music/MP3'
!
! You can use any combination of the 4 variables below to create subdirectories,
! and filename of songs.
! The four variables are: genre, artist,album, and song.
! Whatever follows the last slash indicates how to create the filename.
! Everything before the last slash indicates the directory structure you would
! like to use -which will be appended to AUDIO_BACKUP_DIR.
! CD_RIP_PN_PREF= '%(genre)s/%(artist)s/%(album)s/%(song)s'
!
! This would give you something like:
! /music/MP3/metal/Metallica/And Justice For All/Blackened.mp3
! (or Blackened.wav, Blackened.ogg)
!
! Here is another example which includes the artist and album in the filename:
! CD_RIP_PN_PREF = '%(artist)s/%(artist)s - %(album)s - %(song)s'
! /music/MP3/Metallica/Metallica - And Justice For All - Blackened.mp3
!
! cdparanoia is used to rip the CD to your hard drive. The actual command that
! will be executed is stored in CDPAR_CMD.
! CDPAR_CMD = 'cdparanoia'
!
! Lame .mp3 encoding parameters:
! Lame is used for .mp3 encoding. The actual command that will be executed is
! stored in LAME_CMD
! LAME_CMD = 'lame'
!
! For ripping to .mp3 you can provide your own Lame encoder parameters for
! bitrate, algorithm, and various other lame options. Add your custom parameters
! in CD_RIP_LAME_OPTS.
! CD_RIP_LAME_OPTS = '--vbr-new'
!
! Ogg Encoding:
! Likewise for Ogg format, the command is as below, and you can add your own
! custom ogg encoding options.
! OGGENC_CMD ='oggenc'
! CD_RIP_OGG_OPTS = ' '
!
! To activate this plugin, add the following to local_conf.py:
! plugin.activate('audio.cdbackup')
!
! Finally, to actually backup an audio CD within Freeevo, when you are in the
! Music menu, highlight/choose a CD, then hit 'e' on keyboard or 'ENTER' on
! your remote control and you will be able to access the rip/backup menu.
!
! Here is a list of all the above mentioned parameters for simple cutting and
! pasting:
!
! #The following are for adding and configuring the CD Audio backup plugin:
! AUDIO_BACKUP_DIR = '/music/MP3'
!
! CD_RIP_PN_PREF= '%(genre)s/%(artist)s/%(album)s/%(song)s'
! CDPAR_CMD = 'cdparanoia'
!
! LAME_CMD = 'lame'
! CD_RIP_LAME_OPTS = '--vbr-new'
!
! #You can leave this out if you never use ogg and it won't show up in the
! #backup menu
! OGGENC_CMD ='oggenc'
! CD_RIP_OGG_OPTS = ' '
!
! #To activate the cdbackup plugin:
! plugin.activate('audio.cdbackup')
! """
! def __init__(self):
! plugin.ItemPlugin.__init__(self)
! self.artist = ''
! self.album = ''
! self.song_names = []
! self.device = ''
!
! def config(self):
! """
! list of config variables this plugin needs
! """
! return (('AUDIO_BACKUP_DIR', config.DIR_AUDIO[ 0 ][ 1 ],
! 'directory where to put the encoded files'),
! ('LAME_CMD', config.CONF.lame , '' ),
! ('CDPAR_CMD', config.CONF.cdparanoia, ''),
! ('OGGENC_CMD', config.CONF.oggenc, ''),
! ('FLAC_CMD', config.CONF.flac, ''),
! ('CD_RIP_PN_PREF', '%(artist)s/%(album)s/%(song)s', ''),
! ('CD_RIP_LAME_OPTS', '--preset standard', ''),
! ('CD_RIP_OGG_OPTS', '-m 128', ''),
! ('FLAC_OPTS', '-8', '8==Best, but slowest compression'))
! def actions(self, item):
! global rip_thread
! self.item = item
!
! try:
! if (self.item.type == 'audiocd'):
! if rip_thread:
! return [ ( self.show_status, 'Show CD ripping status') ]
! else:
! self.device = self.item.devicename
! if DEBUG:
! print 'devicename = %s' %self.device
! return [ ( self.create_backup_menu, 'Rip the CD to the hard
drive',
! 'Get CDs available for ripping') ]
! except:
! print 'Error: Item is not an AudioCD'
! return []
! def show_status(self, arg=None, menuw=None):
! global rip_thread
! t = rip_thread
! if t:
! pop = AlertBox(text='Ripping in progress\nTrack %s of %s' % \
! (t.current_track, t.max_track))
! pop.show()
!
!
! def create_backup_menu(self, arg=None, menuw=None):
! mm_menu = self.create_backup_items(self.device, menuw=None)
! menuw.pushmenu(mm_menu)
! menuw.refresh()
!
!
! def create_backup_items(self, arg, menuw):
! items = []
!
! if config.LAME_CMD:
! items.append(menu.MenuItem('Backup CD to hard drive in mp3 format',
! self.cd_backup, arg=(arg, 'mp3')))
! if config.OGGENC_CMD:
! items.append(menu.MenuItem('Backup CD to hard drive in Ogg format',
! self.cd_backup, arg=(arg, 'ogg')))
! if config.FLAC_CMD:
! items.append(menu.MenuItem('Backup CD to hard drive in FLAC format',
! self.cd_backup, arg=(arg, 'flac')))
! items.append(menu.MenuItem('Backup CD to hard drive in wav format',
! self.cd_backup, arg=(arg, 'wav')))
!
! backupmenu = menu.Menu('CD Backup', items,
reload_func=self.create_backup_menu)
! return backupmenu
!
!
! def cd_backup(self, arg, menuw=None):
! global rip_thread
! device, type = arg
! rip_thread = main_backup_thread(device=device, rip_format=type)
! rip_thread.start()
! AlertBox(text='Ripping started').show()
! menuw.delete_menu()
! menuw.back_one_menu()
***************
*** 112,118 ****
def __init__(self, rip_format, device=None):
threading.Thread.__init__(self)
! self.device = device
! self.rip_format = rip_format
!
def run(self, rip_format='mp3'):
if self.rip_format == 'mp3' :
--- 259,268 ----
def __init__(self, rip_format, device=None):
threading.Thread.__init__(self)
! self.device = device
! self.rip_format = rip_format
! self.current_track = 0
! self.max_track = 0
! self.output_directory = ''
!
def run(self, rip_format='mp3'):
if self.rip_format == 'mp3' :
***************
*** 164,188 ****
os.makedirs(pathname, 0777)
except:
! if DEBUG: print 'Directory %s already exists' %pathname
! pass
!
cdparanoia_command = []
length=len(song_names)
!
!
for i in range (0, len(song_names)):
# Keep track of track#
track = i +1
!
! # store start time
begin = time.time()
# CD_RIP_PATH = '%(artist)s/%(album)/%(song)s'
! # Add the song and track key back into user_rip_path_prefs to be used in
the song name
! # as specified in CD_RIP_PN_PREF. The song name was previously not set
! # so had to wait until here to add it in.
track = '%0.2d' % int(track)
--- 314,338 ----
os.makedirs(pathname, 0777)
except:
! if DEBUG:
! print 'Directory %s already exists' % pathname
!
! self.output_directory = pathname
cdparanoia_command = []
length=len(song_names)
! self.max_track = len(song_names)
for i in range (0, len(song_names)):
# Keep track of track#
track = i +1
! self.current_track = track
+ # store start time
begin = time.time()
# CD_RIP_PATH = '%(artist)s/%(album)/%(song)s'
! # Add the song and track key back into user_rip_path_prefs to be used
! # in the song name as specified in CD_RIP_PN_PREF. The song name was
! # previously not set so had to wait until here to add it in.
track = '%0.2d' % int(track)
***************
*** 195,211 ****
path_tail = path_tail_temp % user_rip_path_prefs
! # If rip_format is mp3 or ogg, then copy the file to
/temp/track_being_ripped.wav
!
! if (string.upper(rip_format) == 'MP3') or (string.upper(rip_format) ==
'OGG') or \
! (string.upper(rip_format) == 'FLAC'):
pathname_cdparanoia = '/tmp'
path_tail_cdparanoia = '/track_being_ripped'
! # Otherwise if it's going to be a .wav just use the the users preferred
directory and filename.
! # i.e. don't bother putting into /tmp directory, just use directory and
filename of final destination.
else:
! pathname_cdparanoia = pathname
! path_tail_cdparanoia = path_tail
# Build the cdparanoia command to be run
--- 345,363 ----
path_tail = path_tail_temp % user_rip_path_prefs
! # If rip_format is mp3 or ogg, then copy the file to
! # /tmp/track_being_ripped.wav
! if (string.upper(rip_format) == 'MP3') or \
! (string.upper(rip_format) == 'OGG') or \
! (string.upper(rip_format) == 'FLAC'):
pathname_cdparanoia = '/tmp'
path_tail_cdparanoia = '/track_being_ripped'
! # Otherwise if it's going to be a .wav just use the the users preferred
! # directory and filename. i.e. don't bother putting into /tmp directory,
! # just use directory and filename of final destination.
else:
! pathname_cdparanoia = pathname
! path_tail_cdparanoia = path_tail
# Build the cdparanoia command to be run
***************
*** 213,218 ****
# XXX Sending output to dev /null; someone should move this into runapp
# and parse the output
! cdparanoia_command = '%s -s %s "%s%s.wav" >/dev/null 2>&1' %
(config.CDPAR_CMD, str(i+1),
! pathname_cdparanoia, path_tail_cdparanoia)
if DEBUG: print 'cdparanoia: %s' % cdparanoia_command
--- 365,371 ----
# XXX Sending output to dev /null; someone should move this into runapp
# and parse the output
! cdparanoia_command = '%s -s %s "%s%s.wav" >/dev/null 2>&1' % \
! (config.CDPAR_CMD, str(i+1),
! pathname_cdparanoia, path_tail_cdparanoia)
if DEBUG: print 'cdparanoia: %s' % cdparanoia_command
***************
*** 222,238 ****
# Build the lame command to be run if mp3 format is selected
-
if string.upper(rip_format) == 'MP3':
# XXX Sending output to /dev/null too; move this into runapp, parse
output
! lame_command = '%s --nohist -h %s "%s%s.wav" "%s%s.mp3" >/dev/null
2>&1' % (config.LAME_CMD,
! config.CD_RIP_LAME_OPTS, pathname_cdparanoia,
path_tail_cdparanoia,
! pathname, path_tail)
if DEBUG: 'lame: %s' %lame_command
os.system(lame_command)
! util.tagmp3(pathname+path_tail+'.mp3', title=song_names[i],
artist=artist, album=album, track=track,
! tracktotal=len(song_names))
# Remove the .wav file.
--- 375,392 ----
# Build the lame command to be run if mp3 format is selected
if string.upper(rip_format) == 'MP3':
# XXX Sending output to /dev/null too; move this into runapp, parse
output
! lame_command = '%s --nohist -h %s "%s%s.wav" "%s%s.mp3" >/dev/null
2>&1' % \
! (config.LAME_CMD, config.CD_RIP_LAME_OPTS,
! pathname_cdparanoia, path_tail_cdparanoia,
! pathname, path_tail)
if DEBUG: 'lame: %s' %lame_command
os.system(lame_command)
! util.tagmp3(pathname+path_tail+'.mp3', title=song_names[i],
! artist=artist, album=album, track=track,
! tracktotal=len(song_names))
# Remove the .wav file.
***************
*** 240,251 ****
if os.path.exists (rm_command): os.unlink(rm_command)
# Build the oggenc command to be run if ogg format is selected
-
elif string.upper(rip_format) == 'OGG':
! oggenc_command = \
! '%s %s -a "%s" -G "%s" -N "%s" -t "%s" -l "%s" "%s%s.wav" -o
"%s%s.ogg"' % \
! (config.OGGENC_CMD, config.CD_RIP_OGG_OPTS,
! artist, genre, track, song_names[i], album,
! pathname_cdparanoia, path_tail_cdparanoia, pathname, path_tail)
if DEBUG: 'oggenc_command: %s' %oggenc_command
--- 394,406 ----
if os.path.exists (rm_command): os.unlink(rm_command)
+
# Build the oggenc command to be run if ogg format is selected
elif string.upper(rip_format) == 'OGG':
! oggenc_command = '%s %s -a "%s" -G "%s" -N "%s" -t "%s" -l "%s" ' \
! '"%s%s.wav" -o "%s%s.ogg"' % \
! (config.OGGENC_CMD, config.CD_RIP_OGG_OPTS,
! artist, genre, track, song_names[i], album,
! pathname_cdparanoia, path_tail_cdparanoia,
pathname,
! path_tail)
if DEBUG: 'oggenc_command: %s' %oggenc_command
***************
*** 256,267 ****
if os.path.exists (rm_command): os.unlink(rm_command)
elif string.upper(rip_format) == 'FLAC':
! flac_command = \
! '%s %s "%s%s.wav" -o "%s%s.flac"' % \
! ( config.FLAC_CMD, config.FLAC_OPTS, pathname_cdparanoia,
! path_tail_cdparanoia, pathname, path_tail)
metaflac_command = \
! 'metaflac --set-vc-field=ARTIST="%s" --set-vc-field=ALBUM="%s"
--set-vc-field=TITLE="%s" --set-vc-field=TRACKNUMBER="%s/%s" "%s%s.flac"' % \
! (artist, album, song_names[i], track, len(song_names), pathname,
path_tail)
if DEBUG: 'flac_command: %s' % (flac_command)
if DEBUG: 'metaflac : %s' % (metaflac_command)
--- 411,424 ----
if os.path.exists (rm_command): os.unlink(rm_command)
+ # Build the flacenc command
elif string.upper(rip_format) == 'FLAC':
! flac_command = '%s %s "%s%s.wav" -o "%s%s.flac"' % \
! ( config.FLAC_CMD, config.FLAC_OPTS,
pathname_cdparanoia,
! path_tail_cdparanoia, pathname, path_tail)
metaflac_command = \
! 'metaflac --set-vc-field=ARTIST="%s" --set-vc-field=ALBUM="%s" '\
! '--set-vc-field=TITLE="%s" --set-vc-field=TRACKNUMBER="%s/%s" '\
! '"%s%s.flac"' % (artist, album, song_names[i], track,
! len(song_names), pathname, path_tail)
if DEBUG: 'flac_command: %s' % (flac_command)
if DEBUG: 'metaflac : %s' % (metaflac_command)
***************
*** 283,286 ****
--- 440,449 ----
# you can no longer do anything in Freevo.
+ # done
+ global rip_thread
+ rip_thread = None
+
+
+
def get_formatted_cd_info(self, device):
cd_info = mmpython.parse(device)
***************
*** 301,305 ****
# Flash a popup window indicating copying is done
! popup_string="CD info not found!\nMust manually rename files\nwhen
finished ripping"
pop = AlertBox(text=popup_string)
--- 464,469 ----
# Flash a popup window indicating copying is done
! popup_string="CD info not found!\nMust manually rename files\n"\
! "when finished ripping"
pop = AlertBox(text=popup_string)
***************
*** 318,322 ****
return [artist, album, genre, song_names]
! # This function gets rid of the slash, '/', in a string, and replaces it with
join_string
def slash_split(self, string, join_string = '-'):
split_string= re.split(" \\/ ", string)
--- 482,488 ----
return [artist, album, genre, song_names]
!
! # This function gets rid of the slash, '/', in a string, and replaces it
! # with join_string
def slash_split(self, string, join_string = '-'):
split_string= re.split(" \\/ ", string)
***************
*** 328,335 ****
if (i == (len(split_string) - 1)):
rejoined_string += split_string[i]
! # if not at the last slash, keep adding to string the join_string
else :
rejoined_string += split_string[i] + join_string
! # If there are no slashes , then the list is only 1 element long and there
is nothing to do.
else:
rejoined_string = string
--- 494,502 ----
if (i == (len(split_string) - 1)):
rejoined_string += split_string[i]
! # if not at the last slash, keep adding to string the join_string
else :
rejoined_string += split_string[i] + join_string
! # If there are no slashes , then the list is only 1 element long and there
! # is nothing to do.
else:
rejoined_string = string
***************
*** 350,495 ****
pattern = j
try:
! # A few of the special characters get automatically converted to a
different char,
! # rather than what is passed in as repl
if (pattern == "\'"):
(new_string, num) = re.subn(pattern, "\\\'", new_string, count=0)
elif (pattern == '/'):
! (new_string, num) = re.subn(pattern, '\\\\', new_string,
count=0)
else:
(new_string, num) = re.subn(pattern, repl, new_string, count=0)
except:
print 'Error: Problem trying to call re.subn'
! return new_string
!
! class PluginInterface(plugin.ItemPlugin):
! """
! Freevo can now backup your audio CDs in .mp3, .ogg, or .wav format.
!
! To do so, the following variables need to be added to your local_conf.py:
!
! Directory that you want to backup your audio CD to.
! AUDIO_BACKUP_DIR = '/music/MP3'
!
! You can use any combination of the 4 variables below to create subdirectories,
! and filename of songs.
! The four variables are: genre, artist,album, and song.
! Whatever follows the last slash indicates how to create the filename.
! Everything before the last slash indicates the directory structure you would
! like to use -which will be appended to AUDIO_BACKUP_DIR.
! CD_RIP_PN_PREF= '%(genre)s/%(artist)s/%(album)s/%(song)s'
!
! This would give you something like:
! /music/MP3/metal/Metallica/And Justice For All/Blackened.mp3
! (or Blackened.wav, Blackened.ogg)
!
! Here is another example which includes the artist and album in the filename:
! CD_RIP_PN_PREF = '%(artist)s/%(artist)s - %(album)s - %(song)s'
! /music/MP3/Metallica/Metallica - And Justice For All - Blackened.mp3
!
! cdparanoia is used to rip the CD to your hard drive. The actual command that
! will be executed is stored in CDPAR_CMD.
! CDPAR_CMD = 'cdparanoia'
!
! Lame .mp3 encoding parameters:
! Lame is used for .mp3 encoding. The actual command that will be executed is
! stored in LAME_CMD
! LAME_CMD = 'lame'
!
! For ripping to .mp3 you can provide your own Lame encoder parameters for
! bitrate, algorithm, and various other lame options. Add your custom parameters
! in CD_RIP_LAME_OPTS.
! CD_RIP_LAME_OPTS = '--vbr-new'
!
! Ogg Encoding:
! Likewise for Ogg format, the command is as below, and you can add your own
! custom ogg encoding options.
! OGGENC_CMD ='oggenc'
! CD_RIP_OGG_OPTS = ' '
!
! To activate this plugin, add the following to local_conf.py:
! plugin.activate('audio.cdbackup')
!
! Finally, to actually backup an audio CD within Freeevo, when you are in the
! Music menu, highlight/choose a CD, then hit 'e' on keyboard or 'ENTER' on
! your remote control and you will be able to access the rip/backup menu.
!
! Here is a list of all the above mentioned parameters for simple cutting and
! pasting:
!
! #The following are for adding and configuring the CD Audio backup plugin:
! AUDIO_BACKUP_DIR = '/music/MP3'
!
! CD_RIP_PN_PREF= '%(genre)s/%(artist)s/%(album)s/%(song)s'
! CDPAR_CMD = 'cdparanoia'
!
! LAME_CMD = 'lame'
! CD_RIP_LAME_OPTS = '--vbr-new'
!
! #You can leave this out if you never use ogg and it won't show up in the
! #backup menu
! OGGENC_CMD ='oggenc'
! CD_RIP_OGG_OPTS = ' '
!
! #To activate the cdbackup plugin:
! plugin.activate('audio.cdbackup')
! """
! artist = ''
! album = ''
! song_names = []
! device = ''
!
! def actions(self, item):
! self.item = item
!
! try:
! if (self.item.display_type == 'audio'):
! self.device = self.item.devicename
! if DEBUG: print 'devicename = %s' %self.device
! return [ ( self.create_backup_menu, 'Rip the CD to the hard drive',
'Get CDs available for ripping') ]
! except:
! print 'Error: Item is not an AudioCD'
! return []
!
! def create_backup_menu(self, arg=None, menuw=None):
! mm_menu = self.create_backup_items(self.device, menuw=None)
! menuwidget.pushmenu(mm_menu)
! menuwidget.refresh()
!
! def create_backup_items(self, arg, menuw):
! items = []
!
! if config.LAME_CMD:
! items += [menu.MenuItem('Backup CD to hard drive in mp3 format',
! self.cd_backup_mp3, arg=arg)]
! if config.OGGENC_CMD:
! items += [menu.MenuItem('Backup CD to hard drive in Ogg format',
! self.cd_backup_ogg, arg=arg)]
! if config.FLAC_CMD:
! items += [menu.MenuItem('Backup CD to hard drive in FLAC format',
! self.cd_backup_flac, arg=arg)]
! items += [menu.MenuItem('Backup CD to hard drive in wav format',
! self.cd_backup_wav, arg=arg)]
!
! backupmenu = menu.Menu('CD Backup', items,
reload_func=self.create_backup_menu)
! rc.app(None)
! return backupmenu
!
! def cd_backup_wav(self, arg, menuw=None):
! device = arg
! rip_thread = main_backup_thread(device=device, rip_format='wav')
! rip_thread.start()
!
! def cd_backup_mp3(self, arg, menuw=None):
! device = arg
! rip_thread = main_backup_thread(device=device, rip_format='mp3')
! rip_thread.start()
!
! def cd_backup_ogg(self, arg, menuw=None):
! device = arg
! rip_thread = main_backup_thread(device=device, rip_format='ogg')
! rip_thread.start()
!
! def cd_backup_flac(self, arg, menuw=None):
! device = arg
! rip_thread = main_backup_thread(device=device, rip_format='flac')
! rip_thread.start()
--- 517,529 ----
pattern = j
try:
! # A few of the special characters get automatically converted to a
! # different char, rather than what is passed in as repl
if (pattern == "\'"):
(new_string, num) = re.subn(pattern, "\\\'", new_string, count=0)
elif (pattern == '/'):
! (new_string, num) = re.subn(pattern, '\\\\', new_string,
count=0)
else:
(new_string, num) = re.subn(pattern, repl, new_string, count=0)
except:
print 'Error: Problem trying to call re.subn'
! return new_string
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog