Esempio n. 1
0
    def resolve_viewalbum(self,id=1) :

        album = gordon_model.Album.query.get(id)
        tracks = album.tracks
        albumcover = widgets.get_albumcover(album)
        artiststring = widgets.get_album_artiststring(album)
        res= gordon_model.Mbalbum_recommend.query.filter_by(album_id=id)
            
        if res.count()<>1 :
            flash('No recommendation or multiple recommendations for album %s' % id)
            redirect("/resolve_viewalbums")
        else :
            mbrecommend=res[0]


        if mbrecommend.trackorder<>None :
            trackorder = eval(mbrecommend.trackorder)
            if len(trackorder)==len(tracks) :
                trks = [0] * len(tracks)
                for t in tracks :
                    idx = trackorder[t.id]
                    trks[idx]=t
                tracks = trks



        mbrainz_resolver = gordon.db.mbrainz_resolver.GordonResolver()        

        #get the recommended album name for display

        (recommend_tracks,status) = mbrainz_resolver.add_mbalbumdata_to_trackdict(mbrecommend.mb_id,tracks) #adds mb tracks to tracks structure
        if status==False :
            #try redoing the recommmendation
            print 'Trying to get closest album'
            mbrainz_resolver.resolve_album(id) 
            (recommend_tracks,status) = mbrainz_resolver.add_mbalbumdata_to_trackdict(mbrecommend.mb_id,tracks) #adds mb tracks to tracks structure
            if status==False :
                flash('Unable to merge tracks for album %s' % id)
                redirect('/resolve_viewalbums')
        mbrecommend_mb_id_url=widgets.get_album_mb_id_url(mbrecommend.mb_id)
        mb_album=mbrecommend.mb_album
        submit_form = TableForm(
            fields=[TextField(name='mb_id',default=mbrecommend.mb_id,label='Recommended MB_ID',attrs=dict(size='38'))],
            action="../resolve_submitalbum/%s" % str(id),
            submit_text="Accept and Update(!)",
            )
        return dict(album=album,artiststring=artiststring,albumcover=albumcover,tracks=recommend_tracks,mb_album=mb_album,
                    tracklist=mbrecommend_track_datagrid,mbrecommend=mbrecommend,submit_form=submit_form,mbrecommend_mb_id_url=mbrecommend_mb_id_url)
Esempio n. 2
0
    def resolve_viewalbum(self, id=1):

        album = gordon_model.Album.query.get(id)
        tracks = album.tracks
        albumcover = widgets.get_albumcover(album)
        artiststring = widgets.get_album_artiststring(album)
        res = gordon_model.Mbalbum_recommend.query.filter_by(album_id=id)

        if res.count() <> 1:
            flash(
                'No recommendation or multiple recommendations for album %s' %
                id)
            redirect("/resolve_viewalbums")
        else:
            mbrecommend = res[0]

        if mbrecommend.trackorder <> None:
            trackorder = eval(mbrecommend.trackorder)
            if len(trackorder) == len(tracks):
                trks = [0] * len(tracks)
                for t in tracks:
                    idx = trackorder[t.id]
                    trks[idx] = t
                tracks = trks

        mbrainz_resolver = gordon.db.mbrainz_resolver.GordonResolver()

        #get the recommended album name for display

        (recommend_tracks,
         status) = mbrainz_resolver.add_mbalbumdata_to_trackdict(
             mbrecommend.mb_id, tracks)  #adds mb tracks to tracks structure
        if status == False:
            #try redoing the recommmendation
            print 'Trying to get closest album'
            mbrainz_resolver.resolve_album(id)
            (recommend_tracks,
             status) = mbrainz_resolver.add_mbalbumdata_to_trackdict(
                 mbrecommend.mb_id,
                 tracks)  #adds mb tracks to tracks structure
            if status == False:
                flash('Unable to merge tracks for album %s' % id)
                redirect('/resolve_viewalbums')
        mbrecommend_mb_id_url = widgets.get_album_mb_id_url(mbrecommend.mb_id)
        mb_album = mbrecommend.mb_album
        submit_form = TableForm(
            fields=[
                TextField(name='mb_id',
                          default=mbrecommend.mb_id,
                          label='Recommended MB_ID',
                          attrs=dict(size='38'))
            ],
            action="../resolve_submitalbum/%s" % str(id),
            submit_text="Accept and Update(!)",
        )
        return dict(album=album,
                    artiststring=artiststring,
                    albumcover=albumcover,
                    tracks=recommend_tracks,
                    mb_album=mb_album,
                    tracklist=mbrecommend_track_datagrid,
                    mbrecommend=mbrecommend,
                    submit_form=submit_form,
                    mbrecommend_mb_id_url=mbrecommend_mb_id_url)
Esempio n. 3
0
    def album(self,id=1,action='view',shuffle='') :
        if len(id)==36 :
            #mbid
            album = gordon_model.Album.query.filter_by(mb_id=id)
            if album.count()>0 :
                album=album.first()
                id = album.id
            else :
                album=None
        else :
            album = gordon_model.Album.query.get(id)
        if album==None :
            flash('gordon_model.Album %s not found' % str(id))
            redirect('/')

        referer = cherrypy.request.headerMap.get("Referer", "/")
        album.referer=referer
        albumcover = widgets.get_albumcover(album)
        artiststring = widgets.get_album_artiststring(album)
        if album.mb_id<>None and len(album.mb_id)>5 :
            album_mb_id_link = ET.Element('a',href='http://www.musicbrainz.org/release/%s.html' % album.mb_id)#target='_blank')
            album_mb_id_link.text = "MusicBrainz"
        else :
            album_mb_id_link=''
        #widget_data is for the widget to render while track is the actual record.
        #allows us to render for viewing using DataGrid
        if action=='edit':
            album_widget=album_edit_widget
            album_widget_data=album
            alternate_action=ET.Element('a',href='/album/%s/view' % str(id))
            alternate_action.text='View'
            track_widget=track_edit_datagrid
            deleteform_header=ET.Element('form',action='/album_modify/deletetracks', method="post")
            deleteform_button=ET.Element('input',type='submit',value='Delete Selected gordon_model.Tracks')
            deleteform_footer=ET.Element('/form')
        else :
            album_widget=null_widget
            album_widget_data=list()#rotate_record(artist)
            alternate_action=ET.Element('a',href='/album/%s/edit' % str(id))
            alternate_action.text='Edit'
            track_widget=track_datagrid_no_album
            deleteform_header=''
            deleteform_button=''
            deleteform_footer=''
            



        album_sims=list()
        album_top_sims=list()
        album_bottom_sims=list()
#        album_sims=gordon_model.AlbumSim.query.filter_by(album_id=id)
#        if album_sims.count()==0 :
#            album_top_sims=list()
#            album_bottom_sims=list()
#        else :
#            album_sims=album_sims[album_sims.count()-1]
#            album_top_sims=album_sims.top_sims
#            album_bottom_sims=album_sims.bottom_sims



        top_albumcovers=list()
        top_albumtitles=list()
        top_albumartists=list()
        albumtitles=set()
        albumartists=set()
        albumids=set() #albums already used
        ctr=0
        idx=0
        #build our grid for similar albums
        doall=False        
        do_albumgrid=False    
        while do_albumgrid and len(album_top_sims)>0:
            if idx==len(album_top_sims) :
                #oops we ran out of data. Loop again and take whatever we can get
                idx=1
                doall=True

            if ctr==9 :
                break
            
            other = album_top_sims[idx].other
            if not other :
                break
            album_id= other.id
            atitle = other.name
            if len(album_top_sims[idx].other.artists)>1 :
                aartist="Various gordon_model.Artists"
            elif len(album_top_sims[idx].other.artists)== 0:
                aartist="Unknown"
            else :
                aartist=album_top_sims[idx].other.artists[0].name
            albumcvr = widgets.get_albumcover(album_top_sims[idx].other,clickable=False,sz=90)

            albumtitle = ET.Element('a',href='/album/%s' % album_id)
            if len(atitle)>20 :
                atitle='%s...' % atitle[0:19]
            albumtitle.text = atitle

            albumartist = ET.Element('a',href='/album/%s' % album_id)
            albumartist.text = aartist
            idx+=1
            
            if not doall :
                #we try to skip some undesirable albums
                if atitle=="" : #skip blank albums
                    continue
                if atitle.lower()==gordon_model.Album.query.get(id).name.lower and aartist.lower()==gordon_model.Album.query.get(id).artists[0].name :
                    continue
                if aartist.lower()=='various artists' :
                    continue
                if aartist.lower() in albumartists :
                    continue
            albumartists.add(aartist.lower())
            albumtitles.add(atitle.lower())
 
            top_albumcovers.append(albumcvr)
            top_albumtitles.append(albumtitle)
            top_albumartists.append(albumartist)
            ctr+=1
        do_albumgrid= len(top_albumcovers)>8  #should we show an album grid?

        tracks=album.tracks
        if shuffle<>'' :
            random.shuffle(tracks)

        return dict(album_widget=album_widget,album_widget_data=album_widget_data,album=album,alternate_action=alternate_action,
                    artiststring=artiststring,album_mb_id_url=get_album_mb_id_url(album.mb_id),albumcover=albumcover,tracks=album.tracks,track_widget=track_widget,
                    artist_widget=artist_datagrid,artists=album.artists,deleteform_header=deleteform_header,
                    deleteform_button=deleteform_button,deleteform_footer=deleteform_footer,album_mb_id_link=album_mb_id_link,action=action,
                    album_top_sims=album_top_sims,album_bottom_sims=album_bottom_sims,
                    album_top_sim_datagrid=album_top_sim_datagrid,album_bottom_sim_datagrid=album_bottom_sim_datagrid,
                    top_albumcovers=top_albumcovers,top_albumtitles=top_albumtitles,top_albumartists=top_albumartists, do_albumgrid=do_albumgrid)
Esempio n. 4
0
    def album(self, id=1, action='view', shuffle=''):
        if len(id) == 36:
            #mbid
            album = gordon_model.Album.query.filter_by(mb_id=id)
            if album.count() > 0:
                album = album.first()
                id = album.id
            else:
                album = None
        else:
            album = gordon_model.Album.query.get(id)
        if album == None:
            flash('gordon_model.Album %s not found' % str(id))
            redirect('/')

        referer = cherrypy.request.headerMap.get("Referer", "/")
        album.referer = referer
        albumcover = widgets.get_albumcover(album)
        artiststring = widgets.get_album_artiststring(album)
        if album.mb_id <> None and len(album.mb_id) > 5:
            album_mb_id_link = ET.Element(
                'a',
                href='http://www.musicbrainz.org/release/%s.html' %
                album.mb_id)  #target='_blank')
            album_mb_id_link.text = "MusicBrainz"
        else:
            album_mb_id_link = ''
        #widget_data is for the widget to render while track is the actual record.
        #allows us to render for viewing using DataGrid
        if action == 'edit':
            album_widget = album_edit_widget
            album_widget_data = album
            alternate_action = ET.Element('a', href='/album/%s/view' % str(id))
            alternate_action.text = 'View'
            track_widget = track_edit_datagrid
            deleteform_header = ET.Element('form',
                                           action='/album_modify/deletetracks',
                                           method="post")
            deleteform_button = ET.Element(
                'input',
                type='submit',
                value='Delete Selected gordon_model.Tracks')
            deleteform_footer = ET.Element('/form')
        else:
            album_widget = null_widget
            album_widget_data = list()  #rotate_record(artist)
            alternate_action = ET.Element('a', href='/album/%s/edit' % str(id))
            alternate_action.text = 'Edit'
            track_widget = track_datagrid_no_album
            deleteform_header = ''
            deleteform_button = ''
            deleteform_footer = ''

        album_sims = list()
        album_top_sims = list()
        album_bottom_sims = list()
        #        album_sims=gordon_model.AlbumSim.query.filter_by(album_id=id)
        #        if album_sims.count()==0 :
        #            album_top_sims=list()
        #            album_bottom_sims=list()
        #        else :
        #            album_sims=album_sims[album_sims.count()-1]
        #            album_top_sims=album_sims.top_sims
        #            album_bottom_sims=album_sims.bottom_sims

        top_albumcovers = list()
        top_albumtitles = list()
        top_albumartists = list()
        albumtitles = set()
        albumartists = set()
        albumids = set()  #albums already used
        ctr = 0
        idx = 0
        #build our grid for similar albums
        doall = False
        do_albumgrid = False
        while do_albumgrid and len(album_top_sims) > 0:
            if idx == len(album_top_sims):
                #oops we ran out of data. Loop again and take whatever we can get
                idx = 1
                doall = True

            if ctr == 9:
                break

            other = album_top_sims[idx].other
            if not other:
                break
            album_id = other.id
            atitle = other.name
            if len(album_top_sims[idx].other.artists) > 1:
                aartist = "Various gordon_model.Artists"
            elif len(album_top_sims[idx].other.artists) == 0:
                aartist = "Unknown"
            else:
                aartist = album_top_sims[idx].other.artists[0].name
            albumcvr = widgets.get_albumcover(album_top_sims[idx].other,
                                              clickable=False,
                                              sz=90)

            albumtitle = ET.Element('a', href='/album/%s' % album_id)
            if len(atitle) > 20:
                atitle = '%s...' % atitle[0:19]
            albumtitle.text = atitle

            albumartist = ET.Element('a', href='/album/%s' % album_id)
            albumartist.text = aartist
            idx += 1

            if not doall:
                #we try to skip some undesirable albums
                if atitle == "":  #skip blank albums
                    continue
                if atitle.lower() == gordon_model.Album.query.get(
                        id).name.lower and aartist.lower(
                        ) == gordon_model.Album.query.get(id).artists[0].name:
                    continue
                if aartist.lower() == 'various artists':
                    continue
                if aartist.lower() in albumartists:
                    continue
            albumartists.add(aartist.lower())
            albumtitles.add(atitle.lower())

            top_albumcovers.append(albumcvr)
            top_albumtitles.append(albumtitle)
            top_albumartists.append(albumartist)
            ctr += 1
        do_albumgrid = len(top_albumcovers) > 8  #should we show an album grid?

        tracks = album.tracks
        if shuffle <> '':
            random.shuffle(tracks)

        return dict(album_widget=album_widget,
                    album_widget_data=album_widget_data,
                    album=album,
                    alternate_action=alternate_action,
                    artiststring=artiststring,
                    album_mb_id_url=get_album_mb_id_url(album.mb_id),
                    albumcover=albumcover,
                    tracks=album.tracks,
                    track_widget=track_widget,
                    artist_widget=artist_datagrid,
                    artists=album.artists,
                    deleteform_header=deleteform_header,
                    deleteform_button=deleteform_button,
                    deleteform_footer=deleteform_footer,
                    album_mb_id_link=album_mb_id_link,
                    action=action,
                    album_top_sims=album_top_sims,
                    album_bottom_sims=album_bottom_sims,
                    album_top_sim_datagrid=album_top_sim_datagrid,
                    album_bottom_sim_datagrid=album_bottom_sim_datagrid,
                    top_albumcovers=top_albumcovers,
                    top_albumtitles=top_albumtitles,
                    top_albumartists=top_albumartists,
                    do_albumgrid=do_albumgrid)