本文整理汇总了Python中scatterbrainz.model.meta.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Session.delete方法的具体用法?Python Session.delete怎么用?Python Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scatterbrainz.model.meta.Session
的用法示例。
在下文中一共展示了Session.delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: savePlaylistAJAX
# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import delete [as 别名]
def savePlaylistAJAX(self):
playlistname = request.params['name']
trackids = simplejson.loads(request.params['trackids'])
trackids = map(lambda x: x.replace('track_',''), trackids)
results = Session.query(Track, MBRecording).join(MBRecording).filter(Track.id.in_(trackids)).all()
results.sort(lambda a,b: cmp(trackids.index(a[0].id), trackids.index(b[0].id)))
recordings = map(itemgetter(1), results)
Session.begin()
user_name = request.environ['repoze.what.credentials']['repoze.what.userid']
user_id = Session.query(User).filter(User.user_name==user_name).one().user_id
playlist = Session.query(Playlist) \
.filter(Playlist.owner_id==user_id) \
.filter(Playlist.name==playlistname) \
.first()
if not trackids:
if playlist is None:
return '{}'
else:
Session.delete(playlist)
else:
if playlist is None:
playlist = Playlist(user_id, playlistname)
Session.add(playlist)
else:
playlist.modified = datetime.now()
playlist.tracks = recordings
Session.commit()
return '{}'
示例2: create
# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import delete [as 别名]
def create(self):
usr = request.params['login']
if Session.query(User).filter_by(user_name=usr).count() > 0:
return simplejson.dumps({'success':False,'msg':'That username is already taken, sorry.'})
pwd = request.params['pass']
if len(usr) < 3 or len(pwd) < 3:
return simplejson.dumps({'success':False,'msg':'Your username and password must each be at least 3 characters.'})
code = request.params['code']
invite = Session.query(Invite).filter_by(code=code).first()
if invite is None:
return simplejson.dumps({'success':False,'msg':'Your registration code appears to be invalid.'})
user = User()
user.who = invite.who
user.user_name = usr
user.password = pwd
user.registered = datetime.now()
Session.begin()
user.groups = [Session.query(Group).filter_by(group_name='users').one()]
Session.delete(invite)
Session.add(user)
Session.commit()
return simplejson.dumps({'success':True})
示例3: load
# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import delete [as 别名]
def load(self):
commit = 'commit' in request.params and request.params['commit'] == 'true'
s = ''
if commit:
Session.begin()
now = datetime.now()
initialLoad = True #Session.query(AudioFile).count() == 0
if initialLoad:
s = _msg(s, 'Initial track loading!')
else:
s = _msg(s, 'Updating tracks!')
then = now
missing = 0
changed = 0
for track in Session.query(AudioFile):
path = os.path.join(MUSIC, track.filepath)
if os.path.exists(path):
size = os.path.getsize(path)
mtime = datetime.fromtimestamp(os.path.getmtime(path))
if size != track.filesize or mtime != track.filemtime:
changed = changed + 1
s = _msg(s, 'Modified file: ' + path)
if commit:
raise Exception('not implemented!')
else:
s = _msg(s, 'Deleted file: ' + path)
missing = missing + 1
if commit:
Session.delete(track)
s = _msg(s, 'Found ' + str(missing) + ' missing files and ' + str(changed) + ' modified files, took ' + \
str(datetime.now() - then))
then = datetime.now()
filepaths = set(map(lambda t: t.filepath, Session.query(AudioFile)))
s = _msg(s, 'Querying for all filepaths took ' + str(datetime.now() - then))
then = datetime.now()
added = 0
skippedNoMBID = 0
release_groups_added = set()
unknownrelease = set()
unknownrecording = set()
alreadyhaverecordingrelease = set()
alreadyhavereleasegroup = set()
unicodeproblems = set()
fuckedmp3s = set()
for dirname, dirnames, filenames in os.walk(INCOMING, followlinks=True):
for filename in filenames:
if not os.path.splitext(filename)[-1].lower() == '.mp3':
continue
try:
filepath = os.path.join(os.path.relpath(dirname, INCOMING), filename).decode('utf-8')
except UnicodeDecodeError:
log.error('unicode problem ' + os.path.join(os.path.relpath(dirname, INCOMING), filename))
unicodeproblems.add(os.path.join(os.path.relpath(dirname, INCOMING), filename))
continue
if not initialLoad and filepath in filepaths:
continue
if not initialLoad:
s = _msg(s, 'New file: ' + filepath)
if not commit:
continue
# get size, date
fileabspath = os.path.join(dirname,filename)
filesize = os.path.getsize(fileabspath)
filemtime = datetime.fromtimestamp(os.path.getmtime(fileabspath))
# mp3 length, bitrate, etc.
try:
mutagen = MP3(fileabspath)
except:
fuckedmp3s.add(fileabspath)
log.error('fucked mp3 ' + fileabspath)
continue
info = mutagen.info
mp3bitrate = info.bitrate
mp3samplerate = info.sample_rate
mp3length = int(round(info.length))
if info.sketchy:
fuckedmp3s.add(fileabspath)
log.error('sketchy mp3! ' + fileabspath)
continue
# brainz!!
if RECORDING_MBID_KEY not in mutagen:
#.........这里部分代码省略.........
示例4: download
# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import delete [as 别名]
#.........这里部分代码省略.........
# Gather up information about all downloads for this torrent
ttable = tpage.cssselect('table.torrent_table')[0]
downloads = []
for download in ttable.cssselect('tr.group_torrent[id]'):
torrentid = re.sub('^torrent', '', download.attrib['id'])
torrenttype = download.cssselect('a[onclick]')[0].text.encode('ascii', 'ignore').split('/')[0].strip()
if torrenttype != 'MP3':
continue
downloadurl = download.cssselect('a[title=Download]')[0].attrib['href']
if len(download.cssselect('td')) != 5:
raise Exception('Torrent ' + torrentid + ' has !=5 TD tags at ' + torrentpageurl)
numseeders = int(download.cssselect('td')[3].text.replace(',', ''))
if numseeders < 1:
continue
filestr = ttable.cssselect('div#files_' + torrentid)[0].cssselect('tr')[1:]
filenames = []
for tr in filestr:
filename = tr.cssselect('td')[0].text
if filename.lower().endswith('.mp3'):
filenames.append({'original' : filename,
'compare' : re.sub(' +', '', filename.split('/')[-1][:-4].lower())})
downloads.append({'seeders' : numseeders, 'torrentid' : torrentid, 'url' : downloadurl, 'filenames' : filenames})
if not downloads:
log.info('[shop] no seeded files of correct type found at torrent ' + torrentid)
# See if any of the downloads nicely match any of the releases, trying best seeded first
downloads.sort(key=itemgetter('seeders'), reverse=True)
for download in downloads:
releasescores = []
filenames = download['filenames']
for releaseid in releases.keys():
release = releases[releaseid]
if len(filenames) != len(release):
minscore = 0
avgscore = 0
else:
numtracks = len(release)
minscore = None
minscoreidx = None
sumscore = 0
for i in range(numtracks):
rtrack = release[i]
rtracknum = '%02d' % rtrack['num']
rtartist = rtrack['artist'].lower()
rtname = rtrack['name'].lower()
dname = filenames[i]['compare']
name1 = rtracknum + ' ' + rtname
name2 = rtracknum + ' ' + rtartist + ' ' + rtname
score1 = SequenceMatcher(None, dname, name1).ratio()
score2 = SequenceMatcher(None, dname, name2).ratio()
score = max(score1, score2)
sumscore = sumscore + score
if score < minscore or minscore is None:
minscore = score
minscoreidx = i
avgscore = sumscore * 1.0 / numtracks
log.info('[shop] match avg=' + str(avgscore) + ' min=' + str(minscore) + ' ' + download['torrentid'] + ' -> ' + releaseid)
releasescores.append({'releaseid' : releaseid, 'min' : minscore, 'avg' : avgscore})
releasescores = filter(lambda x: x['min'] > 0.3 and x['avg'] > 0.70, releasescores)
releasescores.sort(key=itemgetter('avg'), reverse=True)
if releasescores:
# Toss torrent over to rtorrent via xml-rpc
releaseid = releasescores[0]['releaseid']
torrenturl = shopbaseurl + '/' + download['url']
torrentdata = opener.open(torrenturl).read()
torrentdecode = bencode.bdecode(torrentdata)
infohash = hashlib.sha1(bencode.bencode(torrentdecode['info'])).hexdigest().upper()
with tempfile.NamedTemporaryFile(delete=False) as torrentfile:
torrentpath = torrentfile.name
torrentfile.write(torrentdata)
# scp torrent over if necessary
if Config.SCP_SHOP_DOWNLOADS:
remotetorrentpath = '/tmp/' + infohash + '.torrent'
cmd = Config.SCP_CMD + ' ' + torrentpath + ' ' + Config.SCP_REMOTE + ':' + remotetorrentpath
log.info('[shop] running ' + cmd)
retval = os.system(cmd)
os.unlink(torrentpath)
if retval != 0:
raise Exception('scp command [' + cmd + '] returned ' + str(retval))
torrentpath = remotetorrentpath
rtorrent = xmlrpclib.ServerProxy(Config.SHOP_RPC_URL)
rtorrent.load_start(torrentpath, "execute=rm," + torrentpath)
log.info('[shop] downloaded ' + torrenturl + ' has ' + str(download['seeders']) +
' seeders, infohash=' + infohash + ', match to album ' + releaseid)
file_json = simplejson.dumps(map(itemgetter('original'), filenames))
minscore = releasescores[0]['min']
avgscore = releasescores[0]['avg']
shopdownload = ShopDownload(releaseid, album.gid, infohash, torrenturl, torrentpageurl, download['torrentid'], download['seeders'], file_json, minscore, avgscore, owner_id)
Session.add(shopdownload)
if attempt in Session:
Session.delete(attempt)
Session.commit()
return infohash
log.info('[shop] no matches, sorry :(')
attempt.gotsearchresults = True
if attempt not in Session:
Session.add(attempt)
Session.commit()
return None
示例5: load
# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import delete [as 别名]
def load(self):
commit = 'commit' in request.params and request.params['commit'] == 'true'
s = ''
now = datetime.now()
albums = {}
artists = {}
if commit:
Session.begin()
variousArtists = Session.query(Artist).filter_by(mbid=u'89ad4ac3-39f7-470e-963a-56509c546377').first()
if variousArtists is None:
variousArtists = Artist(name=u'Various Artists',
mbid=u'89ad4ac3-39f7-470e-963a-56509c546377',
added=now)
Session.save(variousArtists)
s = _msg(s, 'Committed various artists placeholder')
artists['Various Artists'] = variousArtists
initialLoad = Session.query(Track).count() == 0
if initialLoad:
s = _msg(s, 'Initial track loading!')
else:
s = _msg(s, 'Updating tracks!')
then = now
missing = 0
changed = 0
for track in Session.query(Track):
path = os.path.join(BASE, track.filepath)
if os.path.exists(path):
size = os.path.getsize(path)
mtime = datetime.fromtimestamp(os.path.getmtime(path))
if size != track.filesize or mtime != track.filemtime:
changed = changed + 1
s = _msg(s, 'Modified file: ' + path)
if commit:
raise Exception('not implemented!')
else:
s = _msg(s, 'Deleted file: ' + path)
missing = missing + 1
if commit:
Session.delete(track)
s = _msg(s, 'Found ' + str(missing) + ' missing files and ' + str(changed) + ' modified files, took ' + \
str(datetime.now() - then))
then = datetime.now()
filepaths = set(map(lambda t: t.filepath, Session.query(Track)))
s = _msg(s, 'Querying for all filepaths took ' + str(datetime.now() - then))
then = datetime.now()
added = 0
for dirname, dirnames, filenames in os.walk(BASE):
localAlbums = {}
for filename in filenames:
filepath = os.path.join(os.path.relpath(dirname, BASE), filename).decode('utf-8')
if not os.path.splitext(filename)[-1].lower() == '.mp3':
continue
if not initialLoad and filepath in filepaths:
continue
added = added + 1
if not initialLoad:
s = _msg(s, 'New file: ' + filepath)
if not commit:
continue
# get size, date
fileabspath = os.path.join(dirname,filename)
filesize = os.path.getsize(fileabspath)
filemtime = datetime.fromtimestamp(os.path.getmtime(fileabspath))
# mp3 length, bitrate, etc.
mutagen = MP3(fileabspath, ID3=EasyID3)
info = mutagen.info
mp3bitrate = info.bitrate
mp3samplerate = info.sample_rate
mp3length = int(round(info.length))
if info.sketchy:
raise Exception('sketchy mp3! ' + filename)
# id3
# keys: ['album', 'date', 'version', 'composer', 'title'
# 'genre', 'tracknumber', 'lyricist', 'artist']
id3artist = getid3prop(mutagen, 'artist')
id3album = getid3prop(mutagen, 'album')
id3title = getid3prop(mutagen, 'title')
#.........这里部分代码省略.........