• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python meta.Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scatterbrainz.model.meta.Session的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Session类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getAlbumInfoAJAX

 def getAlbumInfoAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     json = {}
     albumMbid = track.album.mbid
     # get wikipedia from the release group
     wikipedia = Session.query(MBURL.url) \
                        .join(MBLReleaseGroupURL) \
                        .join(MBLink) \
                        .join(MBLinkType) \
                        .filter(MBLinkType.name=='wikipedia') \
                        .join(MBReleaseGroup) \
                        .filter(MBReleaseGroup.gid==albumMbid) \
                        .all()
     wikipedia = filter(self._filterForEnglishWiki, map(lambda x: x[0], wikipedia))
     if wikipedia:
         wurl = wikipedia[0]
         json['wikipedia'] = wurl
         json['summary'] = albumsummary.get_album_summary(Session, albumMbid, wurl)
     # get amazon from any of the releases
     amazon = Session.query(MBURL) \
                     .join(MBLReleaseURL) \
                     .join(MBLink) \
                     .join(MBLinkType) \
                     .filter(MBLinkType.name=='amazon asin') \
                     .join(MBRelease) \
                     .join(MBReleaseGroup) \
                     .filter(MBReleaseGroup.gid==albumMbid) \
                     .first()
     if amazon:
         json['amazon'] = amazon.url
     json['musicbrainz'] = 'http://musicbrainz.org/release-group/' + albumMbid
     return simplejson.dumps(json)
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:33,代码来源:hello.py


示例2: getLyricsAJAX

 def getLyricsAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     if not track.lyrics and \
        (track.lastHitLyricWiki is None or \
         datetime.now() > track.lastHitLyricWiki + timedelta(days=10)):
         
         track.lastHitLyricWiki = datetime.now()
         
         title = track.id3title
         artist = track.id3artist
         params = {
             'artist' : artist,
             'song'   : title,
             'fmt'    : 'json',
         }
         
         url = 'http://lyrics.wikia.com/api.php?%s' % urllib.urlencode(params)
         
         html = urllib.urlopen(url).read()
         
         if not "'lyrics':'Not found'" in html:
             search = re.search("'url':'(?P<url>.*?)'",html)
             lyricurl = urllib.unquote(search.group('url'))
             lyrichtml = urllib.urlopen(lyricurl).read()
             lyrics = re.search("<div class='lyricbox'>.*?</div>(?P<lyrics>.*?)<!-- \n", lyrichtml).group('lyrics')
             lyrics = unescape(lyrics)
             track.lyrics = lyrics
         Session.begin()
         Session.commit()
     json = {}
     if track.lyrics:
         json['lyrics'] = track.lyrics
     return simplejson.dumps(json)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:34,代码来源:hello.py


示例3: trackArtistAlbumsLOCAL

    def trackArtistAlbumsLOCAL(self):
        trackid = request.params['trackid']

        #note that we can do this because there is 
        #only a single foreign key matched between 
        #tracks and albums.
        artistid=Session.query(Track).filter_by(id=trackid)[0].artistid
        joined=Session.query(Track).filter_by(artistid=artistid)

        aids = []
        out = []
        for t in joined:
            aid = t.albumid
            if not aid in aids:
                aids.append(aid)
                year_re = re.compile('[0-9]{4}')
                early_year = (re.search(year_re,t.id3date)).group()
                json = {
                    'aid':aid,
                    'mbid':t.album.mbid,
                    'name':t.album.name,
                    'year':early_year
                    }
                out.append(json)
        return sjson.dumps(out)
开发者ID:steez,项目名称:scatterbrainz,代码行数:25,代码来源:getlocal.py


示例4: clearAlbumArt

 def clearAlbumArt(self):
     id = request.params['id']
     Session.begin()
     album = Session.query(Album).filter_by(id=id).one()
     album.albumArtFilename = None
     album.lastHitAlbumArtExchange = None
     Session.commit()
     return 'Cleared album art for ' + album.artist.name + ' - ' + album.name
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:8,代码来源:hello.py


示例5: saveLyricsFramesAJAX

 def saveLyricsFramesAJAX(self):
     trackid = request.params['trackid']
     recordedFrames = simplejson.loads(request.params['frames']) # list of (time, lyrics line index) pairs
     recordedFrames.sort(key = itemgetter(0))                    # (sort by time)
     Session.begin()
     track = Session.query(Track).filter_by(id=trackid).one()
     track.lyricsFrames = recordedFrames
     Session.commit()
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:8,代码来源:hello.py


示例6: setAlbumArt

 def setAlbumArt(self):
     id = request.params['id']
     url = request.params['url']
     Session.begin()
     album = Session.query(Album).filter_by(id=id).one()
     album.albumArtFilename = albumart._fetchAlbumArt(album.artist.name, album.name, url)
     Session.commit()
     return 'Set album art for ' + album.artist.name + ' - ' + album.name + ' to ' + url + ', saved to ' + album.albumArtFilename
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:8,代码来源:hello.py


示例7: pp2

 def pp2(self):
     artists = Session.query(Artist)
     tracks = Session.query(Track)
     paths = []
     for r in tracks:
         paths.append( os.path.join('.media', r.filepath ))
         
     return render('/hello2.html')
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:8,代码来源:hello2.py


示例8: similarTrackAJAX

 def similarTrackAJAX(self):
     id = request.params['id'].split('_')[1]
     track = Session.query(Track).filter_by(id=id).one()
     lastfmArtist = self.lastfmNetwork.get_artist(track.artist.name)
     similarArtists = lastfmArtist.get_similar()
     similarMbids = filter(lambda x: x is not None, map(lambda x: x.mbid, similarArtists))
     randomSimilarArtist = Session.query(Artist).filter(Artist.mbid.in_(similarMbids)).order_by(random()).first()
     return simplejson.dumps([rand.choice(randomSimilarArtist.tracks).toPlaylistJSON()]) \
         if randomSimilarArtist \
         else self.randomTrackAJAX()
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:10,代码来源:hello.py


示例9: randomRooAlbumAJAX

 def randomRooAlbumAJAX(self):
     album = Session.query(Album) \
                    .join(Album.artists) \
                    .filter(Artist.mbid.in_(Bonnaroo.artist_mbids)) \
                    .order_by(random()) \
                    .first()
     tracks = Session.query(Track) \
                     .filter_by(albumid=album.mbid)
     json = map(lambda x: x.toPlaylistJSON(), tracks)
     return simplejson.dumps(json)
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:10,代码来源:hello.py


示例10: _getTracksForPlaylist

 def _getTracksForPlaylist(self, id):
     playlist = Session.query(Playlist).filter(Playlist.playlist_id==id).one()
     recordings = playlist.tracks
     recording_mbids = map(lambda x: x.gid, recordings)
     tracks = Session.query(Track).filter(Track.mbid.in_(recording_mbids)).all()
     tracks.sort(lambda a,b: cmp(recording_mbids.index(a.mbid), recording_mbids.index(b.mbid)))
     filtertracks = [tracks[0]]
     for track in tracks[1:]:
         if track.mbid != filtertracks[-1].mbid:
             filtertracks.append(track)
     return filtertracks
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:11,代码来源:hello.py


示例11: searchShopAlbumAJAX

 def searchShopAlbumAJAX(self):
     mbid = request.params['mbid']
     (album, albumname, artistname) = Session.query(MBReleaseGroup, MBReleaseName, MBArtistName) \
                                             .join(MBReleaseName) \
                                             .join(MBReleaseGroup.artistcredit, MBArtistCredit.name) \
                                             .filter(MBReleaseGroup.gid==mbid) \
                                             .one()
     user_name = request.environ['repoze.what.credentials']['repoze.what.userid']
     user_id = Session.query(User).filter(User.user_name==user_name).one().user_id
     infohash = shopservice.download(Session, mbid, user_id)
     if infohash:
         return simplejson.dumps({'success' : True})
     else:
         return simplejson.dumps({'success' : False})
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:14,代码来源:hello.py


示例12: searchAJAX

 def searchAJAX(self):
     search = request.params['search']
     maxResults = 50
     artists = Session.query(Artist). \
                       filter(Artist.name.like('%'+search+'%')). \
                       join(Album) \
                       [0:maxResults]
     albums = Session.query(Album). \
                      filter(Album.name.like('%'+search+'%')) \
                      [0:maxResults]
     tracks = Session.query(Track). \
                      filter(Track.id3title.like('%'+search+'%')) \
                      [0:maxResults]
     if len(artists) == maxResults or len(tracks) == maxResults or len(albums) == maxResults:
         truncated = True
     else:
         truncated = False
     artistIdToJSON = {}
     albumsIdToJSON = {}
     for artist in artists:
         if artist.id not in artistIdToJSON:
             artistJSON = artist.toTreeJSON()
             artistIdToJSON[artist.id] = artistJSON
     for album in albums:
         if album.artist and album.artist.id not in artistIdToJSON:
             artistJSON = album.artist.toTreeJSON(children=[])
             artistIdToJSON[album.artist.id] = artistJSON
             albumJSON = album.toTreeJSON()
             artistJSON['children'].append(albumJSON)
         else:
             continue
     for track in tracks:
         if track.album and \
            track.album.artist and \
            track.album.artist.id not in artistIdToJSON:
             artistJSON = track.album.artist.toTreeJSON(children=[])
             artistIdToJSON[track.album.artist.id] = artistJSON
         else:
             continue
         if track.album and track.album.id not in albumsIdToJSON:
             albumJSON = track.album.toTreeJSON(children=[])
             artistJSON['children'].append(albumJSON)
             albumsIdToJSON[track.album.id] = albumJSON
         else:
             continue
         albumJSON['children'].append(track.toTreeJSON())
     json = artistIdToJSON.values()
     json.sort(self._compareTreeFloatVA)
     return simplejson.dumps(json)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:49,代码来源:hello.py


示例13: alltracks

    def alltracks(self):
        tracks = Session.query(Track)
        count = 0
        namefun = lambda x: x.id3title
        out = []
        this_artist_count = 0 
        last_artist = ''
        max_per_artist = 5
        for t in tracks:
            name = namefun(t)
            type = t.__class__.__name__

            this_artist = t.artistid
            if this_artist == last_artist:
                this_artist_count = this_artist_count + 1
            else:
                this_artist_count = 0
                last_artist = this_artist
            if this_artist_count < max_per_artist:
                json = {
                    'type':type,
                    'name':name,
                    'url':self.track_URL_from_id(t.id),
                    'id':t.id,
                    'albumid':t.albumid,
                    'artistid':t.artistid
                    }
                out.append(json)
                count = count + 1
                if count > 50: break

        return sjson.dumps(out)
开发者ID:steez,项目名称:scatterbrainz,代码行数:32,代码来源:getlocal.py


示例14: randomRooTrackAJAX

 def randomRooTrackAJAX(self):
     track = Session.query(Track) \
                    .join(Album, Album.artists) \
                    .filter(Artist.mbid.in_(Bonnaroo.artist_mbids)) \
                    .order_by(random()) \
                    .first()
     return simplejson.dumps([track.toPlaylistJSON()])
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:7,代码来源:hello.py


示例15: index

    def index(self):

        # Return a rendered template
        #return render('/ben_kvp.mako')
        # or, return a string
        
        return 'Hello World - how you doing today {0}'.format(Session.query(User).first())
开发者ID:drassi,项目名称:scatterbrainz,代码行数:7,代码来源:ben_kvp.py


示例16: alltracks

    def alltracks(self):
        trk_total_limit = 200;
        trk_artist_limit = 10;

        tracks = Session.query(Track)
        count = 0
        namefun = lambda x: x.id3title
        out = []
        this_artist_count = 0 
        last_artist = ''
        for t in tracks:
            name = namefun(t)

            this_artist = t.artistid
            if this_artist == last_artist:
                this_artist_count = this_artist_count + 1
            else:
                this_artist_count = 0
                last_artist = this_artist
            if this_artist_count < trk_artist_limit:
                json = {
                    'track_name':name,
                    'url':self.track_URL_from_id(t.id),
                    'track_id':t.id,
                    'albumid':t.albumid,
                    'artistid':t.artistid,
                    'datatype':'track',
                    'tostring':name
                    }
                out.append(json)
                count = count + 1
                if count > trk_total_limit: break

        return sjson.dumps(out)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:34,代码来源:getlocal.py


示例17: printPaths

 def printPaths(self):
     tracks = Session.query(Track)
     paths = []
     for r in tracks:
         paths.append( os.path.join('.media', r.filepath ))
         
     return paths
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:7,代码来源:hello2.py


示例18: getArtistInfoAJAX

 def getArtistInfoAJAX(self):
     json = {}
     # Get the artist credit for the given artist or track
     if 'trackid' in request.params:
         trackid = request.params['trackid'].split('_')[1]
         artistCreditNames = self._getArtistCreditNames(trackid)
         credit = []
         for artistcredit in artistCreditNames:
             credit.append({
                 'text' : artistcredit.name.name,
                 'mbid' : artistcredit.artist.gid
             })
             if artistcredit.joinphrase:
                 credit.append({
                     'text' : artistcredit.joinphrase
                 })
         artistMbid = artistCreditNames[0].artist.gid
     elif 'mbid' in request.params:
         artistMbid = request.params['mbid']
         artist = Session.query(MBArtist).filter(MBArtist.gid==artistMbid).one()
         credit = [{
             'text' : artist.name.name
         }]
     else:
         raise Exception('need trackid or artist mbid')
     json['credit'] = credit
     # Get artist bio, and url relationships
     urls = Session.query(MBURL.url, MBLinkType.name) \
                   .join(MBLArtistURL) \
                   .join(MBLink) \
                   .join(MBLinkType) \
                   .join(MBArtist) \
                   .filter(MBArtist.gid==artistMbid) \
                   .all()
     urls = self._mapify(urls)
     if 'wikipedia' in urls:
         wurls = filter(self._filterForEnglishWiki, urls['wikipedia'])
         if wurls:
             wurl = wurls[0]
             json['wikipedia'] = wurl
             json['bio'] = artistbio.get_artist_bio(Session, artistMbid,  wurl)
     if 'youtube' in urls:
         json['youtube'] = urls['youtube'][0]
     if 'official homepage' in urls:
         json['official'] = urls['official homepage'][0]
     json['musicbrainz'] = 'http://musicbrainz.org/artist/' + artistMbid
     return simplejson.dumps(json)
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:47,代码来源:hello.py


示例19: getAlbumArtAJAX

 def getAlbumArtAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     albumartfilename = albumart.get_art(Session, track.album)
     json = {}
     if albumartfilename is not None:
         json['albumArtURL'] = albumartfilename
     return simplejson.dumps(json)
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:8,代码来源:hello.py


示例20: getAlbumArtAJAX

 def getAlbumArtAJAX(self):
     trackid = request.params['trackid'].split('_')[1]
     track = Session.query(Track).filter_by(id=trackid).one()
     albumartfilename = albumart.get_art(Session, track.album)
     if albumartfilename:
         return simplejson.dumps({'albumArtURL' : albumartfilename})
     else:
         return '{}'
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:8,代码来源:hello.py



注:本文中的scatterbrainz.model.meta.Session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python actions.Action类代码示例发布时间:2022-05-27
下一篇:
Python utils.PcapReader类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap