3 # Simple PartyMode Upload Script
4 # Copyright (c) 2015 Clinton Ebadi <clinton@unknownlamer.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # fix weird characters (see erica's song)
20 # track uploads (overcomplicated version)
21 # - phone ip is hopefully good enough
22 # - track # of uses of asap/Next Please
23 # - track files we have queued (need at least next-please so we can queue those in order)
24 # track uploads (easy version)
25 # - dump timestamps into file (/tmp = cleared at reboot, no need to clear it manually probably)
26 # - sum up # of songs uploading in last N minutes
27 # - throttle asap position based on the number of songs being uploaded
28 # - e.g. no one in last PERIOD = go next, fuckton of people = asap just ain't working
31 # integrate better with native queue (if it existed...)
34 # - show playlist length, # of next/asap available, likely queue position
35 # - show upcoming songs (5? just next-please?)
36 # - - just use SSI + python virtual includes, seriously
43 from xbmcjson import XBMC
47 print "content-type: text/html\n\n"
49 music_dir
= "/srv/archive/incoming/stolen-moosic"
50 form
= cgi
.FieldStorage
()
52 # Evil: just run replaygain/mp3gain/metaflac on the file and hope one
53 # works instead of dealing with MIME. For now.
54 def attempt_rpgain
(file_name
):
55 subprocess
.call
(["/usr/bin/vorbisgain", "-q", file_name
])
56 subprocess
.call
(["/usr/bin/mp3gain", "-q", "-s", "i", file_name
])
57 subprocess
.call
(["/usr/bin/aacgain", "-q", "-s", "i", file_name
])
58 subprocess
.call
(["/usr/bin/metaflac", "--add-replay-gain", file_name
])
60 def save_uploaded_file
(form_field
, upload_dir
):
61 if form_field
not in form
:
62 print "<p>No file provided.</p>"
64 fileitem
= form
[form_field
]
65 fout
= file
(os
.path
.join(upload_dir
, fileitem
.filename
), 'wb')
66 fout
.write (fileitem
.value
)
68 return fileitem
.filename
70 song_name
= save_uploaded_file
("song", music_dir
)
72 print '<p><a href="upload.html">Upload another song</a></p>'
75 #with daemon.DaemonContext ():
76 attempt_rpgain
("{0}/{1}".format
(music_dir
, song_name
))
78 xbmc
= XBMC
("http://localhost:8080/jsonrpc")
80 # todo: use REMOTE_ADDR to limit how many asap requests a person can
81 # make in a time period
82 totalitems
= xbmc
.Playlist
.GetItems
(playlistid
=0)['result']['limits']['total']
83 playpos
= random
.randint
(1, totalitems
/ (1 if 'asap' not in form
else 3))
85 print xbmc
.Playlist
.Insert
(playlistid
=0, item
={"file": "{0}/{1}".format
(music_dir
, song_name
)}, position
=playpos
)
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)