Commit | Line | Data |
---|---|---|
b61367d1 | 1 | #!/usr/bin/python3 |
51a600c2 CE |
2 | # Simple PartyMode Web Console |
3 | # Copyright (c) 2015,2016 Clinton Ebadi <clinton@unknownlamer.org> | |
a823df94 CE |
4 | # This program is free software: you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | ||
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | ||
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | # todo: | |
18 | # fix weird characters (see erica's song) | |
51a600c2 CE |
19 | # use shutil.copyfileobj to possibly speed up copying |
20 | # - check if it actually causes chunked reads from the browser | |
21 | # - LOL WHAT uploads are like 10s don't bother | |
22 | # support multiple files | |
23 | # - daemonize replaygain? NOPE it runs in like no time thanks to moar power | |
a823df94 CE |
24 | # track uploads (overcomplicated version) |
25 | # - phone ip is hopefully good enough | |
26 | # - track # of uses of asap/Next Please | |
27 | # - track files we have queued (need at least next-please so we can queue those in order) | |
28 | # track uploads (easy version) | |
29 | # - dump timestamps into file (/tmp = cleared at reboot, no need to clear it manually probably) | |
30 | # - sum up # of songs uploading in last N minutes | |
31 | # - throttle asap position based on the number of songs being uploaded | |
32 | # - e.g. no one in last PERIOD = go next, fuckton of people = asap just ain't working | |
33 | ||
34 | ||
51a600c2 CE |
35 | # integrate better with native queue |
36 | ||
37 | ||
38 | ## crazy idea: if the playlist can be watched with a script... (maybe | |
39 | ## a json rpc notification? but ... reliability, and upload.cgi runs | |
40 | ## infrequently enough that it cannot record the playlist and extract | |
41 | ## a meaningful image of the queue ...). | |
42 | ||
43 | # diff playlist whenever item is inserted (or song changes, or whatever we can hook on). | |
44 | # scan for common items (discarding the head of the old snapshot, since we could just be advancing) | |
45 | # when the first different item is found... if it ain't the end of the list it's been queued | |
46 | # keep going until we match up again and record the end of the queue position in a file | |
47 | # what about when we delete in the list? | |
48 | # | |
a823df94 CE |
49 | |
50 | # upload.html | |
51 | # - show playlist length, # of next/asap available, likely queue position | |
52 | # - show upcoming songs (5? just next-please?) | |
53 | # - - just use SSI + python virtual includes, seriously | |
54 | ||
55 | import cgi, cgitb | |
56 | import os, sys | |
57 | import daemon | |
58 | import subprocess | |
59 | import random | |
b61367d1 | 60 | from kodijson import Kodi |
a823df94 | 61 | |
51a600c2 CE |
62 | import partyparty |
63 | from partyparty import Upload, PartyManager | |
64 | ||
a823df94 CE |
65 | cgitb.enable() |
66 | ||
67 | print "content-type: text/html\n\n" | |
51a600c2 | 68 | sys.stdout.flush () |
a823df94 | 69 | |
a823df94 CE |
70 | form = cgi.FieldStorage () |
71 | ||
51a600c2 | 72 | manager = PartyManager (form) |
a823df94 CE |
73 | |
74 | print '<p><a href="upload.html">Upload another song</a></p>' | |
75 | sys.stdout.flush () | |
76 | ||
b61367d1 | 77 | xbmc = partyparty.connect (Kodi ("http://localhost:8080/jsonrpc")) |
51a600c2 | 78 | manager.randomqueue ({"file": filename}, 1 if 'asap' not in form else 3) |
a823df94 CE |
79 | |
80 | # todo: use REMOTE_ADDR to limit how many asap requests a person can | |
81 | # make in a time period | |
51a600c2 CE |
82 | #totalitems = xbmc.Playlist.GetItems (playlistid=0)['result']['limits']['total'] |
83 | #playpos = random.randint (1, totalitems / (1 if 'asap' not in form else 3)) | |
a823df94 | 84 | |
51a600c2 | 85 | #print xbmc.Playlist.Insert (playlistid=0, item={"file": filename }, position=playpos) |
a823df94 | 86 | |
51a600c2 | 87 | #print '<p style="font-size: x-large">Your song is number {0} in the queue ({1} songs in playlist).</p>'.format (playpos, totalitems+1) |