__author__ = 'rvb'
'''
Local Playlist Plugin
(based on ytv plugin by ValdikSS)

plsylist index

http://ip:port/index

m3u playlists

http://ip:port/m3u
http://ip:port/m3u/
http://ip:port/m3u/list-name

plain-tet channel names

http://ip:port/list
http://ip:port/list/
http://ip:port/list/list-name

forward to player

http://ip:port/play/channel-name
http://ip:port/play/list-name/channel-name
http://ip:port/play/{list-name}/(get|mp4|webm)/channel-name

'''
import logging
import gc
from modules.PluginInterface import VPProxyPlugin
import os
from guppy import hpy
h = hpy()

class Debug(VPProxyPlugin):

    handlers = ('debug',)

    logger = logging.getLogger('mem_debug')

    def handle(self, connection):

        connection.send_response(200)
        connection.send_header('Content-Type', 'text/plain')
        connection.end_headers()
        
        gc.set_debug(gc.DEBUG_LEAK)

        connection.wfile.write('{} objects collected\n'.format(gc.collect()))

        connection.wfile.write(h.heap())

    def getparam(self, key):
        if key in self.params:
            return self.params[key][0]
        else:    
            return None
                                            
                                            