def handler(self, context): import HaloRadio.Util as Util if self.form.has_key("songids"): songids = self.form['songids'] else: self.do_error("must request at least one song") list = [] try: for obj in songids: list.append(int(obj.value)) except: list.append(int(songids.value)) num_errors = 0 error_string = "" for sid in list: try: r = Request.Request(0, sid, self.session.userid) except HaloException.RequestOverQuota, value: num_errors = num_errors + 1 s = Song.Song(sid) error_string = "%s\n[%s failed, over quota]" % ( error_string, s.GetDisplayName()) except HaloException.RequestOverPlayed, value: num_errors = num_errors + 1 s = Song.Song(sid) error_string = "%s\n[%s failed, over played]" % ( error_string, s.GetDisplayName())
def handler(self, context): import HaloRadio.SongListMaker as SongListMaker import HaloRadio.Song as Song if self.form.has_key("num"): num = int(self.form['num'].value) else: num = 25 if self.form.has_key("days"): days = int(self.form['days'].value) else: days = 7 context.addGlobal("num", num) context.addGlobal("days", days) slm = SongListMaker.SongListMaker() slm.GetTopRequestsForTime(num, days) songs = [] for songid in slm.list: try: song = Song.Song(songid) entity = {} entity['songlink'] = "%s?action=songInfo&id=%s" % ( self.config['general.cgi_url'], song.id) entity['songname'] = song.GetDisplayName() entity['recent_plays'] = song.GetNumRecentRequests(days) songs.append(entity) except: pass context.addGlobal("songlist", songs)
def GetRandomSong( self ): import HaloRadio.Song as Song self.GetList() if len(self.list) < 1: import HaloRadio.Exception as Exception raise Exception.PlaylistEmpty, self.id song = Song.Song(self.list[random.randint(0,len(self.list)- 1)]) return song
def clean_db(verbose=0): slm = SongListMaker.SongListMaker() slm.GetAll() for songid in slm.list: song = Song.Song(songid) if (os.access(arc_root + "/" + song.path, os.R_OK) == 0): song.Delete() print "#Deleted", song.path, "from the database"
def handler(self, context): if self.form.has_key("id"): songid = self.form['id'].value else: raise "songInfo without an id, duh!" s = Song.Song(songid) context.addGlobal("sngname", s.GetDisplayName()) context.addGlobal("path", s.path) context.addGlobal("id3artist", s.artist) context.addGlobal("id3album", s.album) context.addGlobal("id3track", s.track) context.addGlobal("id3title", s.GetDisplayName()) context.addGlobal("id3genre", s.genre) context.addGlobal("id3year", s.year) context.addGlobal("id3comment", s.comment) context.addGlobal("mime", s.mime) context.addGlobal("sample", s.samplerate) context.addGlobal("length", s.GetDisplayLength()) context.addGlobal("requests", s.requests) context.addGlobal("plays", s.plays) context.addGlobal("kills", s.kills) context.addGlobal( "requesturl", "%s?action=request&songids=%s" % (self.config['general.cgi_url'], s.id)) context.addGlobal( "downloadurl", "%s/%s" % (self.config['general.download_url'], s.path)) import HaloRadio.UserSongStatsListMaker as UserSongStatsListMaker import HaloRadio.UserSongStats as UserSongStats import HaloRadio.User as User usslm = UserSongStatsListMaker.UserSongStatsListMaker() usslm.GetBySong(s.id) killedby = [] requestedby = [] for ussid in usslm.list: uss = UserSongStats.UserSongStats(ussid) try: user = User.User(uss.userid) username = user.GetDisplayName() except: username = "******" if uss.kills > 0: kentity = {} kentity['name'] = username kentity['num'] = uss.kills killedby.append(kentity) if uss.requests > 0: rentity = {} rentity['name'] = username rentity['num'] = uss.requests requestedby.append(rentity) context.addGlobal("killedby", killedby) context.addGlobal("requestedby", requestedby)
def handler(self, context): import HaloRadio.SongListMaker as SongListMaker import HaloRadio.Song as Song slm = SongListMaker.SongListMaker() slm.GetWhere("", "added_date DESC LIMIT 256") songs = [] for songid in slm.list: song = Song.Song(songid) entity = {} entity['songlink'] = "%s?action=songInfo&id=%s" % ( self.config['general.cgi_url'], song.id) entity['songname'] = song.GetDisplayName() entity['date_added'] = song.added_date songs.append(entity) context.addGlobal("songlist", songs)
def handler(self, context): import HaloRadio.SongListMaker as SongListMaker import HaloRadio.Song as Song slm = SongListMaker.SongListMaker() slm.GetTopRank(100) songs = [] for songid in slm.list: song = Song.Song(songid) entity = {} entity['songlink'] = "%s?action=songInfo&id=%s" % ( self.config['general.cgi_url'], song.id) entity['songname'] = song.GetDisplayName() entity['requests'] = song.requests entity['kills'] = song.kills songs.append(entity) context.addGlobal("songlist", songs)
def GetRandomSongForUsers(self, useridlist): import HaloRadio.Song as Song wheres = [] for userid in useridlist: wheres.append(" userid = \"%s\" " % userid) query = """SELECT SUM(requests) as requests, SUM(kills) as kills, (rand()*100) as rank, songid FROM %s WHERE %s GROUP BY songid HAVING requests > kills ORDER BY rank DESC LIMIT 1;""" % ( self.tablename, " OR ".join(wheres)) try: ((requests, kills, rank, songid), ) = self.do_my_query(query) except ValueError: raise HaloException.SongNotExistant try: song = Song.Song(songid) except HaloException.SongNotFound, snf: song = self.GetRandomSongForUsers(useridlist)
def GetRandomSong(self): import HaloRadio.Song as Song import HaloRadio.Exception as HaloException import HaloRadio.UserSongStatsListMaker as UserSongStatsListMaker usslm = UserSongStatsListMaker.UserSongStatsListMaker() usslm.GetRandomSong(self.id) if len(usslm.list) == 1: try: song = Song.Song(usslm.list[0]) except HaloException.SongNotFound, snf: import HaloRadio.UserSongStats as UserSongStats usslm.GetBySong(snf.id) for ussid in usslm.list: uss = UserSongStats.UserSongStats(ussid) uss.Delete() song = self.GetRandomSong()
def do_scan_scale(): r = re.compile('(\d+\.\d+)') all_songs = SongListMaker.SongListMaker() all_songs.GetAll() for songid in all_songs.list: song = Song.Song(songid) if song.scale == 0: print "* %s : " % (song.path), cmd = "nice sox \"%s/%s\" -t null /dev/null stat -v 2>&1" % ( arc_root, song.path) stat_stdout = os.popen( cmd, 'r', ) stat_out = stat_stdout.readline() while stat_out != '': m = r.match(stat_out) if m: song.UpdateScale(m.group(1)) print m.group(1) stat_out = stat_stdout.readline() stat_stdout.close()
sys.exit() if o in ("-i", "--ids"): ids = a.split(",") if o in ("-s", "--search"): search = a if o in ("-r", "--replace"): replace = a print "%s %s %s" % (ids, search, replace) if (search == None) or (replace == None): usage() import HaloRadio if ids == None: import HaloRadio.SongListMaker as SongListMaker slm = SongListMaker.SongListMaker() slm.GetAll() ids = slm.list import HaloRadio.Song as Song for sid in ids: s = Song.Song(sid) pos = s.path.find(search) if pos == -1: continue print "Matched %s." % (s.GetDisplayName()) s.UpdatePath(s.path.replace(search, replace)) print "Updated to %s." % (s.path) print " done."
def process_dir(dir, subroot, verbose=1, dry_run=1): from mutagen import File filestr = "find %s/%s -follow -type f -name \"*.mp3\" " % (arc_root, dir) #print filestr files = os.popen(filestr) line_in = files.readline() while (line_in != ""): file = line_in[:-1] # chomp the \n line_in = files.readline() # grab the next line path = file[arc_len:] # cut the root off the filename # Check to see if this file is in the log_message(verbose, "file_in: %s" % (path)) songlist = SongListMaker.SongListMaker() try: songlist.SearchPath(path) except: log_message(verbose, "ERR-NTFND: %s" % (path)) continue if (len(songlist.list) > 1): for sid in songlist.list: song = Song.Song(sid) print "ERR-DUPE:%d:%s" % (sid, song.path) continue #print file song = Song.Song(songlist.list[0]) ## move files.. fn_artist = make_fn_string(song.artist) fn_album = make_fn_string(song.album) fn_title = make_fn_string(song.title) log_message(verbose, "fn:%s:%s:%s" % (fn_artist, fn_album, fn_title)) if fn_album == "": if fn_artist == "" or fn_title == "": print "#Skipping: ", song.path continue new_path = "%s/%s/%s---%s.mp3" % (subroot, fn_artist, fn_artist, fn_title) elif song.track == 0: new_path = "%s/%s/%s/%s-%s--%s.mp3" % ( subroot, fn_artist, fn_album, fn_artist, fn_album, fn_title) else: new_path = "%s/%s/%s/%s-%s-%02d-%s.mp3" % ( subroot, fn_artist, fn_album, fn_artist, fn_album, song.track, fn_title) if new_path != song.path: log_message( verbose, "nf:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s" % (song.artist, song.album, song.title, song.track, song.genre, song.comment, song.year, song.mime, song.samplerate, song.length)) new_dir = os.path.dirname(new_path) if dry_run == 0: if os.path.exists("%s/%s" % (arc_root, new_dir)) == False: if os.system("mkdir -pv %s/%s" % (arc_root, new_dir)) != 0: os.exit() log_message(verbose, "mv:%s:%s" % (song.path, new_path)) if os.system("mv -v %s/\"%s\" %s/%s" % (arc_root, shell_escape_string( song.path), arc_root, new_path)) != 0: os.exit() song.UpdatePath(new_path) else: print "mv:%s:%s" % (song.path, new_path) else: print "mv:path unchanged"
def handler(self, context): import HaloRadio.UserSongStatsListMaker as UserSongStatsListMaker import HaloRadio.UserSongStats as UserSongStats import HaloRadio.Song as Song import HaloRadio.User as User import HaloRadio.Exception as Exception # Username if self.form.has_key("id"): userid = int(self.form['id'].value) #if ( userid != self.user.id and # not self.do_authorize(self.user.rights,"am") #): # self.do_error("Unautherized") else: userid = self.user.id if self.form.has_key("numtop"): numtop = int(self.form['numtop'].value) else: numtop = 25 if self.form.has_key("numbottom"): numbottom = int(self.form['numbottom'].value) else: numbottom = 25 user = User.User(userid) context.addGlobal("numtop", numtop) context.addGlobal("numbottom", numbottom) context.addGlobal("id", userid) context.addGlobal("action", "userInfo") context.addGlobal("username", user.GetDisplayName()) context.addGlobal("rights", user.GetDisplayRights()) context.addGlobal("createdate", user.create_time) seen = user.LastSeen() if not seen: seen = user.create_time context.addGlobal("seendate", seen) # Return my top 100 slm = UserSongStatsListMaker.UserSongStatsListMaker() slm.GetTopRank(user.id, numtop) songs = [] for (songid, requests, kills) in slm.list: try: song = Song.Song(songid) except Exception.SongNotFound: continue entity = {} entity['songlink'] = "%s?action=songInfo&id=%s" % ( self.config['general.cgi_url'], song.id) entity['songname'] = song.GetDisplayName() entity['requests'] = requests entity['kills'] = kills songs.append(entity) context.addGlobal("songlist", songs) slm.GetBottomRank(user.id, numbottom) songs2 = [] for (songid, kills, requests) in slm.list: try: song = Song.Song(songid) except Exception.SongNotFound: continue entity = {} entity['songlink'] = "%s?action=songInfo&id=%s" % ( self.config['general.cgi_url'], song.id) entity['songname'] = song.GetDisplayName() entity['requests'] = requests entity['kills'] = kills songs2.append(entity) context.addGlobal("bsonglist", songs2)
# This file is part of halo_radio # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. """ This is a simple script to list all the songs in your database. """ import HaloRadio import HaloRadio.Song as Song import HaloRadio.SongListMaker as SongListMaker sl = SongListMaker.SongListMaker() sl.GetAll() for id in sl.list: s = Song.Song(id) print "%d | %s" % (s.id, s.GetDisplayName()) print "%d records listed." % len(sl.list)
def GetSong( self, index ): import HaloRadio.Song as Song song = Song.Song(self.list[index]) return song
import HaloRadio.UserListMaker as UserListMaker ulm = UserListMaker.UserListMaker() ulm.GetAll() print "system users :" for ulid in ulm.list: u = User.User(ulid) print " %d: %s" % (ulid, u.GetDisplayName()) sys.exit(1) elif playlist != 0: import HaloRadio.Playlist as Playlist import HaloRadio.Song as Song cur_playlist = Playlist.Playlist(playlist) cur_playlist.GetList() for i in cur_playlist.list: s = Song.Song(i) print "%s/%s" % (HaloRadio.conf['path.root'], s.path) elif user != 0: import HaloRadio.UserListMaker as UserListMaker import HaloRadio.UserSongStatsListMaker as UserSongStatsListMaker import HaloRadio.UserSongStats as UserSongStats import HaloRadio.User as User import HaloRadio.Song as Song ulm = UserListMaker.UserListMaker() usslm = UserSongStatsListMaker.UserSongStatsListMaker() ulm.GetByName(user) try:
def GetSong(self): import HaloRadio.Song as Song song = Song.Song(self.songid) return song
def update_db(slow, verbose=0): from mutagen import File cfg = Config.Config() timenow = time.time() #print "timenow %s" % timenow if slow: #filestr = "find %s -follow -type f -name \"*.mp3\" " % ( arc_root ) filestr = "find %s -follow -type f " % (arc_root) else: try: lastupdatesecs = float(cfg.GetConfigItem("lastupdate")) except: lastupdatesecs = 0 #print "lastupdatesecs %s" % lastupdatesecs timediff = timenow - lastupdatesecs #print "timediff %s" % timediff #filestr = "find %s -type f -cmin -%d -name \"*.mp3\"" % ( arc_root, (timediff/60)+1 ) filestr = "find %s -type f -cmin -%d " % (arc_root, (timediff / 60) + 1) cfg.SetConfigItem("lastupdate", str(timenow)) #print filestr files = os.popen(filestr) line_in = files.readline() while (line_in != ""): file = line_in[:-1] # chomp the \n line_in = files.readline() # grab the next line path = file[arc_len:] # cut the root off the filename # Check to see if this file is in the #log_message( verbose, "file_in: %s" % ( path ) ) songlist = SongListMaker.SongListMaker() try: songlist.SearchPath(path) except: log_message(verbose, "error searching db for: %s" % (path)) continue if (len(songlist.list) > 1): for sid in songlist.list: song = Song.Song(sid) print "#%d:%s" % (sid, song.path) raise "you got a problem here." #print file try: nfo = File(file) except AttributeError: print "%s:- Unknown file type" % (file) except KeyboardInterrupt: raise except Exception, err: print "%s:%s" % (file, str(err)) try: samplerate = float(nfo.info.sample_rate) except: print "#Invalid MPEG samplerate:", file continue try: length = float(nfo.info.length) except: print "#Invalid MPEG length:", file continue try: mime = nfo.mime[0] except: print "#Invalid mime/type:", file continue if nfo.tags != None: if nfo.tags.has_key('TPE1'): artist = nfo.tags['TPE1'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('artist'): artist = nfo.tags['artist'][0].encode('ascii', 'replace') else: artist = "" if nfo.tags.has_key('TALB'): album = nfo.tags['TALB'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('album'): album = nfo.tags['album'][0].encode('ascii', 'replace') else: album = "" if nfo.tags.has_key('TIT1'): title = nfo.tags['TIT1'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('TIT2'): title = nfo.tags['TIT2'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('title'): title = nfo.tags['title'][0].encode('ascii', 'replace') else: title = "" if nfo.tags.has_key('TRCK'): track = nfo.tags['TRCK'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('tracknumber'): track = nfo.tags['tracknumber'][0].encode('ascii', 'replace') else: track = "0" if not track.find("/") == -1: pos = track.find("/") track = int(track[0:pos]) else: track = int(track) if nfo.tags.has_key('TCON'): genre = nfo.tags['TCON'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('genre'): genre = nfo.tags['genre'][0].encode('ascii', 'replace') else: genre = "" if nfo.tags.has_key('TDRC'): year = nfo.tags['TDRC'].text[0].encode('ascii', 'replace') elif nfo.tags.has_key('date'): year = nfo.tags['date'][0].encode('ascii', 'replace') else: year = "" comment = "" else: artist = "" album = "" title = "" track = 0 genre = "" year = "" comment = "" #print "%s %s %s %s %s %s"%(artist,album, title, track, genre, year) if (len(songlist.list) > 0): song = Song.Song(songlist.list[0]) if (song.artist == artist ) and (song.album == album) and (song.title == title) and (int( song.track) == int(track)) and (song.genre == genre) and ( song.comment == comment) and (song.year == year) and ( song.mime == mime) and (int( song.samplerate) == int(samplerate)) and (int( song.length) == int(length)): continue else: log_message( verbose, "fl:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s" % (artist, album, title, track, genre, comment, year, mime, samplerate, length)) log_message( verbose, "db:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s" % (song.artist, song.album, song.title, song.track, song.genre, song.comment, song.year, song.mime, song.samplerate, song.length)) print "#Updating", path song.Update(artist, album, title, track, genre, comment, year, mime, samplerate, length) continue print "#Adding", path song = Song.Song(0, path, artist, album, title, track, genre, comment, year, mime, samplerate, length) log_message( verbose, "ad:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s" % (song.artist, song.album, song.title, song.track, song.genre, song.comment, song.year, song.mime, song.samplerate, song.length))