Ejemplo n.º 1
0
        def account_details_changed(entry, event):
            username = builder.get_object("username_entry").get_text()
            password = builder.get_object("password_entry").get_text()

            if username == "" or password == "":
                print("missing something")
                return

            # should actually try a request to http://username:[email protected]/
            # to check the password is correct..

            MagnatuneAccount.instance().update(username, password)
Ejemplo n.º 2
0
		def account_details_changed(entry, event):
			username = builder.get_object("username_entry").get_text()
			password = builder.get_object("password_entry").get_text()

			if username == "" or password == "":
				print("missing something")
				return

			# should actually try a request to http://username:[email protected]/
			# to check the password is correct..

			MagnatuneAccount.instance().update(username, password)
Ejemplo n.º 3
0
    def __auth_download(self, sku):  # http://magnatune.com/info/api
        def auth_data_cb(data, userpass):
            (username, password) = userpass
            dl_album_handler = DownloadAlbumHandler(self.__settings['format'])
            auth_parser = xml.sax.make_parser()
            auth_parser.setContentHandler(dl_album_handler)

            if data is None:
                # hmm.
                return

            try:
                data = data.decode("utf-8")
                data = data.replace(
                    "<br>", ""
                )  # get rid of any stray <br> tags that will mess up the parser
                data = data.replace(
                    " & ", " &amp; ")  # clean up some missing escaping
                # print data
                auth_parser.feed(data)
                auth_parser.close()

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

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

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

                print("download uri for %s is %s" % (sku, audio_dl_uri))
                self.__download_album(audio_dl_uri, sku)

            except MagnatuneDownloadError as 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 as e:
                sys.excepthook(*sys.exc_info())
                RB.error_dialog(
                    title=_("Error"),
                    message=
                    _("An error occurred while trying to download the album.\nThe error text is:\n%s"
                      ) % str(e))

        print("downloading album: " + sku)
        account = MagnatuneAccount.instance()
        (account_type, username, password) = account.get()
        url_dict = {'id': magnatune_partner_id, 'sku': sku}
        url = magnatune_api_download_uri % (username, password)
        url = url + urllib.parse.urlencode(url_dict)

        l = rb.Loader()
        l.get_url(url, auth_data_cb, (username, password))
Ejemplo n.º 4
0
	def __auth_download(self, sku): # http://magnatune.com/info/api

		def auth_data_cb(data, userpass):
			(username, password) = userpass
			dl_album_handler = DownloadAlbumHandler(self.__settings['format'])
			auth_parser = xml.sax.make_parser()
			auth_parser.setContentHandler(dl_album_handler)

			if data is None:
				# hmm.
				return

			try:
				data = data.decode("utf-8")
				data = data.replace("<br>", "") # get rid of any stray <br> tags that will mess up the parser
				data = data.replace(" & ", " &amp; ") # clean up some missing escaping
				# print data
				auth_parser.feed(data)
				auth_parser.close()

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

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

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

				print("download uri for %s is %s" % (sku, audio_dl_uri))
				self.__download_album(audio_dl_uri, sku)

			except MagnatuneDownloadError as 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 as e:
				sys.excepthook(*sys.exc_info())
				RB.error_dialog(title = _("Error"),
						message = _("An error occurred while trying to download the album.\nThe error text is:\n%s") % str(e))

		print("downloading album: " + sku)
		account = MagnatuneAccount.instance()
		(account_type, username, password) = account.get()
		url_dict = {
			'id':	magnatune_partner_id,
			'sku':	sku
		}
		url = magnatune_api_download_uri % (username, password)
		url = url + urllib.parse.urlencode(url_dict)

		l = rb.Loader()
		l.get_url(url, auth_data_cb, (username, password))
Ejemplo n.º 5
0
 def __init__(self):
     RB.RhythmDBEntryType.__init__(self, name='magnatune')
     self.URIre = re.compile(r'^http://[^.]+\.magnatune\.com/')
     self.nsre = re.compile(r'\.(mp3|ogg)$')
     self.account = MagnatuneAccount.instance()
Ejemplo n.º 6
0
 def __init__(self):
     GObject.GObject.__init__(self)
     self.settings = Gio.Settings("org.gnome.rhythmbox.plugins.magnatune")
     self.account = MagnatuneAccount.instance()
Ejemplo n.º 7
0
	def __init__(self):
		RB.RhythmDBEntryType.__init__(self, name='magnatune')
		self.URIre = re.compile(r'^http://[^.]+\.magnatune\.com/')
		self.nsre = re.compile(r'\.(mp3|ogg)$')
		self.account = MagnatuneAccount.instance()
Ejemplo n.º 8
0
	def __init__(self):
		GObject.GObject.__init__(self)
		self.settings = Gio.Settings("org.gnome.rhythmbox.plugins.magnatune")
		self.account = MagnatuneAccount.instance()
            except MagnatuneDownloadError, 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:
                sys.excepthook(*sys.exc_info())
                RB.error_dialog(
                    title=_("Error"),
                    message=
                    _("An error occurred while trying to download the album.\nThe error text is:\n%s"
                      ) % str(e))

        print "downloading album: " + sku
        account = MagnatuneAccount.instance()
        (account_type, username, password) = account.get()
        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 __download_album(self, audio_dl_uri, sku):
        def download_progress(copy, complete, total, self):
            self.__downloads[audio_dl_uri] = (complete, total)
            self.__notify_status_changed()

        def download_finished(copy, success, self):
            del self.__downloads[audio_dl_uri]
Ejemplo n.º 10
0
                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:
                sys.excepthook(*sys.exc_info())
                RB.error_dialog(
                    title=_("Error"),
                    message=_("An error occurred while trying to download the album.\nThe error text is:\n%s") % str(e),
                )

        print "downloading album: " + sku
        account = MagnatuneAccount.instance()
        (account_type, username, password) = account.get()
        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 __download_album(self, audio_dl_uri, sku):
        def download_progress(copy, complete, total, self):
            self.__downloads[audio_dl_uri] = (complete, total)
            self.__notify_status_changed()

        def download_finished(copy, success, self):
            del self.__downloads[audio_dl_uri]