本文整理汇总了Python中mpdhelper.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_song
def _update_song(self, songinfo):
artistlabel = self.info_labels['artist']
tracklabel = self.info_labels['track']
albumlabel = self.info_labels['album']
filelabel = self.info_labels['file']
for name in ['title', 'date', 'genre']:
label = self.info_labels[name]
label.set_text(mpdh.get(songinfo, name))
tracklabel.set_text(mpdh.get(songinfo, 'track', '', False))
artistlabel.set_markup(misc.link_markup(misc.escape_html(
mpdh.get(songinfo, 'artist')), False, False,
self.linkcolor))
albumlabel.set_markup(misc.link_markup(misc.escape_html(
mpdh.get(songinfo, 'album')), False, False,
self.linkcolor))
path = misc.file_from_utf8(os.path.join(self.config.musicdir[self.config.profile_num], mpdh.get(songinfo, 'file')))
if os.path.exists(path):
filelabel.set_text(os.path.join(self.config.musicdir[self.config.profile_num], mpdh.get(songinfo, 'file')))
self._editlabel.set_markup(misc.link_markup(_("edit tags"), True, True, self.linkcolor))
else:
filelabel.set_text(mpdh.get(songinfo, 'file'))
self._editlabel.set_text("")
示例2: _artwork_update
def _artwork_update(self):
if 'name' in self.songinfo:
# Stream
streamfile = self.artwork_stream_filename(mpdh.get(self.songinfo, 'name'))
if os.path.exists(streamfile):
gobject.idle_add(self.artwork_set_image, streamfile, None, None, None)
else:
self.artwork_set_default_icon()
return
else:
# Normal song:
artist = mpdh.get(self.songinfo, 'artist', "")
album = mpdh.get(self.songinfo, 'album', "")
path = os.path.dirname(mpdh.get(self.songinfo, 'file'))
if len(artist) == 0 and len(album) == 0:
self.artwork_set_default_icon(artist, album, path)
return
filename = self.target_image_filename()
if filename == self.lastalbumart:
# No need to update..
self.stop_art_update = False
return
self.lastalbumart = None
imgfound = self.artwork_check_for_local(artist, album, path)
if not imgfound:
if self.config.covers_pref == consts.ART_LOCAL_REMOTE:
imgfound = self.artwork_check_for_remote(artist, album, path, filename)
示例3: post
def post(self, prevsonginfo):
self.init()
if self.config.as_enabled and self.scrob_post and prevsonginfo:
if 'artist' in prevsonginfo and \
'title' in prevsonginfo and \
'time' in prevsonginfo:
if not 'album' in prevsonginfo:
album = u''
else:
album = mpdh.get(prevsonginfo, 'album')
if not 'track' in prevsonginfo:
tracknumber = u''
else:
tracknumber = mpdh.get(prevsonginfo, 'track')
try:
self.scrob_post.addtrack(mpdh.get(prevsonginfo, 'artist'),
mpdh.get(prevsonginfo, 'title'),
mpdh.get(prevsonginfo, 'time'),
self.scrob_start_time,
tracknumber,
album)
except:
print sys.exc_info()[1]
thread = threading.Thread(target=self.do_post)
thread.setDaemon(True)
thread.start()
self.scrob_start_time = ""
示例4: _show_lyrics
def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None):
# For error messages where there is no appropriate info:
if not artist_then or not title_then:
self._searchlabel.set_markup('')
self._editlyricslabel.set_markup('')
if error:
self.lyricsText.set_markup(error)
elif lyrics:
self.lyricsText.set_markup(lyrics)
else:
self.lyricsText.set_markup('')
return
# Verify that we are displaying the correct lyrics:
songinfo = self.get_playing_song()
if not songinfo:
return
artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None))
title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None))
if artist_now == artist_then and title_now == title_then:
self._searchlabel.set_markup(misc.link_markup(
_('search'), True, True, self.linkcolor))
self._editlyricslabel.set_markup(misc.link_markup(
_('edit'), True, True, self.linkcolor))
if error:
self.lyricsText.set_markup(error)
elif lyrics:
try:
self.lyricsText.set_markup(misc.escape_html(lyrics))
except: # XXX why would this happen?
self.lyricsText.set_text(lyrics)
else:
self.lyricsText.set_markup('')
示例5: _artwork_update
def _artwork_update(self):
if 'name' in self.songinfo:
# Stream
streamfile = self.artwork_stream_filename(mpdh.get(self.songinfo, 'name'))
if os.path.exists(streamfile):
gobject.idle_add(self.artwork_set_image, streamfile, None, None, None)
else:
self.artwork_set_default_icon()
else:
# Normal song:
artist = mpdh.get(self.songinfo, 'artist', "")
album = mpdh.get(self.songinfo, 'album', "")
filepath = mpdh.get(self.songinfo, 'file')
path = os.path.dirname(filepath)
if len(artist) == 0 and len(album) == 0:
self.artwork_set_default_icon(artist, album, path)
return
try:
response = urllib2.urlopen('http://player.thelogin.ru/cover-for-file/%s' %\
urllib.quote(filepath))
headers = response.info()
filename = headers.get("X-Cover-Path")
if filename:
filename = os.path.join(self.config.musicdir[self.config.profile_num], filename)
gobject.idle_add(self.artwork_set_image, filename, artist, album, path)
except Exception:
pass
示例6: get_path_child_filenames
def get_path_child_filenames(self, return_root):
# If return_root=True, return main directories whenever possible
# instead of individual songs in order to reduce the number of
# mpd calls we need to make. We won't want this behavior in some
# instances, like when we want all end files for editing tags
items = []
model, selected = self.library_selection.get_selected_rows()
for path in selected:
i = model.get_iter(path)
pb = model.get_value(i, 0)
data = model.get_value(i, 1)
value = model.get_value(i, 2)
if value != ".." and value != "/":
album, artist, year, genre, path = self.library_get_data(data, 'album', 'artist', 'year', 'genre', 'path')
if path is not None and album is None and artist is None and year is None and genre is None:
if pb == self.sonatapb:
# File
items.append(path)
else:
# Directory
if not return_root:
items = items + self.library_get_path_files_recursive(path)
else:
items.append(path)
else:
results, _playtime, _num_songs = self.library_return_search_items(genre=genre, artist=artist, album=album, year=year)
results.sort(key=lambda x: (unicode(mpdh.get(x, 'genre', 'zzz')).lower(), unicode(mpdh.get(x, 'artist', 'zzz')).lower(), unicode(mpdh.get(x, 'album', 'zzz')).lower(), mpdh.getnum(x, 'disc', '0', True, 0), mpdh.getnum(x, 'track', '0', True, 0), mpdh.get(x, 'file')))
for item in results:
items.append(mpdh.get(item, 'file'))
# Make sure we don't have any EXACT duplicates:
items = misc.remove_list_duplicates(items, case=True)
return items
示例7: _show_lyrics
def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None):
# For error messages where there is no appropriate info:
if not artist_then or not title_then:
self._searchlabel.set_markup("")
self._editlyricslabel.set_markup("")
if error:
self.lyricsText.get_buffer().set_text(error)
elif lyrics:
self.lyricsText.get_buffer().set_text(lyrics)
else:
self.lyricsText.get_buffer().set_text("")
return
# Verify that we are displaying the correct lyrics:
songinfo = self.get_playing_song()
if not songinfo:
return
artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None))
title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None))
if artist_now == artist_then and title_now == title_then:
self._searchlabel.set_markup(misc.link_markup(
_("search"), True, True, self.linkcolor))
self._editlyricslabel.set_markup(misc.link_markup(
_("edit"), True, True, self.linkcolor))
if error:
self.lyricsText.get_buffer().set_text(error)
elif lyrics:
self._set_lyrics(lyrics)
else:
self.lyricsText.get_buffer().set_text("")
示例8: library_get_path_files_recursive
def library_get_path_files_recursive(self, path):
results = []
for item in mpdh.call(self.client, 'lsinfo', path):
if 'directory' in item:
results = results + self.library_get_path_files_recursive(mpdh.get(item, 'directory'))
elif 'file' in item:
results.append(mpdh.get(item, 'file'))
return results
示例9: libsearchfilter_do_search
def libsearchfilter_do_search(self, searchby, todo):
if not self.prevlibtodo_base in todo:
# Do library search based on first two letters:
self.prevlibtodo_base = todo[:2]
self.prevlibtodo_base_results = mpdh.call(self.client, 'search', searchby, self.prevlibtodo_base)
subsearch = False
else:
subsearch = True
# Now, use filtering similar to playlist filtering:
# this make take some seconds... and we'll escape the search text because
# we'll be searching for a match in items that are also escaped.
todo = misc.escape_html(todo)
todo = re.escape(todo)
todo = '.*' + todo.replace(' ', ' .*').lower()
regexp = re.compile(todo)
matches = []
if searchby != 'any':
for row in self.prevlibtodo_base_results:
if regexp.match(unicode(mpdh.get(row, searchby)).lower()):
matches.append(row)
else:
for row in self.prevlibtodo_base_results:
for meta in row:
if regexp.match(unicode(mpdh.get(row, meta)).lower()):
matches.append(row)
break
if subsearch and len(matches) == len(self.librarydata):
# nothing changed..
return
self.library.freeze_child_notify()
currlen = len(self.librarydata)
newlist = []
for item in matches:
if 'file' in item:
newlist.append([self.sonatapb, self.library_set_data(path=mpdh.get(item, 'file')), self.parse_formatting(self.config.libraryformat, item, True)])
for i, item in enumerate(newlist):
if i < currlen:
j = self.librarydata.get_iter((i, ))
for index in range(len(item)):
if item[index] != self.librarydata.get_value(j, index):
self.librarydata.set_value(j, index, item[index])
else:
self.librarydata.append(item)
# Remove excess items...
newlen = len(newlist)
if newlen == 0:
self.librarydata.clear()
else:
for i in range(currlen-newlen):
j = self.librarydata.get_iter((currlen-1-i,))
self.librarydata.remove(j)
self.library.thaw_child_notify()
if len(matches) == 0:
gobject.idle_add(self.filtering_entry_make_red, self.searchtext)
else:
gobject.idle_add(self.library.set_cursor,'0')
gobject.idle_add(self.filtering_entry_revert_color, self.searchtext)
示例10: _update_lyrics
def _update_lyrics(self, songinfo):
if self.config.show_lyrics:
if 'artist' in songinfo and 'title' in songinfo:
self.get_lyrics_start(mpdh.get(songinfo, 'artist'),
mpdh.get(songinfo, 'title'),
mpdh.get(songinfo, 'artist'),
mpdh.get(songinfo, 'title'),
os.path.dirname(mpdh.get(songinfo, 'file')))
else:
self._show_lyrics(None, None,
error=_('Artist or song title not set.'))
示例11: get_selected_filenames
def get_selected_filenames(self, return_abs_paths):
_model, selected = self.current_selection.get_selected_rows()
filenames = []
for path in selected:
if not self.filterbox_visible:
item = mpdh.get(self.current_songs[path[0]], "file")
else:
item = mpdh.get(self.current_songs[self.filter_row_mapping[path[0]]], "file")
if return_abs_paths:
filenames.append(self.config.musicdir[self.config.profile_num] + item)
else:
filenames.append(item)
return filenames
示例12: library_return_count
def library_return_count(self, genre=None, artist=None, album=None, year=None):
# Because mpd's 'count' is case sensitive, we have to
# determine all equivalent items (case insensitive) and
# call 'count' for each of them. Using 'list' + 'count'
# involves much less data to be transferred back and
# forth than to use 'search' and count manually.
searches = self.library_compose_list_count_searchlist(genre, artist, album, year)
playtime = 0
num_songs = 0
for s in searches:
count = mpdh.call(self.client, 'count', *s)
playtime += int(mpdh.get(count, 'playtime'))
num_songs += int(mpdh.get(count, 'songs'))
return (playtime, num_songs)
示例13: handle_change_status
def handle_change_status(self, state, prevstate, prevsonginfo,
songinfo=None, mpd_time_now=None):
"""Handle changes to play status, submitting info as appropriate"""
if prevsonginfo and 'time' in prevsonginfo:
prevsong_time = mpdh.get(prevsonginfo, 'time')
else:
prevsong_time = None
if state in ('play', 'pause'):
elapsed_prev = self.elapsed_now
self.elapsed_now, length = [float(c) for c in
mpd_time_now.split(':')]
current_file = mpdh.get(songinfo, 'file')
if prevstate == 'stop':
# Switched from stop to play, prepare current track:
self.prepare(songinfo)
elif (prevsong_time and
(self.scrob_last_prepared != current_file or
(self.scrob_last_prepared == current_file and
elapsed_prev and abs(elapsed_prev - length) <= 2 and
self.elapsed_now <= 2 and length > 0))):
# New song is playing, post previous track if time criteria is
# met. In order to account for the situation where the same
# song is played twice in a row, we will check if the previous
# time was the end of the song and we're now at the beginning
# of the same song.. this technically isn't right in the case
# where a user seeks back to the beginning, but that's an edge
# case.
if self.scrob_playing_duration > 4 * 60 or \
self.scrob_playing_duration > int(prevsong_time) / 2:
if self.scrob_start_time != "":
self.post(prevsonginfo)
# Prepare current track:
self.prepare(songinfo)
# Keep track of the total amount of time that the current song
# has been playing:
now = time.time()
if prevstate != 'pause':
self.scrob_playing_duration += now - self.scrob_prev_time
self.scrob_prev_time = now
else: # stopped:
self.elapsed_now = 0
if prevsong_time:
if self.scrob_playing_duration > 4 * 60 or \
self.scrob_playing_duration > int(prevsong_time) / 2:
# User stopped the client, post previous track if time
# criteria is met:
if self.scrob_start_time != "":
self.post(prevsonginfo)
示例14: library_populate_data_songs
def library_populate_data_songs(self, genre, artist, album, year):
bd = []
if genre is not None:
songs, _playtime, _num_songs = self.library_return_search_items(genre=genre, artist=artist, album=album, year=year)
else:
songs, _playtime, _num_songs = self.library_return_search_items(artist=artist, album=album, year=year)
for song in songs:
data = self.library_set_data(path=mpdh.get(song, 'file'))
track = mpdh.getnum(song, 'track', '99', False, 2)
disc = mpdh.getnum(song, 'disc', '99', False, 2)
try:
bd += [('f' + disc + track + misc.lower_no_the(mpdh.get(song, 'title')), [self.sonatapb, data, self.parse_formatting(self.config.libraryformat, song, True)])]
except:
bd += [('f' + disc + track + unicode(mpdh.get(song, 'file')).lower(), [self.sonatapb, data, self.parse_formatting(self.config.libraryformat, song, True)])]
return bd
示例15: update_format
def update_format(self):
for track in self.current_songs:
items = []
for part in self.columnformat:
items += [self.parse_formatting(part, track, True)]
self.currentdata.append([int(mpdh.get(track, "id"))] + items)