This file is indexed.

/usr/lib/python2.7/dist-packages/radiotray/AudioPlayerGStreamer.py is in radiotray 0.7.3-6.

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
##########################################################################
# Copyright 2009 Carlos Ribeiro
#
# This file is part of Radio Tray
#
# Radio Tray 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 1 of the License, or
# (at your option) any later version.
#
# Radio Tray 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 Radio Tray.  If not, see <http://www.gnu.org/licenses/>.
#
##########################################################################
import sys, os
try:
    import gi
    gi.require_version("Gtk", "3.0")
    gi.require_version('Gst', '1.0')
except:
    pass
try:
    from gi.repository import Gtk
    from gi.repository import GObject
    GObject.threads_init()
    from gi.repository import Gst
    Gst.init(None)
except Exception as e:
    print e

from StreamDecoder import StreamDecoder
from lib.common import USER_AGENT
from events.EventManager import EventManager
from threading import Timer
import logging

class AudioPlayerGStreamer:

    def __init__(self, mediator, cfg_provider, eventManager):
        self.mediator = mediator
        self.eventManager = eventManager
        self.decoder = StreamDecoder(cfg_provider)
        self.playlist = []
        self.retrying = False

        self.log = logging.getLogger('radiotray')

        # init player
        self.log.debug("Initializing gstreamer...")
        self.souphttpsrc = Gst.ElementFactory.make("souphttpsrc", "source")
        self.souphttpsrc.set_property("user-agent", USER_AGENT)
		
        self.log.debug("Loading playbin...");
        self.player = Gst.ElementFactory.make("playbin", "player")
        fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
        self.player.set_property("video-sink", fakesink)

        #buffer size
        if(cfg_provider._settingExists("buffer_size")):
            bufferSize = int(cfg_provider.getConfigValue("buffer_size"))
            if (bufferSize > 0):
            
                self.log.debug("Setting buffer size to " + str(bufferSize))
                self.player.set_property("buffer-size", bufferSize)

        
        bus = self.player.get_bus()
        bus.add_signal_watch()
        bus.connect("message", self.on_message)

        self.log.debug("GStreamer initialized.")

    def start(self, uri):

        urlInfo = self.decoder.getMediaStreamInfo(uri)

        if(urlInfo is not None and urlInfo.isPlaylist()):
            self.playlist = self.decoder.getPlaylist(urlInfo)
            if(len(self.playlist) == 0):
                self.log.warn('Received empty playlist!')
                self.mediator.stop()
                self.eventManager.notify(EventManager.STATION_ERROR, {'error':"Received empty stream from station"})
            self.log.debug(self.playlist)
            self.playNextStream()

        elif(urlInfo is not None and urlInfo.isPlaylist() == False):
            self.playlist = [urlInfo.getUrl()]
            self.playNextStream()

        else:
            self.stop()
            self.eventManager.notify(EventManager.STATION_ERROR, {'error':"Couldn't connect to radio station"})
            

    def playNextStream(self):
        if(len(self.playlist) > 0):
            stream = self.playlist.pop(0)
            self.log.info('Play "%s"', stream)

            urlInfo = self.decoder.getMediaStreamInfo(stream)
            if(urlInfo is not None and urlInfo.isPlaylist() == False):
                self.playStream(stream)
            elif(urlInfo is not None and urlInfo.isPlaylist()):
                self.playlist = self.decoder.getPlaylist(urlInfo) + self.playlist
                self.playNextStream()
            elif(urlInfo is None):
                self.playNextStream()
        else:
            self.stop()
            self.eventManager.notify(EventManager.STATE_CHANGED, {'state':'paused'})
        self.mediator.updateVolume(self.player.get_property("volume"))


    def playStream(self, uri):
        self.player.set_property("uri", uri)
        self.player.set_state(Gst.State.PAUSED) # buffer before starting playback

    def stop(self):
        self.player.set_state(Gst.State.NULL)
        self.eventManager.notify(EventManager.STATE_CHANGED, {'state':'paused'})

    def volume_up(self, volume_increment):   
        self.player.set_property("volume", min(self.player.get_property("volume") + volume_increment, 1.0))
        self.mediator.updateVolume(self.player.get_property("volume"))

    def volume_down(self, volume_increment):
        self.player.set_property("volume", max(self.player.get_property("volume") - volume_increment, 0.0))
        self.mediator.updateVolume(self.player.get_property("volume"))

    def on_message(self, bus, message):
        t = message.type

        stru = message.get_structure()
        if(stru != None):
            name = stru.get_name()
            if(name == 'redirect'):
                self.log.info("redirect received")
                self.player.set_state(Gst.State.NULL)
                stru.foreach(self.redirect, None)

                

        if t == Gst.MessageType.EOS:
            self.log.debug("Received MESSAGE_EOS")
            self.player.set_state(Gst.State.NULL)
            self.playNextStream()
        elif t == Gst.MessageType.BUFFERING:
            percent = message.parse_buffering()
            if percent < 100:
                self.log.debug("Buffering %s" % percent)
                self.player.set_state(Gst.State.PAUSED)
            else:
                self.player.set_state(Gst.State.PLAYING)
        elif t == Gst.MessageType.ERROR:
            self.log.debug("Received MESSAGE_ERROR")
            self.player.set_state(Gst.State.NULL)
            err, debug = message.parse_error()
            self.log.warn(err)
            self.log.warn(debug)

            if(len(self.playlist)>0):
                self.playNextStream()
            else:
                self.eventManager.notify(EventManager.STATION_ERROR, {'error':debug})

        elif t == Gst.MessageType.STATE_CHANGED:
            oldstate, newstate, pending = message.parse_state_changed()
            self.log.debug(("Received MESSAGE_STATE_CHANGED (%s -> %s)") % (oldstate, newstate))

            if newstate == Gst.State.PLAYING:
                self.retrying = False
                station = self.mediator.getContext().station
                self.eventManager.notify(EventManager.STATE_CHANGED, {'state':'playing', 'station':station})
            elif oldstate == Gst.State.PLAYING and newstate == Gst.State.PAUSED:
                self.log.info("Received PAUSE state.")
                
                if self.retrying == False:
                    self.retrying = True
                    timer = Timer(20.0, self.checkTimeout)
                    timer.start()
                    self.eventManager.notify(EventManager.STATE_CHANGED, {'state':'paused'})
                    
            

        elif t == Gst.MessageType.TAG:

           taglist = message.parse_tag()

           #for (tag, value) in taglist.items():
           #    print "TT: " + tag + " - " + value

           (present, value) = taglist.get_string('title')

           if present:
               metadata = {}
               station = self.mediator.getContext().station
               metadata['title'] = value
               metadata['station'] = station

               self.eventManager.notify(EventManager.SONG_CHANGED, metadata)

           #if there is no song information, there's no point in triggering song change event
           #if('artist' in taglist.keys() or 'title' in taglist.keys()):
           #    station = self.mediator.getContext().station
           #    metadata = {}

           #    for key in taglist.keys():
           #        metadata[key] = taglist[key]

           #    metadata['station'] = station
           
           #    self.eventManager.notify(EventManager.SONG_CHANGED, metadata)

        return True

    def redirect(self, name, value, data):
        if(name == 'new-location'):
            self.start(value)
        return True


    def checkTimeout(self):
        self.log.debug("Checking timeout...")
        if self.retrying == True:
            self.log.info("Timed out. Retrying...")
            uri = self.player.get_property("uri")
            self.playStream(uri)
        else: 
            self.log.info("Timed out, but not retrying anymore")