1
# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
3
# Copyright (C) 2006 Adam Zimmerman <adam_zimmerman@sfu.ca>
4
# Copyright (C) 2006 James Livingston <doclivingston@gmail.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2, or (at your option)
11
# The Rhythmbox authors hereby grant permission for non-GPL compatible
12
# GStreamer plugins to be used and distributed together with GStreamer
13
# and Rhythmbox. This permission is above and beyond the permissions granted
14
# by the GPL license by which Rhythmbox is covered. If you modify this code
15
# you may extend this exception to your version of the code, but you are not
16
# obligated to do so. If you do not wish to do so, delete this exception
17
# statement from your version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28
import xml.sax, xml.sax.handler
30
class BuyAlbumHandler(xml.sax.handler.ContentHandler): # Class to download the track, etc.
33
'flac' : 'URL_FLACZIP',
35
'mp3-cbr' : 'URL_128KMP3ZIP',
36
'mp3-vbr' : 'URL_VBRZIP'
39
def __init__(self, format):
40
xml.sax.handler.ContentHandler.__init__(self)
41
self._format_tag = self.format_map[format] # format of audio to download
43
def startElement(self, name, attrs):
46
def endElement(self, name):
47
if name == "ERROR": # Something went wrong. Display error message to user.
48
raise MagnatunePurchaseError(self._text)
49
elif name == self._format_tag:
51
# Response also contains:
52
# DL_MSG - Message to the user, with promo stuff, etc.
53
# DL_PAGE - URL that the user can go to to manually download the album.
55
def characters(self, content):
56
self._text = self._text + content
58
class MagnatunePurchaseError(Exception):