当前位置: 首页>>代码示例>>Python>>正文


Python Session.save方法代码示例

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


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

示例1: currentMembersForTrackArtist

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import save [as 别名]
    def currentMembersForTrackArtist(self):
        trackid = request.params["trackid"]
        track = Session.query(Track).filter_by(id=trackid).one()

        # search for triples with subject matching current artist
        db_uri = u""
        for triple in Session.query(RDFTriple).filter_by(artistid=track.artistid):
            if triple.subject == ":artist":
                if triple.predicate == "hasdbpedia":
                    db_uri = triple.obj

        if db_uri == "":
            art_mbid = track.artist.mbid
            db_uri = sDB.dbpedia_from_MBID(art_mbid)
            db_unicode = unicode(db_uri.__str__())
            artist = track.artist
            triple = RDFTriple(
                subject=u":artist", predicate=u"hasdbpedia", obj=db_unicode, artist=artist, track=None, album=None
            )
            Session.save(triple)
            Session.commit()

        g = Graph()
        g.parse(db_uri)
        pmem_re = re.compile("pastmember", re.I)
        cmem_re = re.compile("currentmember", re.I)

        out = {}
        past_members = []
        current_members = []

        for s, p, o in g.triples((None, None, None)):
            if re.search(pmem_re, p):
                past_members.append(getURILabel(o))
            if re.search(cmem_re, p):
                current_members.append(getURILabel(o))

        out["past_members"] = past_members
        out["current_members"] = current_members
        return sjson.dumps(out)
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:42,代码来源:getmb.py

示例2: index

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import save [as 别名]
 def index(self):
     t = Track('asdf')
     Session.save(t)
     Session.commit()
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:6,代码来源:test.py

示例3: load

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import save [as 别名]
    def load(self):

        done = False
        now = datetime.now()
        numFilesSeen = 0
        numBadFiles = 0
        numSketchy = 0
        commitbuffer = []
        albums = {}
        artists = {}
        
        variousArtists = Artist(name='Various Artists',
                                mbid='89ad4ac3-39f7-470e-963a-56509c546377',
                                added=now)
        artists['Various Artists'] = variousArtists
        Session.save(variousArtists)
        
        for dirname, dirnames, filenames in os.walk('scatterbrainz/public/.music/'):
            localAlbums = {}
            for filename in filenames:
                try:
                    numFilesSeen = numFilesSeen + 1
                    
                    # get path, size, date
                    fileabspath = os.path.join(dirname,filename)
                    filepath = os.path.join(os.path.relpath(dirname, 'scatterbrainz/public/.music/'), filename)
                    filesize = os.path.getsize(fileabspath)
                    filemtime = datetime.fromtimestamp(os.path.getmtime(fileabspath))
                    
                    ext = os.path.splitext(filename)[-1]
                    if not ext == '.mp3': continue
  
                    # 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:
                        mp3['sketchy'] = true
                        numSketchy = numSketchy + 1
                        log.warn('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')
                    id3tracknum = getid3prop(mutagen, 'tracknumber')
                    id3date = getid3prop(mutagen, 'date')
                    id3composer = getid3prop(mutagen, 'composer')
                    id3genre = getid3prop(mutagen, 'genre')
                    id3lyricist = getid3prop(mutagen, 'lyricist')
                    
                    # additional musicbrainz related keys: At some point,
                    # should probably switch from easyID3 to ordinary ID3
                    # class to get extra MB relationship data.
                    
                    mbartistid = getid3prop(mutagen,'musicbrainz_albumartistid')
                    mbalbumid = getid3prop(mutagen,'musicbrainz_albumid')
                    mbtrackid = getid3prop(mutagen,'musicbrainz_trackid')

                    if not id3artist:
                        artist = None
                    elif id3artist in artists:
                        artist = artists[id3artist]
                    else:
                        artist = Artist(name=id3artist,
                                        mbid=mbartistid,
                                        added=now)
                        Session.save(artist)
                        artists[id3artist] = artist
                    
                    if not id3album:
                        album = None
                    elif id3album in localAlbums:
                        album = localAlbums[id3album]
                        if artist != album.artist:
                            album.artist = variousArtists
                    else:
                        album = Album(name=id3album,
                                      artist=artist,
<<<<<<< HEAD
                                      mbid=mbalbumid,
                                      albumArtURL=None,
=======
>>>>>>> upstream/master
                                      added=now)
                        Session.save(album)
                        albums[id3album] = album
                        localAlbums[id3album] = album
                    
                    track = Track(artist=artist,
                                  album=album,
                                  filepath=filepath.decode('utf-8'),
                                  filesize=filesize,
                                  filemtime=filemtime,
                                  mp3bitrate=mp3bitrate,
#.........这里部分代码省略.........
开发者ID:bh0085,项目名称:scatterbrainz,代码行数:103,代码来源:load.py

示例4: load

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import save [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')
#.........这里部分代码省略.........
开发者ID:fichtitious,项目名称:scatterbrainz,代码行数:103,代码来源:load.py


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