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 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 make_announce_playlist(): playlists = PlaylistListMaker.PlaylistListMaker() playlists.GetWhere("name='Announce'") try: playlist = Playlist.Playlist(playlists.Pop()) except: playlist = Playlist.Playlist(0, "Announce") playlist.Clear() slm = SongListMaker.SongListMaker() slm.GetWhere("""path LIKE "%s%%" """ % (HaloRadio.conf['general.announce_path'])) for songid in slm.list: playlist.AddSong(songid)
def make_smart_auto_playlist(): playlists = PlaylistListMaker.PlaylistListMaker() playlists.GetWhere("name='AutoAI'") try: playlist = Playlist.Playlist(playlists.Pop()) except: playlist = Playlist.Playlist(0, "AutoAI") playlist.Clear() reqested_songs = SongListMaker.SongListMaker() reqested_songs.GetWhere("requests > kills") for songid in reqested_songs.list: playlist.AddSong(songid)
def make_request_playlist(): playlists = PlaylistListMaker.PlaylistListMaker() playlists.GetWhere("name='Requested'") try: playlist = Playlist.Playlist(playlists.Pop()) except: playlist = Playlist.Playlist(0, "Requested") playlist.Clear() reqested_songs = SongListMaker.SongListMaker() reqested_songs.GetWhere("requests > 0") for songid in reqested_songs.list: playlist.AddSong(songid)
def make_master_playlist(): playlists = PlaylistListMaker.PlaylistListMaker() playlists.GetWhere("name='Master'") try: playlist = Playlist.Playlist(playlists.Pop()) except: playlist = Playlist.Playlist(0, "Master") # delete any songs from playlist 1 playlist.Clear() # add all songs to playlist 1 all_songs = SongListMaker.SongListMaker() all_songs.GetAll() for songid in all_songs.list: playlist.AddSong(songid)
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 handler(self, context): import HaloRadio.Util as Util if self.form.has_key("search"): search = self.form['search'].value else: search = "GAWDthisISghettoBUTkindaCONSISTANT" import HaloRadio.SongListMaker as SongListMaker slm = SongListMaker.SongListMaker() slm.SubSearch( search, order="popular" ) if len(slm.list) > 0: r = Request.Request( 0, slm.list[0], self.session.userid ) else: self.do_error("search (%s), not popular enough..."% (search) ) request_url = "%s?action=RequestQueue" % ( self.config['general.cgi_url'] ) context.addGlobal ("refresh", "0;URL=%s" % ( request_url ) ) context.addGlobal ("requesturl", request_url )
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 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))
# 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 handler(self, context): pageappend = "" recent = 0 if self.form.has_key("search"): searchstring = self.form['search'].value else: searchstring = "NOTHINGwillMATCHthis" if self.form.has_key("offset"): offset = int(self.form['offset'].value) else: offset = 0 if self.form.has_key("limit"): limit = int(self.form['limit'].value) else: limit = 15 if self.form.has_key("sort"): sort = self.form['sort'].value pageappend += "&sort=%s" % sort else: sort = "popularity" if self.form.has_key("type"): type_input = self.form['type'].value pageappend += "&type=%s" % type_input else: type_input = "both" if self.form.has_key("userlogic"): userlogic_input = self.form['userlogic'].value pageappend += "&userlogic=%s" % userlogic_input else: userlogic_input = "OR" if self.form.has_key("recent"): try: recent = int(self.form['days'].value) pageappend += "&recent=on&days=%d" % recent except ValueError: self.do_error("""Invalid input into Past Days: "%s" """ % self.form['days'].value) query_field = [] if self.form.has_key("query_fields"): value = self.form.getvalue("query_fields", "") if not isinstance(value, list): if (value.find(',')): value = string.split(value, ",") else: value = [value] for field in value: if field == "path": query_field.append("path") elif field == "artist": query_field.append("artist") elif field == "album": query_field.append("album") elif field == "title": query_field.append("title") pageappend += "&query_fields=" + "&query_fields=%s" % ",".join( query_field) else: query_field = ['path', 'artist', 'album', 'title'] if self.form.has_key("querylogic"): querylogic_input = self.form['querylogic'].value pageappend += "&querylogic=%s" % querylogic_input else: querylogic_input = "OR" slm = SongListMaker.SongListMaker() if self.form.has_key("users"): users = [] import re ulm = UserListMaker.UserListMaker() value = self.form.getvalue("users", "") if isinstance(value, list): pageappend += "&users=" pageappend += "&users=".join(value) for user in value: usr = ulm.GetByName(re.sub("\(.\)$", "", user)) users.extend(ulm.list) else: user = ulm.GetByName(re.sub("\(.\)$", "", value)) users.extend(ulm.list) pageappend += "&users=%s" % value userids = [] for id in users: userids.append(str(id)) users = ",".join(userids) if sort == "popularity": slm.SubSearchUsers(searchstring, users=users, order="popular", type=type_input, recent_days=recent, user_logic=userlogic_input, query_fields=query_field, query_logic=querylogic_input) else: slm.SubSearchUsers(searchstring, users=users, type=type_input, recent_days=recent, user_logic=userlogic_input, query_fields=query_field, query_logic=querylogic_input) else: if sort == "popularity": slm.SubSearchUsers(searchstring, order="popular", type=type_input, recent_days=recent, query_fields=query_field, query_logic=querylogic_input) #elif sort == "myPopularity": # slm.SubSearchPath( searchstring, order="mypopularity") else: slm.SubSearchUsers(searchstring, type=type_input, recent_days=recent, query_fields=query_field, query_logic=querylogic_input) numres = len(slm.list) options = [] for option in ('filename', 'popularity'): entity = {} entity['name'] = option if option == sort: entity['selected'] = 'true' options.append(entity) context.addGlobal("options", options) context.addGlobal("numresults", numres) context.addGlobal("searchstr", searchstring) context.addGlobal( "advsearch", self.config['general.cgi_url'] + "?action=advancedSearch") #slm.Skip(offset) if offset + limit > numres: numdisp = numres - offset else: numdisp = limit min = offset + 1 max = offset + numdisp tot = numres resultlist = [] for i in range(offset, offset + numdisp): s = slm.GetSong(i) result = {} result['id'] = s.id result['song'] = s.GetDisplayName() result['songlen'] = s.GetDisplayLength() if self.form.has_key("users") and self.form.has_key("recent"): result['requests'] = s.GetRequestsFromUsers(users, recent=recent) result['kills'] = s.GetKillsFromUsers(users, recent=recent) elif self.form.has_key("users"): result['requests'] = s.GetRequestsFromUsers(users) result['kills'] = s.GetKillsFromUsers(users) elif self.form.has_key("recent"): result['requests'] = s.GetNumRecentRequests(days=recent) result['kills'] = s.GetNumRecentKills(days=recent) else: result['requests'] = s.requests result['kills'] = s.kills result['songurl'] = "%s?action=songInfo&id=%d" % ( self.config['general.cgi_url'], s.id) resultlist.append(result) context.addGlobal("resultlist", resultlist) pages = [] pagefootlimit = 20 subsetmax = pagefootlimit * limit numpages = int((tot - 1) / limit + 1) if offset == 0: curpage = 1 else: curpage = (offset / limit + 1) context.addGlobal("curpage", curpage) context.addGlobal("totpage", numpages) if (numpages < pagefootlimit): i = 0 if curpage > 1: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (curpage - 2) * limit, limit, pageappend) page['pagename'] = "<<" pages.append(page) for j in range(0, numpages): i = i + 1 page = {} if j == curpage - 1: page['pagename'] = i pages.append(page) else: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (i - 1) * limit, limit, pageappend) page['pagename'] = i pages.append(page) if curpage < numpages: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (curpage) * limit, limit, pageappend) page['pagename'] = ">>" pages.append(page) context.addGlobal("pages", pages) context.addGlobal("searchformaction", self.config['general.cgi_url']) else: i = 0 if curpage <= (pagefootlimit / 2): if curpage != 1: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (curpage - 2) * limit, limit, pageappend) page['pagename'] = "<<" pages.append(page) for j in range(0, pagefootlimit): i = i + 1 if j == curpage - 1: page = {} page['pagename'] = i pages.append(page) else: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (i - 1) * limit, limit, pageappend) page['pagename'] = i pages.append(page) page = {} page['pagename'] = ".." pages.append(page) page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, ((tot / limit + 1) * limit - limit), limit, pageappend) page['pagename'] = (tot / limit + 1) pages.append(page) page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (curpage) * limit, limit, pageappend) page['pagename'] = ">>" pages.append(page) context.addGlobal("pages", pages) context.addGlobal("searchformaction", self.config['general.cgi_url']) else: halfpagefootlimit = pagefootlimit / 2 page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (curpage - 2) * limit, limit, pageappend) page['pagename'] = "<<" pages.append(page) page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, 0, limit, pageappend) page['pagename'] = 1 pages.append(page) page = {} page['pagename'] = ".." pages.append(page) if ((curpage + halfpagefootlimit) > numpages): lastpage = numpages else: lastpage = curpage + halfpagefootlimit i = curpage - halfpagefootlimit for j in range(curpage - halfpagefootlimit, lastpage): i = i + 1 page = {} if j == curpage - 1: page['pagename'] = i pages.append(page) else: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (i - 1) * limit, limit, pageappend) page['pagename'] = i pages.append(page) if curpage < (numpages - (pagefootlimit / 2)): page = {} page['pagename'] = ".." pages.append(page) page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, ((tot / limit + 1) * limit - limit), limit, pageappend) page['pagename'] = (tot / limit + 1) pages.append(page) if curpage < numpages: page = {} page[ 'pagelink'] = "%s?action=searchResults&search=%s&offset=%s&limit=%s%s" % ( self.config['general.cgi_url'], searchstring, (curpage) * limit, limit, pageappend) page['pagename'] = ">>" pages.append(page) context.addGlobal("pages", pages) context.addGlobal("searchformaction", self.config['general.cgi_url'])