本文整理汇总了Python中song.Song.init_from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Song.init_from_dict方法的具体用法?Python Song.init_from_dict怎么用?Python Song.init_from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类song.Song
的用法示例。
在下文中一共展示了Song.init_from_dict方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: choose_file_and_convert
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def choose_file_and_convert(self):
filename = WinFile(False).run()
if filename and common.file_is_supported(filename):
tags = {"uri" : utils.get_uri_from_path(filename)}
s = Song()
s.init_from_dict(tags)
s.read_from_file()
AttributesUI([s]).show_window()
示例2: load
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def load(self):
'''load songs and playlists from db file'''
self.logdebug("Loading library...")
# Load songs
try:
db_objs = utils.load_db(get_config_file("songs.db"))
except:
self.logexception("Failed to load library")
db_objs = []
# Load playlists
try:
pls_objs = utils.load_db(get_config_file("playlists.db"))
except:
self.logexception("Failed load playlists")
pls_objs = []
if db_objs:
for obj in db_objs:
try:
song_type = obj["song_type"]
except KeyError:
self.logerror("Song with no type found, %s", obj.get("uri"))
if song_type not in self.__song_types:
self.logwarn("Song type %s not exist, for registration", song_type)
self.register_type(song_type)
if self.__force_check:
s = Song()
s.init_from_dict(obj)
s["uri"] = utils.realuri(s.get("uri"))
else:
s = Song(obj)
s.set_type(song_type)
if not self.__force_check or not self.__songs.has_key(s.get("uri")):
self.add(s)
if pls_objs:
for pl_obj in pls_objs:
name, infos = pl_obj
if self.__force_check:
infos = map(utils.realuri, infos)
self.create_playlist("local", name, infos)
if self.__force_check:
self.save()
self.__dirty = False
# fire signal
self.__reset_queued_signal()
gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save)
gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal)
self.logdebug("%s songs loaded in %s types", len(self.__songs), len(self.__song_types))
self.logdebug("Finish loading library")
gobject.idle_add(self.__delay_post_load)
示例3: __create_song
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def __create_song(self, tags, song_type, read_from_file=False):
'''create song'''
s = Song()
s.init_from_dict(tags)
s.set_type(song_type)
if read_from_file:
s.read_from_file()
self.add(s)
return s
示例4: load
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def load(self):
objs = utils.load_db(self.db_file)
songs = []
if objs:
for obj in objs:
s = Song()
s.init_from_dict(obj, cmp_key="sid")
songs.append(s)
if songs:
self.add_songs(songs)
示例5: post_mount_cb
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def post_mount_cb(self, track_infos, device_path, udi):
track_tags, cd_label = track_infos
if len(track_tags) > 0:
songs = []
for tag in track_tags:
cd_song = Song()
cd_song.init_from_dict(tag)
cd_song.set_type("cdda")
songs.append(cd_song)
Dispatcher.new_audiocd_playlist(cd_label, songs, udi)
self.audiocd_items[udi] = songs
示例6: create_song
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def create_song(self, tags):
# Set dirty flag.
self.set_dirty()
s = Song()
s.init_from_dict(tags)
s.set_type(self.__type)
self.add(s)
return s
示例7: load_status
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def load_status(self):
obj = utils.load_db(self.status_db_file)
if obj:
index, d = obj
song = Song()
song.init_from_dict(d, cmp_key="sid")
else:
index = 0
song = None
self.playlist_index = index
self.last_song = song
示例8: reload_song_from_file
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def reload_song_from_file(self, song):
s = Song()
s.init_from_dict({"uri":song.get("uri")})
s["uri"] = utils.realuri(s.get("uri"))
s.read_from_file()
new_tags = {}
for key in TAG_KEYS.values() + ["#size", "#mtime", "ctime"]:
if s.has_key(key) and not song.has_key(key):
new_tags[key] = s.get(key)
elif not s.has_key(key) and song.has_key(key):
new_tags[key] = song.get(key)
elif s.get(key) != song.get(key):
new_tags[key] = s.get(key)
self.set_property(song, new_tags)
示例9: load
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def load(self):
objs = utils.load_db(self.listen_db_file)
if objs:
items = []
for title, bsongs in objs:
item = MusicListItem(title, list_type=MusicListItem.LOCAL_TYPE)
songs = []
for d in bsongs:
s = Song()
s.init_from_dict(d, cmp_key="sid")
songs.append(s)
item.add_songs(songs)
items.append(item)
self.category_list.add_items(items, insert_pos=1)
示例10: parser_song
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def parser_song(self, douban_song):
for douban_tag , tag in TAGS_DOUBAN_KEYS.iteritems():
if douban_song.has_key(douban_tag):
douban_song[tag] = douban_song[douban_tag]
del douban_song[douban_tag]
for key, value in douban_song.iteritems():
if key == "album_url":
douban_song[key] = urlparse.urljoin("http://music.douban.com", value)
if key in "album title company".split():
douban_song[key] = value.encode("utf-8", "ignore")
song = Song()
song.init_from_dict(douban_song)
song.set_type("douban")
return song
示例11: on_drag_data_received
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def on_drag_data_received(self, widget, context, x, y, selection, info, timestamp):
root_y = widget.allocation.y + y
try:
pos = self.get_coordinate_row(root_y)
except: pos = None
if pos == None:
pos = len(self.items)
if selection.target == "text/deepin-webcasts":
webcasts_data = selection.data
webcast_taglists = eval(webcasts_data)
webcasts = []
for tag in webcast_taglists:
webcast = Song()
webcast.init_from_dict(tag)
webcast.set_type("webcast")
webcasts.append(webcast)
self.add_webcasts(webcasts)
示例12: getattr
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
has_key = "has_key"
else:
has_key = "hasOwnProperty"
try:
bsong = ret
bfile = ret['file_list'][0]
for btag, tag in TAGS_MUSIC_KEYS.iteritems():
if getattr(bsong, has_key)(btag):
song[tag] = bsong[btag]
if getattr(bfile, has_key)(btag):
if btag == "duration":
song[tag] = bfile[btag] * 1000
else:
song[tag] = bfile[btag]
except Exception, e:
import sys
import traceback
traceback.print_exc(file=sys.stdout)
return None
else:
song["fetch_time"] = time.time()
if is_dummy:
new_song = Song()
new_song.init_from_dict(song, cmp_key="sid")
new_song.set_type('baidumusic')
return new_song
return song
示例13: WebcastListItem
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
class WebcastListItem(gobject.GObject):
__gsignals__ = {"redraw-request" : ( gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),}
def __init__(self, tags, draw_collect=False):
gobject.GObject.__init__(self)
self.webcast = Song()
self.webcast.init_from_dict(tags)
self.webcast.set_type("webcast")
if draw_collect:
self.is_collected = True
else:
self.is_collected = WebcastsDB.is_collected(tags["uri"])
self.webcast["collect"] = self.is_collected
self.index = None
self.webcast_normal_pixbuf = app_theme.get_pixbuf("webcast/webcast_normal.png").get_pixbuf()
self.webcast_press_pixbuf = app_theme.get_pixbuf("webcast/webcast_press.png").get_pixbuf()
self.collect_normal_pixbuf = app_theme.get_pixbuf("webcast/collect_normal.png").get_pixbuf()
self.collect_press_pixbuf = app_theme.get_pixbuf("webcast/collect_press.png").get_pixbuf()
self.__update_size()
def set_index(self, index):
self.index = index
def get_index(self):
return self.index
def emit_redraw_request(self):
self.emit("redraw-request")
def __update_size(self):
self.title = self.webcast.get_str("title")
self.webcast_icon_padding_x = 10
self.webcast_icon_padding_y = 5
self.webcast_icon_w = self.webcast_normal_pixbuf.get_width()
self.webcast_icon_h = self.webcast_normal_pixbuf.get_height()
self.title_padding_x = 5
self.title_padding_y = 5
self.title_w, self.title_h = get_content_size(self.title, DEFAULT_FONT_SIZE)
self.collect_icon_padding_x = 2
self.collect_icon_padding_y = 5
self.collect_icon_w = self.collect_normal_pixbuf.get_width()
self.collect_icon_h = self.collect_normal_pixbuf.get_height()
def render_webcast_icon(self, cr, rect, in_select, in_highlight):
icon_x = rect.x + self.webcast_icon_padding_x
icon_y = rect.y + (rect.height - self.webcast_icon_h) / 2
if in_select:
pixbuf = self.webcast_press_pixbuf
else:
pixbuf = self.webcast_normal_pixbuf
draw_pixbuf(cr, pixbuf, icon_x, icon_y)
def render_title(self, cr, rect, in_select, in_highlight):
rect.x += self.title_padding_x
rect.width -= self.title_padding_x * 2
render_item_text(cr, self.title, rect, in_select, in_highlight)
def render_collect_icon(self, cr, rect, in_select, in_highlight):
icon_y = rect.y + (rect.height - self.collect_icon_h) / 2
rect.x += self.collect_icon_padding_x
if self.is_collected:
pixbuf = self.collect_press_pixbuf
else:
pixbuf = self.collect_normal_pixbuf
draw_pixbuf(cr, pixbuf, rect.x , icon_y)
def render_block(self, cr, rect, in_select, in_highlight):
pass
def get_column_sizes(self):
return [
(self.webcast_icon_w + self.webcast_icon_padding_x * 2, self.webcast_icon_h + self.webcast_icon_padding_y * 2),
(360, self.title_h + self.title_padding_y * 2),
(self.collect_icon_w + self.collect_icon_padding_x * 2, self.collect_icon_h + self.collect_icon_padding_y * 2),
(50, 1)
]
def get_renders(self):
return [self.render_webcast_icon, self.render_title, self.render_collect_icon, self.render_block]
def toggle_is_collected(self):
if self.is_collected:
self.is_collected = False
else:
self.is_collected = True
self.webcast["collect"] = self.is_collected
self.emit_redraw_request()
def set_draw_collect(self, value):
self.draw_collect_flag = value
self.emit_redraw_request()
def get_tags(self):
#.........这里部分代码省略.........
示例14: write_tags
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import init_from_dict [as 别名]
def write_tags(self):
tags = deepcopy(self.raw_song)
tags["uri"] = utils.get_uri_from_path(self.output_path)
s = Song()
s.init_from_dict(tags)
s.write_to_file()