本文整理汇总了Python中scatterbrainz.model.meta.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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
示例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()
示例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
示例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')
示例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()
示例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)
示例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
示例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})
示例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)
示例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)
示例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()])
示例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())