-
Notifications
You must be signed in to change notification settings - Fork 7
/
doubanfm_mode.py
369 lines (300 loc) · 13.7 KB
/
doubanfm_mode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2012 Sun Ning <[email protected]>
# Copyright (C) 2012 Yu Shijun <[email protected]>
# Copyright (C) 2012 Liu Guyue <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# The developers of the Exaile media player hereby grant permission
# for non-GPL compatible GStreamer and Exaile plugins to be used and
# distributed together with GStreamer and Exaile. This permission is
# above and beyond the permissions granted by the GPL license by which
# Exaile is covered. If you modify this code, you may extend this
# exception to your version of the code, but you are not obligated to
# do so. If you do not wish to do so, delete this exception statement
# from your version.
import gtk
import gtk.glade
import pango
import cairo
import os
import urllib
from xl import xdg, event, settings, player
from xlgui import cover, tray
from xlgui.widgets.playback import PlaybackProgressBar
from xlgui.widgets import info, playback
from xl.nls import gettext as _
from libdoubanfm import DoubanTrack
def get_resource_path(filename):
basedir = os.path.dirname(os.path.realpath(__file__))
resource = os.path.join(basedir, filename)
return resource
class DoubanFMMode():
def __init__(self, exaile, doubanfm_plugin):
self.exaile = exaile
self.dbfm_plugin = doubanfm_plugin
self.builder = gtk.Builder()
self.builder.add_from_file(get_resource_path('doubanfm_mode.ui'))
self.builder.connect_signals({
'on_bookmark_button_clicked': self.on_bookmark_button_clicked,
'on_skip_button_clicked': self.on_skip_button_clicked,
'on_delete_button_clicked': self.on_delete_button_clicked,
'on_go_home_button_clicked': self.on_go_home_button_clicked,
'on_item_setting_clicked': self.on_button_setting_clicked,
'on_item_album_clicked': self.on_button_album_clicked,
'on_item_report_clicked': self.on_button_report_clicked,
'on_menu_toggle': self.on_menu_toggle,
'on_quit': self.on_quit,
'on_pausebutton_clicked': self.on_pausebutton_clicked,
'on_recommend_song': self.on_recommend_song,
'on_share_sina': self.on_share_sina,
'on_share_renren': self.on_share_renren,
'on_share_kaixin001': self.on_share_kaixin001,
'on_share_twitter': self.on_share_twitter,
'on_share_fanfou': self.on_share_fanfou,
'on_copy_permalink': self.on_copy_permalink,
})
self.window = self.builder.get_object('doubanfm_mode_window')
self.window.connect('destroy', self.hide)
volume = settings.get_option('player/volume', 1)
self.volume_control = playback.VolumeControl(player.PLAYER)
self.builder.get_object('hbox2').pack_start(self.volume_control)
self.cover_box = self.builder.get_object('cover_eventbox1')
self.info_area = info.TrackInfoPane(player.PLAYER)
self.cover = cover.CoverWidget(self.cover_box,player.PLAYER)
# self.cover_box.add(self.cover)
self.track_title_label = self.builder.get_object('track_title_label')
attr = pango.AttrList()
attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 800))
attr.change(pango.AttrSize(12500, 0, 600))
self.track_title_label.set_attributes(attr)
self.track_info_label = self.builder.get_object('track_info_label')
self.bookmark_button = self.builder.get_object('bookmark_button')
self.trash_button = self.builder.get_object('delete_button')
self.skip_button = self.builder.get_object('skip_button')
self.pause_button = self.builder.get_object('pause_button')
self.popup_menu = self.builder.get_object('moremenu')
self.report_menuitem = self.builder.get_object('menuitem1')
self.album_menuitem = self.builder.get_object('menuitem2')
self.recmd_menuitem = self.builder.get_object('menuitem10')
self.sensitive_widgets = [
self.bookmark_button,
self.trash_button,
self.skip_button,
self.pause_button,
self.report_menuitem,
self.album_menuitem,
self.recmd_menuitem,
]
self.progress_bar = playback.PlaybackProgressBar(player.PLAYER)
self.builder.get_object('vbox2').pack_start(self.progress_bar)
self.visible = False
self.active = False
self._build_channel_menu()
event.add_callback(self.on_playback_start, 'playback_track_start', player.PLAYER)
event.add_callback(self.on_playback_stop, 'playback_track_end', player.PLAYER)
event.add_callback(self.on_pausebutton_toggled, 'playback_toggle_pause', player.PLAYER)
event.add_callback(self.on_tag_update, 'track_tags_changed')
self._toggle_id = self.exaile.gui.main.connect('main-visible-toggle', self.toggle_visible)
## added for 0.3.2
self._init_alpha()
def _build_channel_menu(self):
menu = self.builder.get_object('channel_menu')
group = None
for channel_name in self.dbfm_plugin.channels.keys():
menuItem = gtk.RadioMenuItem(group, _(channel_name))
group = group or menuItem
menuItem.connect('toggled', self.on_channel_group_change,
self.dbfm_plugin.channels[channel_name])
menu.prepend(menuItem)
menuItem.show()
def _init_alpha(self):
if settings.get_option('gui/use_alpha', False):
screen = self.window.get_screen()
colormap = screen.get_rgba_colormap()
if colormap is not None:
self.window.set_app_paintable(True)
self.window.set_colormap(colormap)
self.window.connect('expose-event', self.on_expose_event)
self.window.connect('screen-changed', self.on_screen_changed)
def on_expose_event(self, widget, event):
"""
Paints the window alpha transparency
"""
opacity = 1 - settings.get_option('gui/transparency', 0.3)
context = widget.window.cairo_create()
background = widget.style.bg[gtk.STATE_NORMAL]
context.set_source_rgba(
float(background.red) / 256**2,
float(background.green) / 256**2,
float(background.blue) / 256**2,
opacity
)
context.set_operator(cairo.OPERATOR_SOURCE)
context.paint()
def on_screen_changed(self, widget, event):
"""
Updates the colormap on screen change
"""
screen = widget.get_screen()
colormap = screen.get_rgba_colormap() or screen.get_rgb_colormap()
self.window.set_colormap(rgbamap)
def toggle_visible(self, *e):
if not self.active:
return False
if self.visible:
self.window.hide()
else:
self.window.show_all()
self.visible = not self.visible
return True
def show(self, *e):
if not self.visible:
self.exaile.gui.main.window.hide()
self.window.show_all()
self.visible = True
self.active = True
def hide(self, *e):
if self.visible:
self.window.hide()
self.exaile.gui.main.window.show()
self.visible = False
self.active = False
def on_bookmark_button_clicked(self, *e):
track = self.dbfm_plugin.get_current_track()
if track.get_tag_raw("fav")[0] == "1":
self.dbfm_plugin.mark_as_dislike(track)
else :
self.dbfm_plugin.mark_as_like(track)
def on_skip_button_clicked(self, *e):
track = self.dbfm_plugin.get_current_track()
self.dbfm_plugin.mark_as_skip(track)
def on_delete_button_clicked(self, *e):
track = self.dbfm_plugin.get_current_track()
self.dbfm_plugin.mark_as_recycle(track)
def on_go_home_button_clicked(self, *e):
self.hide(e)
def on_playback_start(self, etype, player, *data):
track = player.current
artist = track.get_tag_raw('artist')[0]
album = track.get_tag_raw('album')[0]
title = track.get_tag_raw('title')[0]
self.window.set_title(u"Exaile \u8c46\u74e3FM %s - %s" % (title, artist))
self.track_title_label.set_label("%s - %s" %(title, artist))
self.track_info_label.set_label(album)
if track.get_tag_raw('fav')[0] == "1":
self.bookmark_button.set_image(
gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON))
else:
self.bookmark_button.set_image(
gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON))
self.sensitive(True)
self.pause_button.set_image(
gtk.image_new_from_stock('gtk-media-pause', gtk.ICON_SIZE_BUTTON))
def on_tag_update(self, e, track, tag):
if track != self.dbfm_plugin.get_current_track():
return
if track.get_tag_raw('fav')[0] == "1":
self.bookmark_button.set_image(
gtk.image_new_from_icon_name('emblem-favorite', gtk.ICON_SIZE_BUTTON))
else:
self.bookmark_button.set_image(
gtk.image_new_from_icon_name('bookmark-new', gtk.ICON_SIZE_BUTTON))
def on_playback_stop(self, type, player, data):
self.pause_button.set_image(
gtk.image_new_from_stock('gtk-media-play', gtk.ICON_SIZE_BUTTON))
self.sensitive(False)
def sensitive(self, enable):
for w in self.sensitive_widgets:
w.set_sensitive(enable)
def on_button_setting_clicked(self, *e):
os.popen(' '.join(['xdg-open', 'http://douban.fm/mine']))
def on_button_album_clicked(self, *e):
track = self.dbfm_plugin.get_current_track()
if track is not None:
aid = track.get_tag_raw('aid')[0]
url = "http://music.douban.com/subject/%s/" % aid
os.popen(' '.join(['xdg-open', url]))
def on_button_report_clicked(self, *e):
track = self.dbfm_plugin.get_current_track()
if track is not None:
aid = track.get_tag_raw('aid')[0]
sid = track.get_tag_raw('sid')[0]
url = "http://music.douban.com/subject/%s/report?song_id=%s" % (aid, sid)
os.popen(' '.join(['xdg-open', url]))
def on_share_sina(self, *e):
track = self.dbfm_plugin.get_current_track()
url = self.dbfm_plugin.share('sina', track)
os.popen(' '.join(['xdg-open', '"%s"'%url]))
def on_share_kaixin001(self, *e):
track = self.dbfm_plugin.get_current_track()
url = self.dbfm_plugin.share('kaixin001', track)
os.popen(' '.join(['xdg-open', '"%s"'%url]))
def on_share_renren(self, *e):
track = self.dbfm_plugin.get_current_track()
url = self.dbfm_plugin.share('renren', track)
os.popen(' '.join(['xdg-open', '"%s"'%url]))
def on_share_twitter(self, *e):
track = self.dbfm_plugin.get_current_track()
url = self.dbfm_plugin.share('twitter', track)
os.popen(' '.join(['xdg-open', '"%s"'%url]))
def on_share_fanfou(self, *e):
track = self.dbfm_plugin.get_current_track()
url = self.dbfm_plugin.share('fanfou', track)
os.popen(' '.join(['xdg-open', '"%s"'%url]))
def destroy(self):
self.window.destroy()
event.remove_callback(self.on_playback_start, 'playback_track_start')
event.remove_callback(self.on_playback_stop, 'playback_track_end')
event.remove_callback(self.on_track_update, 'track_tags_changed')
self.exaile.gui.main.disconnect(self._toggle_id)
def on_menu_toggle(self, widget, e):
self.popup_menu.popup(None, None, None, e.button, e.time)
return True
def on_quit(self, *e):
self.exaile.gui.main.quit()
def on_recommend_song(self, *e):
track = self.dbfm_plugin.get_current_track()
url = self.dbfm_plugin.share('douban', track)
os.popen(' '.join(['xdg-open', '"%s"'%url]))
def on_channel_group_change(self, item, data):
channel_id = data
self.dbfm_plugin.close_playlist(None, self.exaile, None)
self.dbfm_plugin.active_douban_radio(None, channel_id, True)
self.show()
def on_pausebutton_clicked(self, *e):
if player.PLAYER.is_paused() or player.PLAYER.is_playing():
player.PLAYER.toggle_pause()
def on_pausebutton_toggled(self, type, player, data):
if player.is_paused():
## switch to play icon
self.pause_button.set_image(
gtk.image_new_from_stock('gtk-media-play', gtk.ICON_SIZE_BUTTON))
self.sensitive(False)
self.pause_button.set_sensitive(True)
else:
## switch back
self.pause_button.set_image(
gtk.image_new_from_stock('gtk-media-pause', gtk.ICON_SIZE_BUTTON))
self.sensitive(True)
def on_copy_permalink(self, *e):
track = self.dbfm_plugin.get_current_track()
sid = track.get_tag_raw('sid')[0]
ssid = track.get_tag_raw('ssid')[0]
t = DoubanTrack(sid=sid, ssid=ssid)
url = t.get_uri()
c = gtk.Clipboard()
c.set_text(url)