本文整理匯總了Python中lollypop.radios.Radios類的典型用法代碼示例。如果您正苦於以下問題:Python Radios類的具體用法?Python Radios怎麽用?Python Radios使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Radios類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: prev
def prev(self):
"""
Return prev radio name, uri
@return Track
"""
track = Track()
if self.current_track.id != Type.RADIOS:
return track
radios_manager = Radios()
radios = radios_manager.get()
i = len(radios) - 1
for (name, url) in reversed(radios):
i -= 1
if self.current_track.album_artist == name:
break
# Get prev radio
if i < 0:
i = len(radios) - 1
name = radios[i][0]
url = radios[i][1]
if url:
track.set_radio(name, url)
return track
示例2: prepare_to_exit
def prepare_to_exit(self, action=None, param=None):
"""
Save window position and view
"""
if self._is_fs:
return
if self.settings.get_value('save-state'):
self.window.save_view_state()
# Save current track
if self.player.current_track.id is None:
track_id = -1
elif self.player.current_track.id == Type.RADIOS:
radios = Radios()
track_id = radios.get_id(
self.player.current_track.album_artist)
else:
track_id = self.player.current_track.id
self.settings.set_value('track-id', GLib.Variant('i',
track_id))
# Save current playlist
if self.player.current_track.id == Type.RADIOS:
playlist_ids = [Type.RADIOS]
elif not self.player.get_user_playlist_ids():
playlist_ids = []
else:
playlist_ids = self.player.get_user_playlist_ids()
self.settings.set_value('playlist-ids', GLib.Variant('ai',
playlist_ids))
self.player.stop_all()
if self.window:
self.window.stop_all()
self.quit()
示例3: next
def next(self):
"""
Return next radio name, uri
@return Track
"""
track = Track()
if self.current_track.id != Type.RADIOS:
return track
radios_manager = Radios()
radios = radios_manager.get()
i = 0
for (name, url) in radios:
i += 1
if self.current_track.album_artist == name:
break
# Get next radio
if i >= len(radios):
i = 0
name = radios[i][0]
url = radios[i][1]
if url:
track.set_radio(name, url)
return track
示例4: restore_state
def restore_state(self):
"""
Restore player state
"""
if Lp().settings.get_value('save-state'):
track_id = Lp().settings.get_value('track-id').get_int32()
playlist_ids = Lp().settings.get_value('playlist-ids')
if playlist_ids and playlist_ids[0] == Type.RADIOS:
radios = Radios()
track = Track()
name = radios.get_name(track_id)
url = radios.get_url(name)
track.set_radio(name, url)
self.load(track)
elif Lp().tracks.get_path(track_id) != "":
track = Track(track_id)
self._load_track(track)
if playlist_ids:
try:
pids = []
for playlist_id in playlist_ids:
pids.append(int(playlist_id))
track_ids = []
for playlist_id in playlist_ids:
if playlist_id == Type.POPULARS:
tracks = Lp().tracks.get_populars()
elif playlist_id == Type.RECENTS:
tracks = Lp().tracks.get_recently_listened_to()
elif playlist_id == Type.NEVER:
tracks = Lp().tracks.get_never_listened_to()
elif playlist_id == Type.RANDOMS:
tracks = Lp().tracks.get_randoms()
else:
tracks = Lp().playlists.get_tracks_ids(
playlist_id)
for track_id in tracks:
if track_id not in track_ids:
track_ids.append(track_id)
self.populate_user_playlist_by_tracks(track_ids,
pids)
except:
pass # User set non int in gsettings
else:
self._albums = Lp().artists.get_albums(
track.album_artist_ids)
for album_id in self._albums:
self.context.genre_ids[album_id] = []
self.context.artist_ids[album_id] = []
self.set_next()
self.set_prev()
if Lp().settings.get_value('repeat'):
self.context.next = NextContext.NONE
else:
self.context.next = NextContext.STOP_ALL
self.emit('current-changed')
else:
print("Player::restore_state(): track missing")
示例5: prepare_to_exit
def prepare_to_exit(self, action=None, param=None, exit=True):
"""
Save window position and view
"""
if self.__is_fs:
return
if self.settings.get_value('save-state'):
self.window.save_view_state()
# Save current track
if self.player.current_track.id is None:
track_id = -1
elif self.player.current_track.id == Type.RADIOS:
from lollypop.radios import Radios
radios = Radios()
track_id = radios.get_id(
self.player.current_track.album_artists[0])
else:
track_id = self.player.current_track.id
# Save albums context
try:
dump(self.player.context.genre_ids,
open(DataPath + "/genre_ids.bin", "wb"))
dump(self.player.context.artist_ids,
open(DataPath + "/artist_ids.bin", "wb"))
self.player.shuffle_albums(False)
dump(self.player.get_albums(),
open(DataPath + "/albums.bin", "wb"))
except Exception as e:
print("Application::prepare_to_exit()", e)
dump(track_id, open(DataPath + "/track_id.bin", "wb"))
dump([self.player.is_playing, self.player.is_party],
open(DataPath + "/player.bin", "wb"))
# Save current playlist
if self.player.current_track.id == Type.RADIOS:
playlist_ids = [Type.RADIOS]
elif not self.player.get_user_playlist_ids():
playlist_ids = []
else:
playlist_ids = self.player.get_user_playlist_ids()
dump(playlist_ids,
open(DataPath + "/playlist_ids.bin", "wb"))
if self.player.current_track.id is not None:
position = self.player.position
else:
position = 0
dump(position, open(DataPath + "/position.bin", "wb"))
self.player.stop_all()
self.window.stop_all()
if self.charts is not None:
self.charts.stop()
if exit:
self.quit()
示例6: set_popularity
def set_popularity(self, popularity):
"""
Set popularity
@param popularity as int between 0 and 5
"""
if self.id is None or self.id == Type.EXTERNALS:
return
try:
if self.id >= 0:
avg_popularity = self.db.get_avg_popularity()
popularity = int((popularity * avg_popularity / 5) + 0.5)
self.db.set_popularity(self.id, popularity, True)
elif self.id == Type.RADIOS:
radios = Radios()
avg_popularity = radios.get_avg_popularity()
popularity = int((popularity * avg_popularity / 5) + 0.5)
radios.set_popularity(self._album_artists[0], popularity)
except Exception as e:
print("Base::set_popularity(): %s" % e)
示例7: get_popularity
def get_popularity(self):
"""
Get popularity
@return int between 0 and 5
"""
if self.id is None or self.id == Type.EXTERNALS:
return 0
popularity = 0
if self.id >= 0:
avg_popularity = self.db.get_avg_popularity()
if avg_popularity > 0:
popularity = self.db.get_popularity(self.id)
elif self.id == Type.RADIOS:
radios = Radios()
avg_popularity = radios.get_avg_popularity()
if avg_popularity > 0:
popularity = radios.get_popularity(self._album_artists[0])
return popularity * 5 / avg_popularity + 0.5
示例8: __init__
def __init__(self, radios_manager=None):
"""
Init Popover
@param radios_manager as Radios
"""
Gtk.Popover.__init__(self)
self._tunein = TuneIn()
if radios_manager is not None:
self._radios_manager = radios_manager
else:
self._radios_manager = Radios()
self._current_url = None
self._timeout_id = None
self._previous_urls = []
self._covers_to_download = []
self._stack = Gtk.Stack()
self._stack.set_property('expand', True)
self._stack.show()
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Lollypop/TuneinPopover.ui')
builder.connect_signals(self)
widget = builder.get_object('widget')
widget.attach(self._stack, 0, 2, 5, 1)
self._back_btn = builder.get_object('back_btn')
self._home_btn = builder.get_object('home_btn')
self._label = builder.get_object('label')
self._view = Gtk.FlowBox()
self._view.set_selection_mode(Gtk.SelectionMode.NONE)
self._view.set_max_children_per_line(100)
self._view.set_property('row-spacing', 10)
self._view.set_property('expand', True)
self._view.show()
self._spinner = builder.get_object('spinner')
builder.get_object('viewport').add(self._view)
builder.get_object('viewport').set_property('margin', 10)
self._scrolled = builder.get_object('scrolled')
self._stack.add_named(self._spinner, 'spinner')
self._stack.add_named(builder.get_object('notfound'), 'notfound')
self._stack.add_named(self._scrolled, 'scrolled')
self.add(widget)
size_setting = Lp().settings.get_value('window-size')
if isinstance(size_setting[1], int):
self.set_size_request(700, size_setting[1]*0.7)
else:
self.set_size_request(700, 400)
示例9: quit
def quit(self):
"""
Quit lollypop
"""
if Lp.scanner.is_locked():
Lp.scanner.stop()
GLib.idle_add(self.quit)
return
try:
Lp.sql.execute('VACUUM')
sql_p = Lp.playlists.get_cursor()
sql_p.execute('VACUUM')
sql_p.close()
radios = Radios()
sql_r = radios.get_cursor()
sql_r.execute('VACUUM')
sql_r.close()
except Exception as e:
print("Application::quit(): ", e)
Lp.window.destroy()
Lp.sql.close()
Gst.deinit()
示例10: __init__
def __init__(self, radios_manager=None):
"""
Init Popover
@param radios_manager as Radios
"""
Gtk.Popover.__init__(self)
self._tunein = TuneIn()
if radios_manager is not None:
self._radios_manager = radios_manager
else:
self._radios_manager = Radios()
self._current_url = None
self._previous_urls = []
self._stack = Gtk.Stack()
self._stack.set_property("expand", True)
self._stack.show()
builder = Gtk.Builder()
builder.add_from_resource("/org/gnome/Lollypop/TuneinPopover.ui")
builder.connect_signals(self)
widget = builder.get_object("widget")
widget.attach(self._stack, 0, 2, 4, 1)
self._back_btn = builder.get_object("back_btn")
self._home_btn = builder.get_object("home_btn")
self._label = builder.get_object("label")
self._view = Gtk.FlowBox()
self._view.set_selection_mode(Gtk.SelectionMode.NONE)
self._view.set_max_children_per_line(100)
self._view.set_property("row-spacing", 10)
self._view.set_property("expand", True)
self._view.show()
builder.get_object("viewport").add(self._view)
builder.get_object("viewport").set_property("margin", 10)
self._scrolled = builder.get_object("scrolled")
self._stack.add_named(builder.get_object("spinner"), "spinner")
self._stack.add_named(builder.get_object("notfound"), "notfound")
self._stack.add_named(self._scrolled, "scrolled")
self._stack.set_visible_child_name("spinner")
self.add(widget)
size_setting = Lp().settings.get_value("window-size")
if isinstance(size_setting[1], int):
self.set_size_request(700, size_setting[1] * 0.7)
else:
self.set_size_request(700, 400)
示例11: __init__
def __init__(self):
"""
Init view
"""
View.__init__(self)
self._signal = Lp().art.connect('radio-artwork-changed',
self._on_logo_changed)
self._radios_manager = Radios()
self._radios_manager.connect('radios-changed',
self._on_radios_changed)
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Lollypop/RadiosView.ui')
builder.connect_signals(self)
widget = builder.get_object('widget')
self._empty = builder.get_object('empty')
self._pop_tunein = TuneinPopover(self._radios_manager)
self._pop_tunein.set_relative_to(builder.get_object('search_btn'))
self._sizegroup = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.BOTH)
self._radiobox = Gtk.FlowBox()
self._radiobox.set_selection_mode(Gtk.SelectionMode.NONE)
self._radiobox.connect("child-activated", self._on_album_activated)
self._radiobox.set_property('column-spacing', 5)
self._radiobox.set_property('row-spacing', 5)
self._radiobox.set_homogeneous(True)
self._radiobox.set_max_children_per_line(1000)
self._radiobox.show()
self._stack = Gtk.Stack()
self._stack.set_transition_duration(500)
self._stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
self._stack.add(self._scrolled)
self._stack.add(self._empty)
self._stack.show()
self._viewport.set_property("valign", Gtk.Align.START)
self._viewport.set_property('margin', 5)
self._viewport.add(self._radiobox)
self._scrolled.set_property('expand', True)
self.add(widget)
self.add(self._stack)
示例12: __init__
def __init__(self):
"""
Init view
"""
LazyLoadingView.__init__(self, True)
self.__signal = Lp().art.connect('radio-artwork-changed',
self.__on_logo_changed)
self.__radios_manager = Radios()
self.__radios_manager.connect('radios-changed',
self.__on_radios_changed)
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Lollypop/RadiosView.ui')
builder.connect_signals(self)
widget = builder.get_object('widget')
self.__empty = builder.get_object('empty')
self.__pop_tunein = TuneinPopover(self.__radios_manager)
self.__pop_tunein.set_relative_to(builder.get_object('search_btn'))
self._box = Gtk.FlowBox()
self._box.set_selection_mode(Gtk.SelectionMode.NONE)
# Allow lazy loading to not jump up and down
self._box.set_homogeneous(True)
self._box.set_max_children_per_line(1000)
self._box.set_filter_func(self._filter_func)
self._box.show()
self.__stack = Gtk.Stack()
self.__stack.set_transition_duration(500)
self.__stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
self.__stack.add(self._scrolled)
self.__stack.add(self.__empty)
self.__stack.show()
self._viewport.set_property("valign", Gtk.Align.START)
self._viewport.set_property('margin', 5)
self._scrolled.set_property('expand', True)
self.add(widget)
self.add(self.__stack)
示例13: RadiosView
class RadiosView(View):
"""
Show radios in a grid
"""
def __init__(self):
"""
Init view
"""
View.__init__(self)
self._signal = Lp().art.connect('radio-artwork-changed',
self._on_logo_changed)
self._radios_manager = Radios()
self._radios_manager.connect('radios-changed',
self._on_radios_changed)
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Lollypop/RadiosView.ui')
builder.connect_signals(self)
widget = builder.get_object('widget')
self._empty = builder.get_object('empty')
self._pop_tunein = TuneinPopover(self._radios_manager)
self._pop_tunein.set_relative_to(builder.get_object('search_btn'))
self._sizegroup = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.BOTH)
self._radiobox = Gtk.FlowBox()
self._radiobox.set_selection_mode(Gtk.SelectionMode.NONE)
self._radiobox.connect("child-activated", self._on_album_activated)
self._radiobox.set_property('column-spacing', 5)
self._radiobox.set_property('row-spacing', 5)
self._radiobox.set_homogeneous(True)
self._radiobox.set_max_children_per_line(1000)
self._radiobox.show()
self._stack = Gtk.Stack()
self._stack.set_transition_duration(500)
self._stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
self._stack.add(self._scrolled)
self._stack.add(self._empty)
self._stack.show()
self._viewport.set_property("valign", Gtk.Align.START)
self._viewport.set_property('margin', 5)
self._viewport.add(self._radiobox)
self._scrolled.set_property('expand', True)
self.add(widget)
self.add(self._stack)
def populate(self):
"""
Populate view with tracks from playlist
Thread safe
"""
Lp().player.set_radios(self._radios_manager.get())
if Lp().player.current_track.id == Type.RADIOS:
Lp().player.set_next() # We force next update
Lp().player.set_prev() # We force prev update
t = Thread(target=self._populate)
t.daemon = True
t.start()
#######################
# PRIVATE #
#######################
def _populate(self):
"""
Populate view with tracks from playlist
Thread safe
"""
radios = []
# Get radios name
for (name, url) in self._radios_manager.get():
radios.append(name)
GLib.idle_add(self._show_stack, radios)
def _get_children(self):
"""
Return view children
@return [RadioWidget]
"""
children = []
for child in self._radiobox.get_children():
widget = child.get_child()
children.append(widget)
return children
def _on_destroy(self, widget):
"""
Disconnect signals
@param widget as Gtk.Widget
"""
if self._signal is not None:
Lp().art.disconnect(self._signal)
def _on_new_clicked(self, widget):
"""
Show popover for adding a new radio
#.........這裏部分代碼省略.........
示例14: restore_state
def restore_state(self):
"""
Restore player state
"""
try:
if Lp().settings.get_value('save-state'):
track_id = load(open(DataPath + "/track_id.bin", "rb"))
playlist_ids = load(open(DataPath + "/playlist_ids.bin",
"rb"))
if playlist_ids and playlist_ids[0] == Type.RADIOS:
radios = Radios()
track = Track()
name = radios.get_name(track_id)
url = radios.get_url(name)
track.set_radio(name, url)
self.load(track)
elif Lp().tracks.get_path(track_id) != "":
track = Track(track_id)
if Lp().notify is not None:
Lp().notify.inhibit()
self._load_track(track)
# We set this initial state
# because seek while failed otherwise
self.pause()
if playlist_ids:
pids = []
for playlist_id in playlist_ids:
pids.append(int(playlist_id))
track_ids = []
for playlist_id in playlist_ids:
if playlist_id == Type.POPULARS:
tracks = Lp().tracks.get_populars()
elif playlist_id == Type.RECENTS:
tracks = Lp().tracks.get_recently_listened_to()
elif playlist_id == Type.NEVER:
tracks = Lp().tracks.get_never_listened_to()
elif playlist_id == Type.RANDOMS:
tracks = Lp().tracks.get_randoms()
else:
tracks = Lp().playlists.get_track_ids(
playlist_id)
for track_id in tracks:
if track_id not in track_ids:
track_ids.append(track_id)
self.populate_user_playlist_by_tracks(track_ids,
pids)
else:
self._albums = load(open(
DataPath + "/albums.bin",
"rb"))
self.shuffle_albums(True)
self._context.genre_ids = load(open(
DataPath + "/genre_ids.bin",
"rb"))
self._context.artist_ids = load(open(
DataPath + "/artist_ids.bin",
"rb"))
self.set_next()
self.set_prev()
if Lp().settings.get_value('repeat'):
self._context.next = NextContext.NONE
else:
self._context.next = NextContext.STOP_ALL
else:
print("Player::restore_state(): track missing")
except Exception as e:
print("Player::restore_state()", e)
示例15: TuneinPopover
class TuneinPopover(Gtk.Popover):
"""
Popover showing tunin radios
"""
def __init__(self, radios_manager=None):
"""
Init Popover
@param radios_manager as Radios
"""
Gtk.Popover.__init__(self)
self._tunein = TuneIn()
if radios_manager is not None:
self._radios_manager = radios_manager
else:
self._radios_manager = Radios()
self._current_url = None
self._timeout_id = None
self._previous_urls = []
self._covers_to_download = []
self._stack = Gtk.Stack()
self._stack.set_property('expand', True)
self._stack.show()
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Lollypop/TuneinPopover.ui')
builder.connect_signals(self)
widget = builder.get_object('widget')
widget.attach(self._stack, 0, 2, 5, 1)
self._back_btn = builder.get_object('back_btn')
self._home_btn = builder.get_object('home_btn')
self._label = builder.get_object('label')
self._view = Gtk.FlowBox()
self._view.set_selection_mode(Gtk.SelectionMode.NONE)
self._view.set_max_children_per_line(100)
self._view.set_property('row-spacing', 10)
self._view.set_property('expand', True)
self._view.show()
self._spinner = builder.get_object('spinner')
builder.get_object('viewport').add(self._view)
builder.get_object('viewport').set_property('margin', 10)
self._scrolled = builder.get_object('scrolled')
self._stack.add_named(self._spinner, 'spinner')
self._stack.add_named(builder.get_object('notfound'), 'notfound')
self._stack.add_named(self._scrolled, 'scrolled')
self.add(widget)
self.connect('map', self._on_map)
self.connect('unmap', self._on_unmap)
def populate(self, url=None):
"""
Populate views
@param url as string
"""
if url is None and self._current_url is not None:
return
self._spinner.start()
self._clear()
self._stack.set_visible_child_name('spinner')
self._current_url = url
self._back_btn.set_sensitive(False)
self._home_btn.set_sensitive(False)
self._label.set_text(_("Please wait..."))
t = Thread(target=self._populate, args=(url,))
t.daemon = True
t.start()
#######################
# PRIVATE #
#######################
def _show_not_found(self, message=""):
"""
Show not found message
@param message as str
"""
# TODO Add a string
self._label.set_text(message)
self._stack.set_visible_child_name('notfound')
self._home_btn.set_sensitive(True)
def _populate(self, url):
"""
Same as populate()
@param url as string
@thread safe
"""
try:
if url is None:
items = self._tunein.get_items(
"http://opml.radiotime.com/Browse.ashx?c=")
else:
items = self._tunein.get_items(url)
if self._current_url == url:
#.........這裏部分代碼省略.........