Exemplo n.º 1
0
 def streamRequest(self, request, quality, forcequality = False):
     try:
         if not self.hasQuality(quality): #hasQuality() sets self._streams in case they are not there already, self._streams should be set up manually if this is removed
             return returnHTTPError(request, 404, "<html><body>Error stream quality %s not found</body></html>" % quality,
                                    debugprint="Bad quality param %s" %quality)
     except Exception as e:
         return returnHTTPError(request, 500, "<html><body>Error accesing the channel</body></html>",
                                debugprint="Error accessing the channel %s" %str(e))
     
     #if not self._streams:
         #try:
             #self._streams = self._channel.get_streams()
         #except Exception as e:
             #returnHTTPError(request, 404, "<html><body>Error retrieving the list of streams for this channel</body></html>",
             #                debugprint="Error getting stream list, %s" %str(e))
     
     if forcequality and self._streamQuality and self._streamQuality != quality:
         if self._fd:
             if hasattr(self._fd, "close"):
                 self._fd.close()
             self._fd = None
         self._stream = None
         self._streamQuality = None
     
     if not self._stream:
         try:
             self._beginStream(quality)
         except Exception as e:
             print 'DEBUG: Exception starting livestreamer stream: %s', str(e)
             self._reset_channel()
             self._server.removeChannel(self)
             return returnHTTPError(request, 404, "<html><body>%s</body></html>" %str(e),
                                    debugprint="Error creating fd: %s" %str(e))
     
     lsconsumer = LSConsumer(self, request)
     self._consumers.append(lsconsumer)
     
     request.setResponseCode(200)
     request.responseHeaders.setRawHeaders("content-type", ["video/raw"])
     
     d = lsconsumer.beginTransfer(self._buffer)
     d.addCallback(self._CBremoveConsumer)
     
     if len(self._consumers) <= 1:
         self._consumerSentData() #forcing initial read
     
     return server.NOT_DONE_YET
Exemplo n.º 2
0
 def _handleInfoRequest(self, request, info):
     print info
     if info == "qualitylist":
         try:
             url = self._handleURL(request.args)
         except NoURL:
             print 'NoURL'
             return returnHTTPError(request, 500, "<html><body>Error Missing URL parameter</body></html>")
         except (NoUserName, NoPassword):
             print 'NoLog'
             return returnHTTPError(request, 500, "<html><body>Error Missing login parameter</body></html>")
         
         try:
             channel = self._getChannel(url)
         except Exception as e:
             print 'Something channel'
             return returnHTTPError(request, 500, "<html><body>Could not find a channel with that url %s</body></html>" %url)
         
         try:
             qualities = channel.getChannelQualities()
         except Exception as e:
             print 'something qualities'
             return returnHTTPError(request, 500, "<html><body>Error accessing the streams of the channel</body></html>" %url)
         
         request.setResponseCode(200)
         request.responseHeaders.setRawHeaders("content-type", ["text/plain"])
         return "<html><body>%s</body></html>" %','.join(qualities)
     
     if info == 'playingquality':
         try:
             url = self._handleURL(request.args)
         except NoURL:
             return returnHTTPError(request, 500, "<html><body>Error Missing URL parameter</body></html>")
         except (NoUserName, NoPassword):
             return returnHTTPError(request, 500, "<html><body>Error Missing login parameter</body></html>")
         
         try:
             channel = channels[url]
         except KeyError:
             return returnHTTPError(request, 500, "<html><body>Channel is not connected</body></html>")
         
         if not channel.streamQuality:
             return returnHTTPError(request, 500, "<html><body>Channel is not connected</body></html>")
         
         request.setResponseCode(200)
         request.responseHeaders.setRawHeaders("content-type", ["text/plain"])
         return "<html><body>%s</body></html>" %channel.streamQuality
     
     else:
         return returnHTTPError(request, 500, "<html><body>Unknown info command %s</body></html>" %info)
Exemplo n.º 3
0
 def render_GET(self, request):
     request.responseHeaders.setRawHeaders("server", ["Livestreamer HTTP Server"])
     
     info = request.args and "info" in request.args and request.args["info"][0]
     if info:
         return self._handleInfoRequest(request, info)
     
     quality = request.args and "stream" in request.args and request.args["stream"][0]
     if not quality:
         quality = "best"
     
     try:
         url = self._handleURL(request.args)
     except NoURL:
         return returnHTTPError(request, 500, "<html><body>Error Missing URL parameter</body></html>",
                                debugprint="Wrong URL")
     except (NoUserName, NoPassword):
         return returnHTTPError(request, 500, "<html><body>Error Missing login parameter</body></html>",
                                debugprint="Wrong login parameters")
     
     print "Q:", quality
     print "U:", url
     
     try:
         channel = self._getChannel(url, checkquality=quality, add=True)
     except QualityNotFound:
         return returnHTTPError(request, 500, "<html><body>Channel has no stream with quality %s</body></html>" %quality,
                                debugprint='Quality not found')
     except Exception as e:
         return returnHTTPError(request, 500, "<html><body>Error accesing the channel</body></html>",
                                debugprint='Was not able to access the channel stream: %s' %str(e))
     
     change = request.args and "change" in request.args and request.args["change"][0]
     if change:
         return channel.streamStream(request, quality, forcequality = True)
     
     return channel.streamRequest(request, quality)