1
# Copyright (C) 2006 Adam Olsen
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 1, or (at your option)
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
import subprocess, logging, os
18
from xl import event, xdg
19
from xl.nls import gettext as _
20
from xl import settings
21
from xlgui import guiutil
25
# trying to not rely on the gui parts of exaile
27
from xlgui import commondialogs
31
logger = logging.getLogger(__name__)
35
STREAMRIPPER_PID = None
36
STREAMRIPPER_OUT = None
42
def toggle_record(widget=None, event=None):
43
global STREAMRIPPER_PID, CURRENT_TRACK, STREAMRIPPER_OUT
47
track = APP.player.current
49
if not STREAMRIPPER_PID:
50
if not track: return True
52
logger.warning('Streamripper can only record streams')
54
commondialogs.error(APP.gui.main.window, _('Streamripper '
55
'can only record streams.'))
58
savedir = settings.get_option(
59
'plugin/streamripper/save_location',
63
port = int(settings.get_option(
64
'plugin/streamripper/relay_port', 8888))
68
outfile = "%s/streamripper.log" % xdg.get_config_dir()
69
STREAMRIPPER_OUT = open(outfile, "w+", 0)
70
STREAMRIPPER_OUT.write("Streamripper log file started: %s\n" %
71
time.strftime("%c", time.localtime()))
72
STREAMRIPPER_OUT.write(
73
"-------------------------------------------------\n\n\n")
76
APP.player.playbin.set_state(gst.STATE_NULL)
77
sub = subprocess.Popen(['streamripper',
78
APP.player.playbin.get_property('uri'), '-r',
79
str(port), '-d', savedir], stdout=STREAMRIPPER_OUT)
82
logger.info("Using streamripper to play location: %s" % track['__loc'])
85
logger.warning('There was an error executing streamripper')
87
commondialogs.error(APP.gui.main.window, _("Error "
88
"executing streamripper"))
91
STREAMRIPPER_PID = sub.pid
92
logger.info("Proxy location: http://localhost:%d" % port)
93
APP.player.playbin.set_property('uri', 'http://localhost:%d' % port)
96
APP.player.playbin.set_state(gst.STATE_PLAYING)
101
os.system('kill -9 %d' % STREAMRIPPER_PID)
102
APP.player.playbin.set_state(gst.STATE_READY)
103
APP.player.playbin.set_property('uri', track['__loc'])
105
APP.player.playbin.set_state(gst.STATE_PLAYING)
106
STREAMRIPPER_PID = None
109
STREAMRIPPER_OUT.close()
115
def playback_stop(type, player, object):
116
global STREAMRIPPER_OUT, STREAMRIPPER_PID
118
BUTTON.set_active(False)
122
STREAMRIPPER_OUT.close()
125
STREAMRIPPER_OUT = None
128
os.system("kill -9 %d" % STREAMRIPPER_PID)
129
STREAMRIPPER_PID = None
131
def initialize(type, exaile, stuff=None):
136
# if the gui is available, add the record button
140
BUTTON = gtk.ToggleButton()
141
BUTTON.connect('button-release-event', toggle_record)
143
image.set_from_stock('gtk-media-record', gtk.ICON_SIZE_SMALL_TOOLBAR)
144
BUTTON.set_image(image)
146
toolbar = exaile.gui.play_toolbar
147
toolbar.pack_start(BUTTON, False, False)
148
toolbar.reorder_child(BUTTON, 3)
152
event.add_callback(playback_stop, 'playback_player_end',
157
Enables the streamripper plugin
160
subprocess.call(['streamripper'], stdout=-1, stderr=-1)
162
raise NotImplementedError('Streamripper is not available.')
166
event.add_callback(initialize, 'exaile_loaded', exaile)
168
initialize(None, exaile)
174
exaile.gui.play_toolbar.remove(BUTTON)
180
event.remove_callback(playback_stop, 'playback_player_end',