def __download_catalogue_chunk_cb (self, result, total, out):
		if not result:
			# done downloading, unzip to real location
			out.close()

			catalog = zipfile.ZipFile(magnatune_song_info_temp)
			out = open(magnatune_song_info, 'w')
			filename = self.__find_song_info(catalog)
			if filename is None:
				rb.error_dialog(title=_("Unable to load catalog"),
						message=_("Rhythmbox could not understand the Magnatune catalog, please file a bug."))
				return
			out.write(catalog.read(filename))
			out.close()
			catalog.close()

			os.unlink(magnatune_song_info_temp)
			self.__updating = False
			self.__catalogue_loader = None
			self.__load_catalogue()

		elif isinstance(result, Exception):
			# complain
			pass
		else:
			out.write(result)
			self.__load_current_size += len(result)
			self.__load_total_size = total

		self.__notify_status_changed()
	def purchase_album(self):
		try:
			library_location = self.__client.get_list("/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0] # Just use the first library location
		except IndexError, e:
			rb.error_dialog(title = _("Couldn't purchase album"),
				        message = _("You must have a library location set to purchase an album."))
			return
            def got_items(result, items):
                account_type = self.__client.get_string(
                    self.__plugin.gconf_keys['account_type'])
                username = ""
                password = ""
                if account_type == 'none':
                    pass
                elif result is not None or len(items) == 0:
                    rb.error_dialog(title=_("Couldn't get account details"),
                                    message=str(result))
                    return
                else:
                    try:
                        username, password = items[0].secret.split('\n')
                    except ValueError:  # Couldn't parse secret, possibly because it's empty
                        pass
                parser = xml.sax.make_parser()
                parser.setContentHandler(
                    TrackListHandler(self.__db, self.__entry_type,
                                     self.__sku_dict, self.__home_dict,
                                     self.__art_dict, account_type, username,
                                     password))

                self.__catalogue_loader = rb.ChunkLoader()
                self.__catalogue_loader.get_url_chunks(magnatune_song_info,
                                                       64 * 1024, True,
                                                       catalogue_chunk_cb,
                                                       parser)
Example #4
0
	def __init__(self, shell):
		# make sure the replaygain elements are available
		missing = []
		required = ("rgvolume", "rglimiter")
		for e in required:
			if gst.element_factory_find(e) is None:
				missing.append(e)

		if len(missing) > 0:
			msg = _("The GStreamer elements required for ReplayGain processing are not available. The missing elements are: %s") % ", ".join(missing)
			rb.error_dialog(shell.props.window, _("ReplayGain GStreamer plugins not available"), msg)
			raise Exception(msg)

		self.shell_player = shell.props.shell_player
		self.player = self.shell_player.props.player
		self.gconf = gconf.client_get_default()

		self.gconf.add_dir(config.GCONF_DIR, preload=False)
		self.gconf.notify_add(config.GCONF_KEYS['limiter'], self.limiter_changed_cb)

		self.previous_gain = []
		self.fallback_gain = 0.0
		self.resetting_rgvolume = False

		# we use different means to hook into the playback pipeline depending on
		# the playback backend in use
		if gobject.signal_lookup("get-stream-filters", self.player):
			self.setup_xfade_mode()
			self.deactivate_backend = self.deactivate_xfade_mode
		else:
			self.setup_playbin2_mode()
			self.deactivate_backend = self.deactivate_playbin2_mode
            def download_finished(uri, result):
                try:
                    success = uri.copy_finish(result)
                except:
                    success = False

                if not success:
                    return

                # done downloading, unzip to real location
                catalog_zip = zipfile.ZipFile(magnatune_song_info_temp)
                catalog = open(magnatune_song_info, 'w')
                filename = find_song_info(catalog_zip)
                if filename is None:
                    rb.error_dialog(
                        title=_("Unable to load catalog"),
                        message=
                        _("Rhythmbox could not understand the Magnatune catalog, please file a bug."
                          ))
                    return
                catalog.write(catalog_zip.read(filename))
                catalog.close()
                catalog_zip.close()

                dest.delete()
                self.__updating = False
                self.__catalogue_loader = None
                self.__notify_status_changed()

                load_catalogue()
			def download_finished(uri, result):
				try:
					success = uri.copy_finish(result)
				except:
					success = False

				if not success:
					return

				# done downloading, unzip to real location
				catalog_zip = zipfile.ZipFile(magnatune_song_info_temp)
				catalog = open(magnatune_song_info, 'w')
				filename = find_song_info(catalog_zip)
				if filename is None:
					rb.error_dialog(title=_("Unable to load catalog"),
							message=_("Rhythmbox could not understand the Magnatune catalog, please file a bug."))
					return
				catalog.write(catalog_zip.read(filename))
				catalog.close()
				catalog_zip.close()

				dest.delete()
				self.__updating = False
				self.__catalogue_loader = None
				self.__notify_status_changed()

				load_catalogue()
Example #7
0
 def _open_lyrics(self, entry):
     artist = self._shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
     title = self._shell.props.db.entry_get(entry, rhythmdb.PROP_TITLE)
     songinfo = SongInfo(artist, title)
     if not open_lyrics(self._prefs.get('main.directory'), songinfo):
         log.info('%s not found' % songinfo)
         rb.error_dialog(title=_('Lyrics not found'), message=str(songinfo))
     return
Example #8
0
	def _open_lyrics(self, entry):
		artist = self._shell.props.db.entry_get(entry, rhythmdb.PROP_ARTIST)
		title = self._shell.props.db.entry_get(entry, rhythmdb.PROP_TITLE)
		songinfo = SongInfo(artist, title)
		if not open_lyrics(self._prefs.get('main.directory'), songinfo):
			log.info('%s not found' % songinfo)
			rb.error_dialog(title = _('Lyrics not found'), message = str(songinfo))
		return
    def __auth_download(self, sku):  # http://magnatune.com/info/api
        def got_items(result, items):
            if result is not None or len(items) == 0:
                rb.error_dialog(title=_("Couldn't get account details"),
                                message=str(result))
                return

            try:
                username, password = items[0].secret.split('\n')
            except ValueError:  # Couldn't parse secret, possibly because it's empty
                username = ""
                password = ""
            print "downloading album: " + sku
            url_dict = {'id': magnatune_partner_id, 'sku': sku}
            url = magnatune_api_download_uri % (username, password)
            url = url + urllib.urlencode(url_dict)

            l = rb.Loader()
            l.get_url(url, auth_data_cb, (username, password))

        def auth_data_cb(data, (username, password)):
            buy_album_handler = BuyAlbumHandler(
                self.__client.get_string(self.__plugin.gconf_keys['format']))
            auth_parser = xml.sax.make_parser()
            auth_parser.setContentHandler(buy_album_handler)

            if data is None:
                # hmm.
                return

            try:
                data = data.replace(
                    "<br>", ""
                )  # get rid of any stray <br> tags that will mess up the parser
                # print data
                auth_parser.feed(data)
                auth_parser.close()

                # process the URI: add authentication info, quote the filename component for some reason
                parsed = urlparse.urlparse(buy_album_handler.url)
                netloc = "%s:%s@%s" % (username, password, parsed.hostname)

                spath = os.path.split(urllib.url2pathname(parsed.path))
                basename = spath[1]
                path = urllib.pathname2url(
                    os.path.join(spath[0], urllib.quote(basename)))

                authed = (parsed[0], netloc, path) + parsed[3:]
                audio_dl_uri = urlparse.urlunparse(authed)

                self.__download_album(gio.File(audio_dl_uri), sku)

            except MagnatunePurchaseError, e:
                rb.error_dialog(
                    title=_("Download Error"),
                    message=
                    _("An error occurred while trying to authorize the download.\nThe Magnatune server returned:\n%s"
                      ) % str(e))
	def __auth_download(self, sku): # http://magnatune.com/info/api
		def got_items(result, items):
			if result is not None or len(items) == 0:
				rb.error_dialog(title = _("Couldn't get account details"),
				                message = str(result))
				return

			try:
				username, password = items[0].secret.split('\n')
			except ValueError: # Couldn't parse secret, possibly because it's empty
				username = ""
				password = ""
			print "downloading album: " + sku
			url_dict = {
				'id':	magnatune_partner_id,
				'sku':	sku
			}
			url = magnatune_api_download_uri % (username, password)
			url = url + urllib.urlencode(url_dict)

			l = rb.Loader()
			l.get_url(url, auth_data_cb, (username, password))

		def auth_data_cb(data, (username, password)):
			buy_album_handler = BuyAlbumHandler(self.__client.get_string(self.__plugin.gconf_keys['format']))
			auth_parser = xml.sax.make_parser()
			auth_parser.setContentHandler(buy_album_handler)

			if data is None:
				# hmm.
				return

			try:
				data = data.replace("<br>", "") # get rid of any stray <br> tags that will mess up the parser
				# print data
				auth_parser.feed(data)
				auth_parser.close()

				# process the URI: add authentication info, quote the filename component for some reason
				parsed = urlparse.urlparse(buy_album_handler.url)
				netloc = "%s:%s@%s" % (username, password, parsed.hostname)

				spath = os.path.split(urllib.url2pathname(parsed.path))
				basename = spath[1]
				path = urllib.pathname2url(os.path.join(spath[0], urllib.quote(basename)))

				authed = (parsed[0], netloc, path) + parsed[3:]
				audio_dl_uri = urlparse.urlunparse(authed)

				self.__download_album(gio.File(audio_dl_uri), sku)

			except MagnatunePurchaseError, e:
				rb.error_dialog(title = _("Download Error"),
						message = _("An error occurred while trying to authorize the download.\nThe Magnatune server returned:\n%s") % str(e))
Example #11
0
			def close_button_pressed(x, y):
				try:
					if keyring_data['id'] and keyring_data['item']:
						# The async version is not in the python bindings, grr...
						keyring.item_set_info_sync(None, keyring_data['id'], keyring_data['item'])
					else:
						rb.error_dialog(title = _("Couldn't store account information"),
						                message = _("There was a problem accessing the keyring. Check the debug output for more information."))
				except Exception, e:
					rb.error_dialog(title = _("Couldn't store account information"),
					                message = str(e))
	def download_album(self):
		if self.__client.get_string(self.__plugin.gconf_keys['account_type']) != 'download':
			# The user doesn't have a download account, so redirect them to the purchase page.
			self.purchase_redirect()
			return

		try:
			library_location = self.__client.get_list("/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0] # Just use the first library location
		except IndexError, e:
			rb.error_dialog(title = _("Couldn't purchase album"),
				        message = _("You must have a library location set to purchase an album."))
			return
Example #13
0
 def close_button_pressed(x, y):
     try:
         if keyring_data['id'] and keyring_data['item']:
             # The async version is not in the python bindings, grr...
             keyring.item_set_info_sync(None, keyring_data['id'],
                                        keyring_data['item'])
         else:
             rb.error_dialog(
                 title=_("Couldn't store account information"),
                 message=
                 _("There was a problem accessing the keyring. Check the debug output for more information."
                   ))
     except Exception, e:
         rb.error_dialog(
             title=_("Couldn't store account information"),
             message=str(e))
    def download_album(self):
        if self.__client.get_string(
                self.__plugin.gconf_keys['account_type']) != 'download':
            # The user doesn't have a download account, so redirect them to the purchase page.
            self.purchase_redirect()
            return

        try:
            library_location = self.__client.get_list(
                "/apps/rhythmbox/library_locations",
                gconf.VALUE_STRING)[0]  # Just use the first library location
        except IndexError, e:
            rb.error_dialog(
                title=_("Couldn't purchase album"),
                message=_(
                    "You must have a library location set to purchase an album."
                ))
            return
        def got_items(result, items):
            if result is not None or len(items) == 0:
                rb.error_dialog(title=_("Couldn't get account details"),
                                message=str(result))
                return

            try:
                username, password = items[0].secret.split('\n')
            except ValueError:  # Couldn't parse secret, possibly because it's empty
                username = ""
                password = ""
            print "downloading album: " + sku
            url_dict = {'id': magnatune_partner_id, 'sku': sku}
            url = magnatune_api_download_uri % (username, password)
            url = url + urllib.urlencode(url_dict)

            l = rb.Loader()
            l.get_url(url, auth_data_cb, (username, password))
			def got_items(result, items):
				account_type = self.__client.get_string(self.__plugin.gconf_keys['account_type'])
				username = ""
				password = ""
				if account_type == 'none':
					pass
				elif result is not None or len(items) == 0:
					rb.error_dialog(title = _("Couldn't get account details"),
							message = str(result))
					return
				else:
					try:
						username, password = items[0].secret.split('\n')
					except ValueError: # Couldn't parse secret, possibly because it's empty
						pass
				parser = xml.sax.make_parser()
				parser.setContentHandler(TrackListHandler(self.__db, self.__entry_type, self.__sku_dict, self.__home_dict, self.__art_dict, account_type, username, password))

				self.__catalogue_loader = rb.ChunkLoader()
				self.__catalogue_loader.get_url_chunks(magnatune_song_info, 64*1024, True, catalogue_chunk_cb, parser)
		def got_items(result, items):
			if result is not None or len(items) == 0:
				rb.error_dialog(title = _("Couldn't get account details"),
				                message = str(result))
				return

			try:
				username, password = items[0].secret.split('\n')
			except ValueError: # Couldn't parse secret, possibly because it's empty
				username = ""
				password = ""
			print "downloading album: " + sku
			url_dict = {
				'id':	magnatune_partner_id,
				'sku':	sku
			}
			url = magnatune_api_download_uri % (username, password)
			url = url + urllib.urlencode(url_dict)

			l = rb.Loader()
			l.get_url(url, auth_data_cb, (username, password))
	def __auth_data_cb (self, data, format):

		buy_album_handler = BuyAlbumHandler(format)
		auth_parser = xml.sax.make_parser()
		auth_parser.setContentHandler(buy_album_handler)

		if data is None:
			# hmm.
			return

		self.__wait_dlg.destroy()
		try:
			data = data.replace("<br>", "") # get rid of any stray <br> tags that will mess up the parser
			# print data
			auth_parser.feed(data)
			auth_parser.close()

			# process the URI: add authentication info, quote the filename component for some reason

			parsed = urlparse.urlparse(buy_album_handler.url)
			netloc = "%s:%s@%s" % (str(buy_album_handler.username), str(buy_album_handler.password), parsed.hostname)

			spath = os.path.split(urllib.url2pathname(parsed.path))
			basename = spath[1]
			path = urllib.pathname2url(os.path.join(spath[0], urllib.quote(basename)))

			authed = (parsed[0], netloc, path) + parsed[3:]
			audio_dl_uri = urlparse.urlunparse(authed)

			in_progress = open(os.path.join(magnatune_in_progress_dir, "in_progress_" + basename), 'w')
			in_progress.write(str(audio_dl_uri))
			in_progress.close()

			self.__download_album(audio_dl_uri)

		except MagnatunePurchaseError, e:
			rb.error_dialog(title = _("Purchase Error"),
					message = _("An error occurred while trying to purchase the album.\nThe Magnatune server returned:\n%s") % str(e))
Example #19
0
    def __init__(self, shell):
        # make sure the replaygain elements are available
        missing = []
        required = ("rgvolume", "rglimiter")
        for e in required:
            if gst.element_factory_find(e) is None:
                missing.append(e)

        if len(missing) > 0:
            msg = _(
                "The GStreamer elements required for ReplayGain processing are not available. The missing elements are: %s"
            ) % ", ".join(missing)
            rb.error_dialog(shell.props.window,
                            _("ReplayGain GStreamer plugins not available"),
                            msg)
            raise Exception(msg)

        self.shell_player = shell.props.shell_player
        self.player = self.shell_player.props.player
        self.gconf = gconf.client_get_default()

        self.gconf.add_dir(config.GCONF_DIR, preload=False)
        self.gconf.notify_add(config.GCONF_KEYS['limiter'],
                              self.limiter_changed_cb)

        self.previous_gain = []
        self.fallback_gain = 0.0
        self.resetting_rgvolume = False

        # we use different means to hook into the playback pipeline depending on
        # the playback backend in use
        if gobject.signal_lookup("get-stream-filters", self.player):
            self.setup_xfade_mode()
            self.deactivate_backend = self.deactivate_xfade_mode
        else:
            self.setup_playbin2_mode()
            self.deactivate_backend = self.deactivate_playbin2_mode
                authed = (parsed[0], netloc, path) + parsed[3:]
                audio_dl_uri = urlparse.urlunparse(authed)

                self.__download_album(gio.File(audio_dl_uri), sku)

            except MagnatunePurchaseError, e:
                rb.error_dialog(
                    title=_("Download Error"),
                    message=
                    _("An error occurred while trying to authorize the download.\nThe Magnatune server returned:\n%s"
                      ) % str(e))
            except Exception, e:
                rb.error_dialog(
                    title=_("Error"),
                    message=
                    _("An error occurred while trying to download the album.\nThe error text is:\n%s"
                      ) % str(e))

        keyring.find_items(keyring.ITEM_GENERIC_SECRET,
                           {'rhythmbox-plugin': 'magnatune'}, got_items)

    def __download_album(self, audio_dl_uri, sku):
        def download_progress(current, total):
            self.__downloads[str_uri] = (current, total)
            self.__notify_status_changed()

        def download_finished(uri, result):
            del self.__cancellables[str_uri]
            del self.__downloads[str_uri]
				netloc = "%s:%s@%s" % (username, password, parsed.hostname)

				spath = os.path.split(urllib.url2pathname(parsed.path))
				basename = spath[1]
				path = urllib.pathname2url(os.path.join(spath[0], urllib.quote(basename)))

				authed = (parsed[0], netloc, path) + parsed[3:]
				audio_dl_uri = urlparse.urlunparse(authed)

				self.__download_album(gio.File(audio_dl_uri), sku)

			except MagnatunePurchaseError, e:
				rb.error_dialog(title = _("Download Error"),
						message = _("An error occurred while trying to authorize the download.\nThe Magnatune server returned:\n%s") % str(e))
			except Exception, e:
				rb.error_dialog(title = _("Error"),
						message = _("An error occurred while trying to download the album.\nThe error text is:\n%s") % str(e))


		keyring.find_items(keyring.ITEM_GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)

	def __download_album(self, audio_dl_uri, sku):
		def download_progress(current, total):
			self.__downloads[str_uri] = (current, total)
			self.__notify_status_changed()

		def download_finished(uri, result):
			del self.__cancellables[str_uri]
			del self.__downloads[str_uri]

			try:
				success = uri.copy_finish(result)