/usr/lib/exaile/xl/player/queue.py is in exaile 0.3.2.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # Copyright (C) 2008-2010 Adam Olsen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# The developers of the Exaile media player hereby grant permission
# for non-GPL compatible GStreamer and Exaile plugins to be used and
# distributed together with GStreamer and Exaile. This permission is
# above and beyond the permissions granted by the GPL license by which
# Exaile is covered. If you modify this code, you may extend this
# exception to your version of the code, but you are not obligated to
# do so. If you do not wish to do so, delete this exception statement
# from your version.
import logging
try:
import cPickle as pickle
except:
import pickle
from xl import playlist, settings, event, common
logger = logging.getLogger(__name__)
class PlayQueue(playlist.Playlist):
"""
Manages the queue of songs to be played
"""
def __init__(self, player, location=None):
self.current_playlist = None
self.current_pl_track = None
playlist.Playlist.__init__(self, name="Queue")
self.player = player
player._set_queue(self)
self.stop_track = None
if location is not None:
self.load_from_location(location)
def set_current_playlist(self, playlist):
self.current_playlist = playlist
def set_current_pl_track(self, track):
self.current_pl_track = track
def peek(self):
track = playlist.Playlist.peek(self)
if track == None:
if self.current_playlist:
track = self.current_playlist.peek()
return track
def next(self, player=True, track=None):
"""
Goes to the next track, either in the queue, or in the current
playlist. If a track is passed in, that track is played
:param player: play the track in addition to returning it
:param track: if passed, play this track
"""
if not track:
if self.player.current and self.player.current == self.stop_track:
self.player.stop()
event.log_event('stop_track', self, self.stop_track)
self.stop_track = None
return None
if not self.ordered_tracks:
if self.current_playlist:
track = self.current_playlist.next()
self.current_playlist.current_playing = True
self.current_playing = False
else:
track = self.ordered_tracks.pop(0)
self.current_pos = 0
self.current_playing = True
if self.current_playlist:
self.current_playlist.current_playing = False
if player:
if not track:
self.player.stop()
event.log_event("playback_playlist_end", self,
self.current_playlist)
return
self.player.play(track)
if not track:
event.log_event("playback_playlist_end", self,
self.current_playlist)
return track
def prev(self):
track = None
if self.player.current:
if self.player.get_time() < 5:
if self.current_playlist:
track = self.current_playlist.prev()
else:
track = self.player.current
else:
track = self.get_current()
self.player.play(track)
return track
def get_current(self):
if self.player.current and self.current_pos > 0:
current = self.player.current
else:
current = playlist.Playlist.get_current(self)
if current == None and self.current_playlist:
current = self.current_playlist.get_current()
return current
def get_current_pos(self):
return 0
def play(self, track=None):
"""
start playback, either from the passed track or from already
queued tracks
"""
if self.player.is_playing() and not track:
return
if not track:
track = self.get_current()
if track:
self.player.play(track)
if track in self.ordered_tracks:
self.ordered_tracks.remove(track)
else:
self.next()
def _save_player_state(self, location):
state = {}
state['state'] = self.player.get_state()
state['position'] = self.player.get_time()
state['_playtime_stamp'] = self.player._playtime_stamp
f = open(location, 'wb')
pickle.dump(state, f, protocol = 2)
f.close()
@common.threaded
def _restore_player_state(self, location):
if not settings.get_option("player/resume_playback", True):
return
try:
f = open(location, 'rb')
state = pickle.load(f)
f.close()
except:
return
for req in ['state', 'position', '_playtime_stamp']:
if req not in state:
return
if state['state'] in ['playing', 'paused']:
event.log_event("playback_player_resume", self.player, None)
vol = self.player._get_volume()
self.player._set_volume(0)
self.play()
if self.player.current:
self.player.seek(state['position'])
if state['state'] == 'paused' or \
settings.get_option("player/resume_paused", False):
self.player.toggle_pause()
self.player._playtime_stamp = state['_playtime_stamp']
self.player._set_volume(vol)
|