summaryrefslogtreecommitdiffstats
path: root/amarok/src/scripts/playlist2html/PlaylistServer.py
blob: 6d259fa94ef22e13feeed1010409ecab428ebd5d (plain)
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
#!/usr/bin/env python
# -*- coding: Latin-1 -*-

"""
 This scripts starts a small http-server that serves the current-playlist as
 HTML. Start it and point your browser to http://localhost:4773/

 Author: André Kelpe fs111 at web dot de
 License: GPL

"""
import http.server
import http.server
from Playlist import Playlist

# the port number to listen to
PORT = 4773


PLIST = None

class RequestHandler(http.server.SimpleHTTPRequestHandler):
    """We need our own 'RequestHandler, to handle the requests, that arrive at
    our server."""

    def do_GET(self):
        """Overwrite the do_GET-method of the super class."""
        self.send_response(200)
        self.send_header("content-type","text/html")
        self.end_headers()
        self.wfile.write(PLIST.toHtml())


def main():
    """main is the starting-point for our script."""
    global PLIST
    PLIST = Playlist()
    srv = http.server.HTTPServer(('',PORT),RequestHandler)
    srv.serve_forever()


if __name__ == "__main__":
    main()