~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to plugins/magnatune/magnatune/BuyAlbumHandler.py

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
ImportĀ upstreamĀ versionĀ 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
2
 
#
3
 
# Copyright (C) 2006 Adam Zimmerman  <adam_zimmerman@sfu.ca>
4
 
# Copyright (C) 2006 James Livingston  <doclivingston@gmail.com>
5
 
#
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)
9
 
# any later version.
10
 
#
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.
18
 
#
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.
23
 
#
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.
27
 
 
28
 
import xml.sax, xml.sax.handler
29
 
 
30
 
class BuyAlbumHandler(xml.sax.handler.ContentHandler): # Class to download the track, etc.
31
 
        format_map =    {
32
 
                        'ogg'           :       'URL_OGGZIP',
33
 
                        'flac'          :       'URL_FLACZIP',
34
 
                        'wav'           :       'URL_WAVZIP',
35
 
                        'mp3-cbr'       :       'URL_128KMP3ZIP',
36
 
                        'mp3-vbr'       :       'URL_VBRZIP'
37
 
                        }
38
 
 
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
42
 
 
43
 
        def startElement(self, name, attrs):
44
 
                self._text = ""
45
 
 
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:
50
 
                        self.url = self._text
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.
54
 
 
55
 
        def characters(self, content):
56
 
                self._text = self._text + content
57
 
 
58
 
class MagnatunePurchaseError(Exception):
59
 
        pass