Пример #1
0
 def artwork_save_cache(self):
     misc.create_dir('~/.config/sonata/')
     filename = os.path.expanduser("~/.config/sonata/art_cache")
     try:
         with open(filename, 'w') as f:
             f.write(repr(self.cache))
     except IOError:
         pass
Пример #2
0
 def artwork_save_cache(self):
     misc.create_dir('~/.config/sonata/')
     filename = os.path.expanduser("~/.config/sonata/art_cache")
     try:
         with open(filename, 'w') as f:
             f.write(repr(self.cache))
     except IOError:
         pass
Пример #3
0
	def get_lyrics_response(self, artist_then, title_then, song_dir,
				lyrics=None, error=None):
		if lyrics and not error:
			filename = self.target_lyrics_filename(artist_then, title_then, song_dir)
			# Save lyrics to file:
			misc.create_dir('~/.lyrics/')
			f = open(filename, 'w')
			lyrics = misc.unescape_html(lyrics)
			try:
				f.write(lyrics.decode(self.enc).encode('utf8'))
			except:
				f.write(lyrics)
			f.close()

		self._show_lyrics(artist_then, title_then, lyrics, error)
Пример #4
0
    def get_lyrics_response(self, artist_then, title_then, song_dir,
                lyrics=None, error=None):
        if lyrics and not error:
            filename = self.target_lyrics_filename(artist_then, title_then, song_dir)
            # Save lyrics to file:
            misc.create_dir('~/.lyrics/')
            try:
                with open(filename, 'w') as f:
                    lyrics = misc.unescape_html(lyrics)
                    try:
                        f.write(lyrics.decode(self.enc).encode('utf8'))
                    except:
                        f.write(lyrics)
            except IOError:
                pass

        self._show_lyrics(artist_then, title_then, lyrics, error)
Пример #5
0
    def settings_load_real(self, library_set_data):
        """Load configuration from file"""
        # Load config
        conf = ConfigParser.ConfigParser()
        misc.create_dir('~/.config/sonata/')
        if os.path.isfile(os.path.expanduser('~/.config/sonata/sonatarc')):
            conf.read(os.path.expanduser('~/.config/sonata/sonatarc'))
        else:
            return
        # Compatibility with previous versions of Sonata:
        # --------------------------------------------------------------------
        if conf.has_option('connection', 'host'):
            self.host[0] = conf.get('connection', 'host')
        if conf.has_option('connection', 'port'):
            self.port[0] = int(conf.get('connection', 'port'))
        if conf.has_option('connection', 'password'):
            self.password[0] = conf.get('connection', 'password')
        if conf.has_option('connection', 'musicdir'):
            self.musicdir[0] = misc.sanitize_musicdir(
                conf.get('connection', 'musicdir'))
        # --------------------------------------------------------------------
        if conf.has_option('connection', 'auto'):
            self.autoconnect = conf.getboolean('connection', 'auto')
        if conf.has_option('connection', 'profile_num'):
            self.profile_num = conf.getint('connection', 'profile_num')
        if conf.has_option('player', 'x'):
            self.x = conf.getint('player', 'x')
        if conf.has_option('player', 'y'):
            self.y = conf.getint('player', 'y')
        if conf.has_option('player', 'w'):
            self.w = conf.getint('player', 'w')
        if conf.has_option('player', 'h'):
            self.h = conf.getint('player', 'h')
        if conf.has_option('player', 'expanded'):
            self.expanded = conf.getboolean('player', 'expanded')
        if conf.has_option('player', 'withdrawn'):
            self.withdrawn = conf.getboolean('player', 'withdrawn')
        if conf.has_option('player', 'screen'):
            self.screen = conf.getint('player', 'screen')
        if conf.has_option('player', 'covers'):
            self.show_covers = conf.getboolean('player', 'covers')
        if conf.has_option('player', 'covers_type'):
            self.covers_type = conf.getint('player', 'covers_type')
        if conf.has_option('player', 'stop_on_exit'):
            self.stop_on_exit = conf.getboolean('player', 'stop_on_exit')
        if conf.has_option('player', 'minimize'):
            self.minimize_to_systray = conf.getboolean('player', 'minimize')
        if conf.has_option('player', 'initial_run'):
            self.initial_run = conf.getboolean('player', 'initial_run')
        if conf.has_option('player', 'statusbar'):
            self.show_statusbar = conf.getboolean('player', 'statusbar')
        if conf.has_option('player', 'lyrics'):
            self.show_lyrics = conf.getboolean('player', 'lyrics')
        if conf.has_option('player', 'sticky'):
            self.sticky = conf.getboolean('player', 'sticky')
        if conf.has_option('player', 'ontop'):
            self.ontop = conf.getboolean('player', 'ontop')
        if conf.has_option('player', 'decorated'):
            self.decorated = conf.getboolean('player', 'decorated')
        if conf.has_option('player', 'notification'):
            self.show_notification = conf.getboolean('player', 'notification')
        if conf.has_option('player', 'popup_time'):
            self.popup_option = conf.getint('player', 'popup_time')
        if conf.has_option('player', 'update_on_start'):
            self.update_on_start = conf.getboolean('player', 'update_on_start')
        if conf.has_option('player', 'notif_location'):
            self.traytips_notifications_location = conf.getint(
                'player', 'notif_location')
        if conf.has_option('player', 'playback'):
            self.show_playback = conf.getboolean('player', 'playback')
        if conf.has_option('player', 'progressbar'):
            self.show_progress = conf.getboolean('player', 'progressbar')
        if conf.has_option('player', 'crossfade'):
            crossfade = conf.getint('player', 'crossfade')
            # Backwards compatibility:
            self.xfade = crossfade
        if conf.has_option('player', 'xfade'):
            self.xfade = conf.getint('player', 'xfade')
        if conf.has_option('player', 'xfade_enabled'):
            self.xfade_enabled = conf.getboolean('player', 'xfade_enabled')
        if conf.has_option('player', 'covers_pref'):
            self.covers_pref = conf.getint('player', 'covers_pref')
            # Specifying remote artwork first is too confusing and probably
            # rarely used, so we're removing this option and defaulting users
            # back to the default 'local, then remote' option.
            if self.covers_pref > consts.ART_LOCAL_REMOTE:
                self.covers_pref = consts.ART_LOCAL_REMOTE
        if conf.has_option('player', 'use_infofile'):
            self.use_infofile = conf.getboolean('player', 'use_infofile')
        if conf.has_option('player', 'infofile_path'):
            self.infofile_path = conf.get('player', 'infofile_path')
        if conf.has_option('player', 'trayicon'):
            self.show_trayicon = conf.getboolean('player', 'trayicon')
        if conf.has_option('player', 'search_num'):
            self.last_search_num = conf.getint('player', 'search_num')
        if conf.has_option('player', 'art_location'):
            self.art_location = conf.getint('player', 'art_location')
        if conf.has_option('player', 'art_location_custom_filename'):
            self.art_location_custom_filename = conf.get(
                'player', 'art_location_custom_filename')
        if conf.has_option('player', 'lyrics_location'):
            self.lyrics_location = conf.getint('player', 'lyrics_location')
        if conf.has_option('player', 'info_song_expanded'):
            self.info_song_expanded = conf.getboolean('player',
                                                      'info_song_expanded')
        if conf.has_option('player', 'info_lyrics_expanded'):
            self.info_lyrics_expanded = conf.getboolean(
                'player', 'info_lyrics_expanded')
        if conf.has_option('player', 'info_album_expanded'):
            self.info_album_expanded = conf.getboolean('player',
                                                       'info_album_expanded')
        if conf.has_option('player', 'info_song_more'):
            self.info_song_more = conf.getboolean('player', 'info_song_more')
        if conf.has_option('player', 'columnwidths'):
            self.columnwidths = [
                int(col)
                for col in conf.get('player', 'columnwidths').split(",")
            ]
        if conf.has_option('player', 'show_header'):
            self.show_header = conf.getboolean('player', 'show_header')
        if conf.has_option('player', 'tabs_expanded'):
            self.tabs_expanded = conf.getboolean('player', 'tabs_expanded')
        if conf.has_option('player', 'browser'):
            self.url_browser = conf.get('player', 'browser')
        if conf.has_option('player', 'info_art_enlarged'):
            self.info_art_enlarged = conf.getboolean('player',
                                                     'info_art_enlarged')
        if conf.has_option('player', 'existing_playlist'):
            self.existing_playlist_option = conf.getint(
                'player', 'existing_playlist')

        if conf.has_section('notebook'):
            if conf.has_option('notebook', 'current_tab_visible'):
                self.current_tab_visible = conf.getboolean(
                    'notebook', 'current_tab_visible')
            if conf.has_option('notebook', 'library_tab_visible'):
                self.library_tab_visible = conf.getboolean(
                    'notebook', 'library_tab_visible')
            if conf.has_option('notebook', 'playlists_tab_visible'):
                self.playlists_tab_visible = conf.getboolean(
                    'notebook', 'playlists_tab_visible')
            if conf.has_option('notebook', 'streams_tab_visible'):
                self.streams_tab_visible = conf.getboolean(
                    'notebook', 'streams_tab_visible')
            if conf.has_option('notebook', 'info_tab_visible'):
                self.info_tab_visible = conf.getboolean(
                    'notebook', 'info_tab_visible')
            if conf.has_option('notebook', 'current_tab_pos'):
                try:
                    self.current_tab_pos = conf.getint('notebook',
                                                       'current_tab_pos')
                except:
                    pass
            if conf.has_option('notebook', 'library_tab_pos'):
                try:
                    self.library_tab_pos = conf.getint('notebook',
                                                       'library_tab_pos')
                except:
                    pass
            if conf.has_option('notebook', 'playlists_tab_pos'):
                try:
                    self.playlists_tab_pos = conf.getint(
                        'notebook', 'playlists_tab_pos')
                except:
                    pass
            if conf.has_option('notebook', 'streams_tab_pos'):
                try:
                    self.streams_tab_pos = conf.getint('notebook',
                                                       'streams_tab_pos')
                except:
                    pass
            if conf.has_option('notebook', 'info_tab_pos'):
                try:
                    self.info_tab_pos = conf.getint('notebook', 'info_tab_pos')
                except:
                    pass

        if conf.has_section('library'):
            album = None
            artist = None
            genre = None
            year = None
            path = None
            if conf.has_option('library', 'lib_view'):
                self.lib_view = conf.getint('library', 'lib_view')
            if conf.has_option('library', 'lib_album'):
                album = conf.get('library', 'lib_album')
            if conf.has_option('library', 'lib_artist'):
                artist = conf.get('library', 'lib_artist')
            if conf.has_option('library', 'lib_genre'):
                genre = conf.get('library', 'lib_genre')
            if conf.has_option('library', 'lib_year'):
                year = conf.get('library', 'lib_year')
            if conf.has_option('library', 'lib_path'):
                path = conf.get('library', 'lib_path')
            if album == self.LIB_NODATA: album = None
            if artist == self.LIB_NODATA: artist = None
            if genre == self.LIB_NODATA: genre = None
            if year == self.LIB_NODATA: year = None
            if path == self.LIB_NODATA: path = None
            self.wd = library_set_data(album=album,
                                       artist=artist,
                                       genre=genre,
                                       year=year,
                                       path=path)

        if conf.has_section('currformat'):
            if conf.has_option('currformat', 'current'):
                self.currentformat = conf.get('currformat', 'current')
            if conf.has_option('currformat', 'library'):
                self.libraryformat = conf.get('currformat', 'library')
            if conf.has_option('currformat', 'title'):
                self.titleformat = conf.get('currformat', 'title')
            if conf.has_option('currformat', 'currsong1'):
                self.currsongformat1 = conf.get('currformat', 'currsong1')
            if conf.has_option('currformat', 'currsong2'):
                self.currsongformat2 = conf.get('currformat', 'currsong2')

        if conf.has_section('tags'):
            if conf.has_option('tags', 'use_mpdpaths'):
                self.tags_use_mpdpath = conf.getboolean('tags', 'use_mpdpaths')

        if conf.has_option('streams', 'num_streams'):
            num_streams = conf.getint('streams', 'num_streams')
            self.stream_names = []
            self.stream_uris = []
            for i in range(num_streams):
                self.stream_names.append(
                    conf.get('streams', 'names[' + str(i) + ']'))
                self.stream_uris.append(
                    conf.get('streams', 'uris[' + str(i) + ']'))
        if conf.has_option('audioscrobbler', 'use_audioscrobbler'):
            self.as_enabled = conf.getboolean('audioscrobbler',
                                              'use_audioscrobbler')
        if conf.has_option('audioscrobbler', 'username'):
            self.as_username = conf.get('audioscrobbler', 'username')
        if conf.has_option('audioscrobbler', 'password'):  # old...
            self.as_password_md5 = hashlib.md5(
                conf.get('audioscrobbler', 'password')).hexdigest()
        if conf.has_option('audioscrobbler', 'password_md5'):
            self.as_password_md5 = conf.get('audioscrobbler', 'password_md5')
        if conf.has_option('profiles', 'num_profiles'):
            num_profiles = conf.getint('profiles', 'num_profiles')
            if num_profiles > 0:
                self.profile_names = []
                self.host = []
                self.port = []
                self.password = []
                self.musicdir = []
            for i in range(num_profiles):
                self.profile_names.append(
                    conf.get('profiles', 'names[' + str(i) + ']'))
                self.host.append(conf.get('profiles', 'hosts[' + str(i) + ']'))
                self.port.append(
                    conf.getint('profiles', 'ports[' + str(i) + ']'))
                self.password.append(
                    conf.get('profiles', 'passwords[' + str(i) + ']'))
                self.musicdir.append(
                    misc.sanitize_musicdir(
                        conf.get('profiles', 'musicdirs[%s]' % i)))
            # Ensure we have a valid profile number:
            self.profile_num = max(0, min(self.profile_num, num_profiles - 1))

        if conf.has_section('plugins'):
            if conf.has_option('plugins', 'autostart_plugins'):
                self.autostart_plugins = conf.get(
                    'plugins', 'autostart_plugins').split(',')
                self.autostart_plugins = [
                    x.strip("[]' ") for x in self.autostart_plugins
                ]
            if conf.has_option('plugins', 'known_plugins'):
                self.known_plugins = conf.get('plugins',
                                              'known_plugins').split(',')
                self.known_plugins = [
                    x.strip("[]' ") for x in self.known_plugins
                ]
Пример #6
0
	def artwork_save_cache(self):
		misc.create_dir('~/.config/sonata/')
		filename = os.path.expanduser("~/.config/sonata/art_cache")
		f = open(filename, 'w')
		f.write(repr(self.cache))
		f.close()
Пример #7
0
	def settings_load_real(self, library_set_data):
		"""Load configuration from file"""
		# Load config
		conf = ConfigParser.ConfigParser()
		misc.create_dir('~/.config/sonata/')
		if os.path.isfile(os.path.expanduser('~/.config/sonata/sonatarc')):
			conf.read(os.path.expanduser('~/.config/sonata/sonatarc'))
		else:
			return
		# Compatibility with previous versions of Sonata:
		# --------------------------------------------------------------------
		if conf.has_option('connection', 'host'):
			self.host[0] = conf.get('connection', 'host')
		if conf.has_option('connection', 'port'):
			self.port[0] = int(conf.get('connection', 'port'))
		if conf.has_option('connection', 'password'):
			self.password[0] = conf.get('connection', 'password')
		if conf.has_option('connection', 'musicdir'):
			self.musicdir[0] = misc.sanitize_musicdir(conf.get('connection', 'musicdir'))
		# --------------------------------------------------------------------
		if conf.has_option('connection', 'auto'):
			self.autoconnect = conf.getboolean('connection', 'auto')
		if conf.has_option('connection', 'profile_num'):
			self.profile_num = conf.getint('connection', 'profile_num')
		if conf.has_option('player', 'x'):
			self.x = conf.getint('player', 'x')
		if conf.has_option('player', 'y'):
			self.y = conf.getint('player', 'y')
		if conf.has_option('player', 'w'):
			self.w = conf.getint('player', 'w')
		if conf.has_option('player', 'h'):
			self.h = conf.getint('player', 'h')
		if conf.has_option('player', 'expanded'):
			self.expanded = conf.getboolean('player', 'expanded')
		if conf.has_option('player', 'withdrawn'):
			self.withdrawn = conf.getboolean('player', 'withdrawn')
		if conf.has_option('player', 'screen'):
			self.screen = conf.getint('player', 'screen')
		if conf.has_option('player', 'covers'):
			self.show_covers = conf.getboolean('player', 'covers')
		if conf.has_option('player', 'covers_type'):
			self.covers_type = conf.getint('player', 'covers_type')
		if conf.has_option('player', 'stop_on_exit'):
			self.stop_on_exit = conf.getboolean('player', 'stop_on_exit')
		if conf.has_option('player', 'minimize'):
			self.minimize_to_systray = conf.getboolean('player', 'minimize')
		if conf.has_option('player', 'initial_run'):
			self.initial_run = conf.getboolean('player', 'initial_run')
		if conf.has_option('player', 'statusbar'):
			self.show_statusbar = conf.getboolean('player', 'statusbar')
		if conf.has_option('player', 'lyrics'):
			self.show_lyrics = conf.getboolean('player', 'lyrics')
		if conf.has_option('player', 'sticky'):
			self.sticky = conf.getboolean('player', 'sticky')
		if conf.has_option('player', 'ontop'):
			self.ontop = conf.getboolean('player', 'ontop')
		if conf.has_option('player', 'decorated'):
			self.decorated = conf.getboolean('player', 'decorated')
		if conf.has_option('player', 'notification'):
			self.show_notification = conf.getboolean('player', 'notification')
		if conf.has_option('player', 'popup_time'):
			self.popup_option = conf.getint('player', 'popup_time')
		if conf.has_option('player', 'update_on_start'):
			self.update_on_start = conf.getboolean('player', 'update_on_start')
		if conf.has_option('player', 'notif_location'):
			self.traytips_notifications_location = conf.getint('player', 'notif_location')
		if conf.has_option('player', 'playback'):
			self.show_playback = conf.getboolean('player', 'playback')
		if conf.has_option('player', 'progressbar'):
			self.show_progress = conf.getboolean('player', 'progressbar')
		if conf.has_option('player', 'crossfade'):
			crossfade = conf.getint('player', 'crossfade')
			# Backwards compatibility:
			self.xfade = crossfade
		if conf.has_option('player', 'xfade'):
			self.xfade = conf.getint('player', 'xfade')
		if conf.has_option('player', 'xfade_enabled'):
			self.xfade_enabled = conf.getboolean('player', 'xfade_enabled')
		if conf.has_option('player', 'covers_pref'):
			self.covers_pref = conf.getint('player', 'covers_pref')
			# Specifying remote artwork first is too confusing and probably
			# rarely used, so we're removing this option and defaulting users
			# back to the default 'local, then remote' option.
			if self.covers_pref > consts.ART_LOCAL_REMOTE:
				self.covers_pref = consts.ART_LOCAL_REMOTE
		if conf.has_option('player', 'use_infofile'):
			self.use_infofile = conf.getboolean('player', 'use_infofile')
		if conf.has_option('player', 'infofile_path'):
			self.infofile_path = conf.get('player', 'infofile_path')
		if conf.has_option('player', 'trayicon'):
			self.show_trayicon = conf.getboolean('player', 'trayicon')
		if conf.has_option('player', 'search_num'):
			self.last_search_num = conf.getint('player', 'search_num')
		if conf.has_option('player', 'art_location'):
			self.art_location = conf.getint('player', 'art_location')
		if conf.has_option('player', 'art_location_custom_filename'):
			self.art_location_custom_filename = conf.get('player', 'art_location_custom_filename')
		if conf.has_option('player', 'lyrics_location'):
			self.lyrics_location = conf.getint('player', 'lyrics_location')
		if conf.has_option('player', 'info_song_expanded'):
			self.info_song_expanded = conf.getboolean('player', 'info_song_expanded')
		if conf.has_option('player', 'info_lyrics_expanded'):
			self.info_lyrics_expanded = conf.getboolean('player', 'info_lyrics_expanded')
		if conf.has_option('player', 'info_album_expanded'):
			self.info_album_expanded = conf.getboolean('player', 'info_album_expanded')
		if conf.has_option('player', 'info_song_more'):
			self.info_song_more = conf.getboolean('player', 'info_song_more')
		if conf.has_option('player', 'columnwidths'):
			self.columnwidths = [int(col) for col in conf.get('player', 'columnwidths').split(",")]
		if conf.has_option('player', 'show_header'):
			self.show_header = conf.getboolean('player', 'show_header')
		if conf.has_option('player', 'tabs_expanded'):
			self.tabs_expanded = conf.getboolean('player', 'tabs_expanded')
		if conf.has_option('player', 'browser'):
			self.url_browser = conf.get('player', 'browser')
		if conf.has_option('player', 'info_art_enlarged'):
			self.info_art_enlarged = conf.getboolean('player', 'info_art_enlarged')
		if conf.has_option('player', 'existing_playlist'):
			self.existing_playlist_option = conf.getint('player', 'existing_playlist')

		if conf.has_section('notebook'):
			if conf.has_option('notebook', 'current_tab_visible'):
				self.current_tab_visible = conf.getboolean('notebook', 'current_tab_visible')
			if conf.has_option('notebook', 'library_tab_visible'):
				self.library_tab_visible = conf.getboolean('notebook', 'library_tab_visible')
			if conf.has_option('notebook', 'playlists_tab_visible'):
				self.playlists_tab_visible = conf.getboolean('notebook', 'playlists_tab_visible')
			if conf.has_option('notebook', 'streams_tab_visible'):
				self.streams_tab_visible = conf.getboolean('notebook', 'streams_tab_visible')
			if conf.has_option('notebook', 'info_tab_visible'):
				self.info_tab_visible = conf.getboolean('notebook', 'info_tab_visible')
			if conf.has_option('notebook', 'current_tab_pos'):
				try: self.current_tab_pos = conf.getint('notebook', 'current_tab_pos')
				except: pass
			if conf.has_option('notebook', 'library_tab_pos'):
				try: self.library_tab_pos = conf.getint('notebook', 'library_tab_pos')
				except: pass
			if conf.has_option('notebook', 'playlists_tab_pos'):
				try: self.playlists_tab_pos = conf.getint('notebook', 'playlists_tab_pos')
				except: pass
			if conf.has_option('notebook', 'streams_tab_pos'):
				try: self.streams_tab_pos = conf.getint('notebook', 'streams_tab_pos')
				except: pass
			if conf.has_option('notebook', 'info_tab_pos'):
				try: self.info_tab_pos = conf.getint('notebook', 'info_tab_pos')
				except: pass

		if conf.has_section('library'):
			album = None
			artist = None
			genre = None
			year = None
			path = None
			if conf.has_option('library', 'lib_view'):
				self.lib_view = conf.getint('library', 'lib_view')
			if conf.has_option('library', 'lib_album'):
				album = conf.get('library', 'lib_album')
			if conf.has_option('library', 'lib_artist'):
				artist = conf.get('library', 'lib_artist')
			if conf.has_option('library', 'lib_genre'):
				genre = conf.get('library', 'lib_genre')
			if conf.has_option('library', 'lib_year'):
				year = conf.get('library', 'lib_year')
			if conf.has_option('library', 'lib_path'):
				path = conf.get('library', 'lib_path')
			if album == self.LIB_NODATA: album = None
			if artist == self.LIB_NODATA: artist = None
			if genre == self.LIB_NODATA: genre = None
			if year == self.LIB_NODATA: year = None
			if path == self.LIB_NODATA: path = None
			self.wd = library_set_data(album=album, artist=artist, genre=genre, year=year, path=path)

		if conf.has_section('currformat'):
			if conf.has_option('currformat', 'current'):
				self.currentformat = conf.get('currformat', 'current')
			if conf.has_option('currformat', 'library'):
				self.libraryformat = conf.get('currformat', 'library')
			if conf.has_option('currformat', 'title'):
				self.titleformat = conf.get('currformat', 'title')
			if conf.has_option('currformat', 'currsong1'):
				self.currsongformat1 = conf.get('currformat', 'currsong1')
			if conf.has_option('currformat', 'currsong2'):
				self.currsongformat2 = conf.get('currformat', 'currsong2')
		
		if conf.has_section('tags'):
			if conf.has_option('tags', 'use_mpdpaths'):
				self.tags_use_mpdpath = conf.getboolean('tags', 'use_mpdpaths')

		if conf.has_option('streams', 'num_streams'):
			num_streams = conf.getint('streams', 'num_streams')
			self.stream_names = []
			self.stream_uris = []
			for i in range(num_streams):
				self.stream_names.append(conf.get('streams', 'names[' + str(i) + ']'))
				self.stream_uris.append(conf.get('streams', 'uris[' + str(i) + ']'))
		if conf.has_option('audioscrobbler', 'use_audioscrobbler'):
			self.as_enabled = conf.getboolean('audioscrobbler', 'use_audioscrobbler')
		if conf.has_option('audioscrobbler', 'username'):
			self.as_username = conf.get('audioscrobbler', 'username')
		if conf.has_option('audioscrobbler', 'password'): # old...
			self.as_password_md5 = hashlib.md5(conf.get('audioscrobbler', 'password')).hexdigest()
		if conf.has_option('audioscrobbler', 'password_md5'):
			self.as_password_md5 = conf.get('audioscrobbler', 'password_md5')
		if conf.has_option('profiles', 'num_profiles'):
			num_profiles = conf.getint('profiles', 'num_profiles')
			if num_profiles > 0:
				self.profile_names = []
				self.host = []
				self.port = []
				self.password = []
				self.musicdir = []
			for i in range(num_profiles):
				self.profile_names.append(conf.get('profiles', 'names[' + str(i) + ']'))
				self.host.append(conf.get('profiles', 'hosts[' + str(i) + ']'))
				self.port.append(conf.getint('profiles', 'ports[' + str(i) + ']'))
				self.password.append(conf.get('profiles', 'passwords[' + str(i) + ']'))
				self.musicdir.append(misc.sanitize_musicdir(conf.get('profiles', 'musicdirs[%s]' % i)))
			# Ensure we have a valid profile number:
			self.profile_num = max(0, min(self.profile_num, num_profiles-1))

		if conf.has_section('plugins'):
			if conf.has_option('plugins', 'autostart_plugins'):
				self.autostart_plugins = conf.get('plugins', 'autostart_plugins').split(',')
				self.autostart_plugins = [x.strip("[]' ") for x in self.autostart_plugins]
			if conf.has_option('plugins', 'known_plugins'):
				self.known_plugins = conf.get('plugins', 'known_plugins').split(',')
				self.known_plugins = [x.strip("[]' ") for x in self.known_plugins]
Пример #8
0
	def get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir):
		filename_artist = misc.strip_all_slashes(filename_artist)
		filename_title = misc.strip_all_slashes(filename_title)
		filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir)
		search_str = misc.link_markup(_("search"), True, True, self.linkcolor)
		edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor)
		if filename:
			# If the lyrics only contain "not found", delete the file and try to
			# fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that
			# prevents lyrics from being found, storing the "not found" will
			# prevent a future release from correctly fetching the lyrics.
			f = open(filename, 'r')
			lyrics = f.read()
			f.close()
			if lyrics == _("Lyrics not found"):
				misc.remove_file(filename)
				filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir)
		if filename:
			# Re-use lyrics from file:
			f = open(filename, 'r')
			lyrics = f.read()
			f.close()
			# Strip artist - title line from file if it exists, since we
			# now have that information visible elsewhere.
			header = filename_artist + " - " + filename_title + "\n\n"
			if lyrics[:len(header)] == header:
				lyrics = lyrics[len(header):]
			gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
			gobject.idle_add(self.info_searchlabel.set_markup, search_str)
			gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
		else:
			# Use default filename:
			filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir)
			# Fetch lyrics from lyricwiki.org
			gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title)
			if self.lyricServer is None:
				wsdlFile = "http://lyricwiki.org/server.php?wsdl"
				try:
					self.lyricServer = True
					timeout = socketgettimeout()
					socketsettimeout(consts.LYRIC_TIMEOUT)
					self.lyricServer = ServiceProxy.ServiceProxy(wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) 
				except:
					socketsettimeout(timeout)
					lyrics = _("Couldn't connect to LyricWiki")
					gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
					self.lyricServer = None
					gobject.idle_add(self.info_searchlabel.set_markup, search_str)
					gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
					return
			try:
				timeout = socketgettimeout()
				socketsettimeout(consts.LYRIC_TIMEOUT)
				lyrics = self.lyricServer.getSong(artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format(search_title))['return']["lyrics"]
				if lyrics.lower() != "not found":
					lyrics = misc.unescape_html(lyrics)
					lyrics = misc.wiki_to_html(lyrics)
					lyrics = lyrics.encode("ISO-8859-1")
					gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
					# Save lyrics to file:
					misc.create_dir('~/.lyrics/')
					f = open(filename, 'w')
					lyrics = misc.unescape_html(lyrics)
					try:
						f.write(lyrics.decode(self.enc).encode('utf8'))
					except:
						f.write(lyrics)
					f.close()
				else:
					lyrics = _("Lyrics not found")
					gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
			except:
				lyrics = _("Fetching lyrics failed")
				gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
			gobject.idle_add(self.info_searchlabel.set_markup, search_str)
			gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
			socketsettimeout(timeout)
Пример #9
0
 def artwork_save_cache(self):
     misc.create_dir('~/.config/sonata/')
     filename = os.path.expanduser("~/.config/sonata/art_cache")
     f = open(filename, 'w')
     f.write(repr(self.cache))
     f.close()
Пример #10
0
    def settings_load_real(self, library_set_data):
        """Load configuration from file"""
        # Load config
        conf = ConfigParser.ConfigParser()
        misc.create_dir("~/.config/sonata/")
        if os.path.isfile(os.path.expanduser("~/.config/sonata/sonatarc")):
            conf.read(os.path.expanduser("~/.config/sonata/sonatarc"))
        else:
            return
            # Compatibility with previous versions of Sonata:
            # --------------------------------------------------------------------
        if conf.has_option("connection", "host"):
            self.host[0] = conf.get("connection", "host")
        if conf.has_option("connection", "port"):
            self.port[0] = int(conf.get("connection", "port"))
        if conf.has_option("connection", "password"):
            self.password[0] = conf.get("connection", "password")
        if conf.has_option("connection", "musicdir"):
            self.musicdir[0] = misc.sanitize_musicdir(conf.get("connection", "musicdir"))
            # --------------------------------------------------------------------
        if conf.has_option("connection", "auto"):
            self.autoconnect = conf.getboolean("connection", "auto")
        if conf.has_option("connection", "profile_num"):
            self.profile_num = conf.getint("connection", "profile_num")
        if conf.has_option("player", "x"):
            self.x = conf.getint("player", "x")
        if conf.has_option("player", "y"):
            self.y = conf.getint("player", "y")
        if conf.has_option("player", "w"):
            self.w = conf.getint("player", "w")
        if conf.has_option("player", "h"):
            self.h = conf.getint("player", "h")
        if conf.has_option("player", "expanded"):
            self.expanded = conf.getboolean("player", "expanded")
        if conf.has_option("player", "withdrawn"):
            self.withdrawn = conf.getboolean("player", "withdrawn")
        if conf.has_option("player", "screen"):
            self.screen = conf.getint("player", "screen")
        if conf.has_option("player", "covers"):
            self.show_covers = conf.getboolean("player", "covers")
        if conf.has_option("player", "covers_type"):
            self.covers_type = conf.getint("player", "covers_type")
        if conf.has_option("player", "stop_on_exit"):
            self.stop_on_exit = conf.getboolean("player", "stop_on_exit")
        if conf.has_option("player", "minimize"):
            self.minimize_to_systray = conf.getboolean("player", "minimize")
        if conf.has_option("player", "initial_run"):
            self.initial_run = conf.getboolean("player", "initial_run")
        if conf.has_option("player", "statusbar"):
            self.show_statusbar = conf.getboolean("player", "statusbar")
        if conf.has_option("player", "lyrics"):
            self.show_lyrics = conf.getboolean("player", "lyrics")
        if conf.has_option("player", "sticky"):
            self.sticky = conf.getboolean("player", "sticky")
        if conf.has_option("player", "ontop"):
            self.ontop = conf.getboolean("player", "ontop")
        if conf.has_option("player", "decorated"):
            self.decorated = conf.getboolean("player", "decorated")
        if conf.has_option("player", "notification"):
            self.show_notification = conf.getboolean("player", "notification")
        if conf.has_option("player", "popup_time"):
            self.popup_option = conf.getint("player", "popup_time")
        if conf.has_option("player", "update_on_start"):
            self.update_on_start = conf.getboolean("player", "update_on_start")
        if conf.has_option("player", "notif_location"):
            self.traytips_notifications_location = conf.getint("player", "notif_location")
        if conf.has_option("player", "playback"):
            self.show_playback = conf.getboolean("player", "playback")
        if conf.has_option("player", "progressbar"):
            self.show_progress = conf.getboolean("player", "progressbar")
        if conf.has_option("player", "crossfade"):
            crossfade = conf.getint("player", "crossfade")
            # Backwards compatibility:
            self.xfade = crossfade
        if conf.has_option("player", "xfade"):
            self.xfade = conf.getint("player", "xfade")
        if conf.has_option("player", "xfade_enabled"):
            self.xfade_enabled = conf.getboolean("player", "xfade_enabled")
        if conf.has_option("player", "covers_pref"):
            self.covers_pref = conf.getint("player", "covers_pref")
            # Specifying remote artwork first is too confusing and probably
            # rarely used, so we're removing this option and defaulting users
            # back to the default 'local, then remote' option.
            if self.covers_pref > consts.ART_LOCAL_REMOTE:
                self.covers_pref = consts.ART_LOCAL_REMOTE
        if conf.has_option("player", "use_infofile"):
            self.use_infofile = conf.getboolean("player", "use_infofile")
        if conf.has_option("player", "infofile_path"):
            self.infofile_path = conf.get("player", "infofile_path")
        if conf.has_option("player", "trayicon"):
            self.show_trayicon = conf.getboolean("player", "trayicon")
        if conf.has_option("player", "search_num"):
            self.last_search_num = conf.getint("player", "search_num")
        if conf.has_option("player", "art_location"):
            self.art_location = conf.getint("player", "art_location")
        if conf.has_option("player", "art_location_custom_filename"):
            self.art_location_custom_filename = conf.get("player", "art_location_custom_filename")
        if conf.has_option("player", "lyrics_location"):
            self.lyrics_location = conf.getint("player", "lyrics_location")
        if conf.has_option("player", "info_song_expanded"):
            self.info_song_expanded = conf.getboolean("player", "info_song_expanded")
        if conf.has_option("player", "info_lyrics_expanded"):
            self.info_lyrics_expanded = conf.getboolean("player", "info_lyrics_expanded")
        if conf.has_option("player", "info_album_expanded"):
            self.info_album_expanded = conf.getboolean("player", "info_album_expanded")
        if conf.has_option("player", "info_song_more"):
            self.info_song_more = conf.getboolean("player", "info_song_more")
        if conf.has_option("player", "columnwidths"):
            self.columnwidths = conf.get("player", "columnwidths").split(",")
            for col in range(len(self.columnwidths)):
                self.columnwidths[col] = int(self.columnwidths[col])
            self.colwidthpercents = [0] * len(self.columnwidths)
        if conf.has_option("player", "show_header"):
            self.show_header = conf.getboolean("player", "show_header")
        if conf.has_option("player", "tabs_expanded"):
            self.tabs_expanded = conf.getboolean("player", "tabs_expanded")
        if conf.has_option("player", "browser"):
            self.url_browser = conf.get("player", "browser")
        if conf.has_option("player", "info_art_enlarged"):
            self.info_art_enlarged = conf.getboolean("player", "info_art_enlarged")
        if conf.has_option("player", "existing_playlist"):
            self.existing_playlist_option = conf.getint("player", "existing_playlist")

        if conf.has_section("notebook"):
            if conf.has_option("notebook", "current_tab_visible"):
                self.current_tab_visible = conf.getboolean("notebook", "current_tab_visible")
            if conf.has_option("notebook", "library_tab_visible"):
                self.library_tab_visible = conf.getboolean("notebook", "library_tab_visible")
            if conf.has_option("notebook", "playlists_tab_visible"):
                self.playlists_tab_visible = conf.getboolean("notebook", "playlists_tab_visible")
            if conf.has_option("notebook", "streams_tab_visible"):
                self.streams_tab_visible = conf.getboolean("notebook", "streams_tab_visible")
            if conf.has_option("notebook", "info_tab_visible"):
                self.info_tab_visible = conf.getboolean("notebook", "info_tab_visible")
            if conf.has_option("notebook", "current_tab_pos"):
                try:
                    self.current_tab_pos = conf.getint("notebook", "current_tab_pos")
                except:
                    pass
            if conf.has_option("notebook", "library_tab_pos"):
                try:
                    self.library_tab_pos = conf.getint("notebook", "library_tab_pos")
                except:
                    pass
            if conf.has_option("notebook", "playlists_tab_pos"):
                try:
                    self.playlists_tab_pos = conf.getint("notebook", "playlists_tab_pos")
                except:
                    pass
            if conf.has_option("notebook", "streams_tab_pos"):
                try:
                    self.streams_tab_pos = conf.getint("notebook", "streams_tab_pos")
                except:
                    pass
            if conf.has_option("notebook", "info_tab_pos"):
                try:
                    self.info_tab_pos = conf.getint("notebook", "info_tab_pos")
                except:
                    pass

        if conf.has_section("library"):
            album = None
            artist = None
            genre = None
            year = None
            path = None
            if conf.has_option("library", "lib_view"):
                self.lib_view = conf.getint("library", "lib_view")
            if conf.has_option("library", "lib_album"):
                album = conf.get("library", "lib_album")
            if conf.has_option("library", "lib_artist"):
                artist = conf.get("library", "lib_artist")
            if conf.has_option("library", "lib_genre"):
                genre = conf.get("library", "lib_genre")
            if conf.has_option("library", "lib_year"):
                year = conf.get("library", "lib_year")
            if conf.has_option("library", "lib_path"):
                path = conf.get("library", "lib_path")
            if album == self.LIB_NODATA:
                album = None
            if artist == self.LIB_NODATA:
                artist = None
            if genre == self.LIB_NODATA:
                genre = None
            if year == self.LIB_NODATA:
                year = None
            if path == self.LIB_NODATA:
                path = None
            self.wd = library_set_data(album=album, artist=artist, genre=genre, year=year, path=path)

        if conf.has_section("currformat"):
            if conf.has_option("currformat", "current"):
                self.currentformat = conf.get("currformat", "current")
            if conf.has_option("currformat", "library"):
                self.libraryformat = conf.get("currformat", "library")
            if conf.has_option("currformat", "title"):
                self.titleformat = conf.get("currformat", "title")
            if conf.has_option("currformat", "currsong1"):
                self.currsongformat1 = conf.get("currformat", "currsong1")
            if conf.has_option("currformat", "currsong2"):
                self.currsongformat2 = conf.get("currformat", "currsong2")

        if conf.has_section("tags"):
            if conf.has_option("tags", "use_mpdpaths"):
                self.tags_use_mpdpath = conf.getboolean("tags", "use_mpdpaths")

        if conf.has_option("streams", "num_streams"):
            num_streams = conf.getint("streams", "num_streams")
            self.stream_names = []
            self.stream_uris = []
            for i in range(num_streams):
                self.stream_names.append(conf.get("streams", "names[" + str(i) + "]"))
                self.stream_uris.append(conf.get("streams", "uris[" + str(i) + "]"))
        if conf.has_option("audioscrobbler", "use_audioscrobbler"):
            self.as_enabled = conf.getboolean("audioscrobbler", "use_audioscrobbler")
        if conf.has_option("audioscrobbler", "username"):
            self.as_username = conf.get("audioscrobbler", "username")
        if conf.has_option("audioscrobbler", "password"):  # old...
            self.as_password_md5 = hashlib.md5(conf.get("audioscrobbler", "password")).hexdigest()
        if conf.has_option("audioscrobbler", "password_md5"):
            self.as_password_md5 = conf.get("audioscrobbler", "password_md5")
        if conf.has_option("profiles", "num_profiles"):
            num_profiles = conf.getint("profiles", "num_profiles")
            if num_profiles > 0:
                self.profile_names = []
                self.host = []
                self.port = []
                self.password = []
                self.musicdir = []
            for i in range(num_profiles):
                self.profile_names.append(conf.get("profiles", "names[" + str(i) + "]"))
                self.host.append(conf.get("profiles", "hosts[" + str(i) + "]"))
                self.port.append(conf.getint("profiles", "ports[" + str(i) + "]"))
                self.password.append(conf.get("profiles", "passwords[" + str(i) + "]"))
                self.musicdir.append(misc.sanitize_musicdir(conf.get("profiles", "musicdirs[" + str(i) + "]")))
                # Ensure we have a valid profile number:
            if self.profile_num < 0 or self.profile_num > num_profiles - 1:
                self.profile_num = 0
Пример #11
0
            print "JavaScript helper function"
            funcs = JS.get_function_list()
            for func in funcs:
                print "\t" + func
        else:
            print "Unknown list type"
        sys.exit(0)

    # Get the basepath for the web server
    mybase = builtins.CFG.get("global", "basepath")
    if mybase == None:
        print "[ERROR] Basepath must be specified"
        sys.exit(1)

    # Ensure dir exist
    misc.create_dir(mybase)

    # Set IP that is used in JS code
    returnip = ""
    if builtins.CFG.exist("global", "publicip"):
        returnip = builtins.CFG.get("global", "publicip")
    else:
        returnip = misc.choose_return_ip()
        builtins.CFG.set("global", "publicip", returnip)

    use_https = False
    if args["ssl"] == True and ssl != None:
        use_https = True

    returnPath = "http"
    if use_https:
Пример #12
0
 def get_lyrics_thread(self, search_artist, search_title, filename_artist,
                       filename_title, song_dir):
     filename_artist = misc.strip_all_slashes(filename_artist)
     filename_title = misc.strip_all_slashes(filename_title)
     filename = self.info_check_for_local_lyrics(filename_artist,
                                                 filename_title, song_dir)
     search_str = misc.link_markup(_("search"), True, True, self.linkcolor)
     edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor)
     if filename:
         # If the lyrics only contain "not found", delete the file and try to
         # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that
         # prevents lyrics from being found, storing the "not found" will
         # prevent a future release from correctly fetching the lyrics.
         f = open(filename, 'r')
         lyrics = f.read()
         f.close()
         if lyrics == _("Lyrics not found"):
             misc.remove_file(filename)
             filename = self.info_check_for_local_lyrics(
                 filename_artist, filename_title, song_dir)
     if filename:
         # Re-use lyrics from file:
         f = open(filename, 'r')
         lyrics = f.read()
         f.close()
         # Strip artist - title line from file if it exists, since we
         # now have that information visible elsewhere.
         header = filename_artist + " - " + filename_title + "\n\n"
         if lyrics[:len(header)] == header:
             lyrics = lyrics[len(header):]
         gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist,
                          filename_title)
         gobject.idle_add(self.info_searchlabel.set_markup, search_str)
         gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
     else:
         # Use default filename:
         filename = self.target_lyrics_filename(filename_artist,
                                                filename_title, song_dir)
         # Fetch lyrics from lyricwiki.org
         gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."),
                          filename_artist, filename_title)
         if self.lyricServer is None:
             wsdlFile = "http://lyricwiki.org/server.php?wsdl"
             try:
                 self.lyricServer = True
                 timeout = socketgettimeout()
                 socketsettimeout(consts.LYRIC_TIMEOUT)
                 self.lyricServer = ServiceProxy.ServiceProxy(
                     wsdlFile,
                     cachedir=os.path.expanduser("~/.service_proxy_dir"))
             except:
                 socketsettimeout(timeout)
                 lyrics = _("Couldn't connect to LyricWiki")
                 gobject.idle_add(self.info_show_lyrics, lyrics,
                                  filename_artist, filename_title)
                 self.lyricServer = None
                 gobject.idle_add(self.info_searchlabel.set_markup,
                                  search_str)
                 gobject.idle_add(self.info_editlyricslabel.set_markup,
                                  edit_str)
                 return
         try:
             timeout = socketgettimeout()
             socketsettimeout(consts.LYRIC_TIMEOUT)
             lyrics = self.lyricServer.getSong(
                 artist=self.lyricwiki_format(search_artist),
                 song=self.lyricwiki_format(
                     search_title))['return']["lyrics"]
             if lyrics.lower() != "not found":
                 lyrics = misc.unescape_html(lyrics)
                 lyrics = misc.wiki_to_html(lyrics)
                 lyrics = lyrics.encode("ISO-8859-1")
                 gobject.idle_add(self.info_show_lyrics, lyrics,
                                  filename_artist, filename_title)
                 # Save lyrics to file:
                 misc.create_dir('~/.lyrics/')
                 f = open(filename, 'w')
                 lyrics = misc.unescape_html(lyrics)
                 try:
                     f.write(lyrics.decode(self.enc).encode('utf8'))
                 except:
                     f.write(lyrics)
                 f.close()
             else:
                 lyrics = _("Lyrics not found")
                 gobject.idle_add(self.info_show_lyrics, lyrics,
                                  filename_artist, filename_title)
         except:
             lyrics = _("Fetching lyrics failed")
             gobject.idle_add(self.info_show_lyrics, lyrics,
                              filename_artist, filename_title)
         gobject.idle_add(self.info_searchlabel.set_markup, search_str)
         gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
         socketsettimeout(timeout)