rhythmbox-ampache-0.11.1+svn43/0000755000000000000000000000000012263316345014666 5ustar rootrootrhythmbox-ampache-0.11.1+svn43/AmpacheConfigDialog.py0000644000000000000000000000315412263316345021047 0ustar rootroot# vim: expandtab shiftwidth=8 softtabstop=8 tabstop=8 import rb from gi.repository import GObject, Gtk, Gio, PeasGtk class AmpacheConfigDialog(GObject.Object, PeasGtk.Configurable): __gtype_name__ = 'AmpacheConfigDialog' object = GObject.property(type=GObject.Object) def do_create_configure_widget(self): self.settings = Gio.Settings('org.gnome.rhythmbox.plugins.ampache') self.ui = Gtk.Builder() self.ui.add_from_file(rb.find_plugin_file(self, 'ampache-prefs.ui')) self.config_dialog = self.ui.get_object('config') self.url = self.ui.get_object("url_entry") self.url.set_text(self.settings['url']) self.username = self.ui.get_object("username_entry") self.username.set_text(self.settings['username']) self.password = self.ui.get_object("password_entry") self.password.set_visibility(False) self.password.set_text(self.settings['password']) self.url.connect('changed', self.url_changed_cb) self.username.connect('changed', self.username_changed_cb) self.password.connect('changed', self.password_changed_cb) return self.config_dialog def url_changed_cb(self, widget): self.settings['url'] = self.url.get_text() def username_changed_cb(self, widget): self.settings['username'] = self.username.get_text() def password_changed_cb(self, widget): self.settings['password'] = self.password.get_text() rhythmbox-ampache-0.11.1+svn43/ampache-prefs.ui0000644000000000000000000001240412263316345017741 0ustar rootroot True False 5 10 True True 0 True False 0 <b>Ampache Instance:</b> True False True 1 True False GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 3 2 True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 1 2 1 2 True False 0 Server UR_L: True True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 1 2 True False 0 _Username (optional): True 1 2 True False 0 _Password (Key): True 2 3 True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 1 2 2 3 True True 2 rhythmbox-ampache-0.11.1+svn43/ampache.ico0000644000000000000000000001027612263316345016766 0ustar rootroot  ( @ DDeeegggeeeeeeeeeeeeeeeeeeeeeUUUkkkeeegggeeeeeeeeeeeeeeeeeeeeeVVViiiwwwQQQwwwQQQvvvQQQvvvPPPvvvQQQvvvPPPvvvQQQvvvQQQwwwQQQvvvQQQwwwQQQwwwQQQwwwQQQwwwQQQwwwRRRwwwQQQwwwRRRwwwQQQwwwRRRwwwQQQwwwSSSwwwRRRwwwSSSwwwRRRwwwSSSwwwRRRwwwSSSwwwRRRwwwQQQsssSSSwwwJJJbbbSSSwww333555:::<<<---SSSwwwSSSxxxTTTxxxtttjjjlllmmmpppTTTxxxFFFQQQUUUyyyQQQHHHLLLMMMJJJ[[[vvvbbbttt"gggmmmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxnnnaaa@?rhythmbox-ampache-0.11.1+svn43/LICENSE0000644000000000000000000004325412263316345015703 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. rhythmbox-ampache-0.11.1+svn43/ampache.plugin0000644000000000000000000000051712263316345017507 0ustar rootroot[Plugin] Loader=python3 Module=ampache IAge=2 Depends=rb Name=Ampache Library Description=Adds support for playing music from an Ampache instance Authors=Rhythmbox Ampache plugin team Copyright=Copyright ©2008-2010 Rhythmbox Ampache plugin team Website=http://code.google.com/p/rhythmbox-ampache/ rhythmbox-ampache-0.11.1+svn43/setup.py0000644000000000000000000000210512263316345016376 0ustar rootroot#!/usr/bin/env python from distutils.core import setup from distutils.sysconfig import PREFIX from distutils.command.install_data import install_data import os class post_install(install_data): def run(self): # Call parent install_data.run(self) # Execute commands after copying os.system('glib-compile-schemas %s/share/glib-2.0/schemas' % self.install_dir) setup(name="rhythmbox-ampache", cmdclass={"install_data": post_install}, version="0.11", description="A Rhythmbox plugin to stream music from an Ampache server", author="Rhythmbox Ampache plugin team", author_email="rhythmbox-ampache@googlegroups.com", url="http://code.google.com/p/rhythmbox-ampache", data_files=[ ("lib/rhythmbox/plugins/ampache", ["ampache.plugin", "ampache.py", "AmpacheBrowser.py", "AmpacheConfigDialog.py"]), ("share/rhythmbox/plugins/ampache", ["ampache-prefs.ui", "ampache.ico", "ampache.png"]), ("share/glib-2.0/schemas", ["org.gnome.rhythmbox.plugins.ampache.gschema.xml"]), ], ) rhythmbox-ampache-0.11.1+svn43/AmpacheBrowser.py0000644000000000000000000010370112263316345020144 0ustar rootroot# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*- # vim: expandtab shiftwidth=8 softtabstop=8 tabstop=8 from gi.repository import RB from gi.repository import GObject, Gtk, Gio, GLib import time from time import mktime from datetime import datetime import re import hashlib import os import os.path import sys import collections import xml.sax, xml.sax.handler class HandshakeHandler(xml.sax.handler.ContentHandler): def __init__(self, handshake): xml.sax.handler.ContentHandler.__init__(self) self.__handshake = handshake def startElement(self, name, attrs): self.__text = '' def endElement(self, name): self.__handshake[name] = self.__text def characters(self, content): self.__text = self.__text + content class PlaylistsHandler(xml.sax.handler.ContentHandler): def __init__(self, playlists, user): xml.sax.handler.ContentHandler.__init__(self) self.__playlists = playlists self.__user = user def startElement(self, name, attrs): if name == 'playlist': self.__id = int(attrs['id']) self.__text = '' def endElement(self, name): if name == 'playlist': # only private with your user name or public # playlists should be considered if self.__owner == self.__user or \ self.__type == 'public': self.__playlists.append([ self.__id, self.__name, self.__items]) elif name == 'name': self.__name = self.__text elif name == 'items': self.__items = int(self.__text) elif name == 'owner': self.__owner = self.__text elif name == 'type': self.__type = self.__text else: self.__null = self.__text def characters(self, content): self.__text = self.__text + content class SongsHandler(xml.sax.handler.ContentHandler): def __init__(self, is_playlist, source, db, entry_type, albumart, auth, entries): xml.sax.handler.ContentHandler.__init__(self) self.__is_playlist = is_playlist self.__source = source self.__db = db self.__entry_type = entry_type self.__albumart = albumart self.__auth = auth self.__entries = entries self.__clear() self.__re_auth = re.compile('\\b(?:auth|ssid)=[a-fA-F0-9]*') def startElement(self, name, attrs): if name == 'song': self.__id = attrs['id'] self.__text = '' def endElement(self, name): if name == 'song': try: if self.__is_playlist: self.__source.add_location(self.__url, -1) else: # add the track to the database if it doesn't exist entry = self.__db.entry_lookup_by_location(self.__url) if entry == None: entry = RB.RhythmDBEntry.new(self.__db, self.__entry_type, self.__url) self.__entries.append(entry) if self.__artist != '': self.__db.entry_set(entry, RB.RhythmDBPropType.ARTIST, self.__artist) if self.__album != '': self.__db.entry_set(entry, RB.RhythmDBPropType.ALBUM, self.__album) if self.__title != '': self.__db.entry_set(entry, RB.RhythmDBPropType.TITLE, self.__title) if self.__tag != '': self.__db.entry_set(entry, RB.RhythmDBPropType.GENRE, self.__tag) self.__db.entry_set(entry, RB.RhythmDBPropType.TRACK_NUMBER, self.__track) self.__db.entry_set(entry, RB.RhythmDBPropType.DATE, self.__year) self.__db.entry_set(entry, RB.RhythmDBPropType.DURATION, self.__time) self.__db.entry_set(entry, RB.RhythmDBPropType.FILE_SIZE, self.__size) self.__db.entry_set(entry, RB.RhythmDBPropType.RATING, self.__rating) self.__db.commit() self.__albumart[self.__artist + self.__album] = self.__art except Exception as e: # This happens on duplicate uris being added sys.excepthook(*sys.exc_info()) print("Couldn't add %s - %s" % (self.__artist, self.__title), e) self.__clear() elif name == 'url': if self.__auth: # replace ssid string with new auth string self.__text = re.sub(self.__re_auth, 'ssid='+self.__auth, self.__text); self.__url = self.__text elif name == 'artist': self.__artist = self.__text elif name == 'album': self.__album = self.__text elif name == 'title': self.__title = self.__text elif name == 'tag': self.__tag = self.__text elif name == 'track': self.__track = int(self.__text) elif name == 'year': if (GLib.Date.valid_year(int(self.__text))): self.__year = GLib.Date.new_dmy(1, 1, int(self.__text)).get_julian() elif name == 'time': self.__time = int(self.__text) elif name == 'size': self.__size = int(self.__text) elif name == 'rating': self.__rating = int(self.__text) elif name == 'art': if self.__auth: # replace auth string with new auth string self.__text = re.sub(self.__re_auth, 'auth='+self.__auth, self.__text); self.__art = self.__text else: self.__null = self.__text def characters(self, content): self.__text = self.__text + content def __clear(self): self.__id = 0 self.__url = '' self.__artist = '' self.__album = '' self.__title = '' self.__tag = '' self.__track = '' self.__year = 0 self.__time = 0 self.__size = 0 self.__rating = 0 self.__art = '' class AmpachePlaylist(RB.StaticPlaylistSource): def __init__(self, **kwargs): super(AmpachePlaylist, self).__init__(kwargs) GObject.type_register(AmpachePlaylist) class AmpacheBrowser(RB.BrowserSource): def __init__(self, **kwargs): super(AmpacheBrowser, self).__init__(kwargs) self.__limit = 5000 self.__songs_cache = '_songs' self.__cache_directory = os.path.join( RB.user_cache_dir(), 'ampache') self.__songs_cache_filename = os.path.join( self.__cache_directory, ''.join([self.__songs_cache, '.xml'])) self.__settings = Gio.Settings('org.gnome.rhythmbox.plugins.ampache') self.__albumart = {} self.__playlists = collections.deque( [[0, self.__songs_cache]]) self.__caches = collections.deque() self.__playlist_sources = [] self.__entries = [] self.__text = None self.__progress_text = None self.__progress = 1 self.__activated = False # add action RefetchAmpache and assign callback refetch_ampache app = Gio.Application.get_default() action = Gio.SimpleAction(name='refetch-ampache') action.connect('activate', self.refetch_ampache) app.add_action(action) def update(self, force_download): ### download songs from Ampache server def download_songs(uri, items, is_playlist, source, cache_filename): def cache_saved_cb(stream, result, data): try: size = stream.write_bytes_finish(result) except Exception as e: print("error writing file: %s" % (self.__songs_cache_filename)) sys.excepthook(*sys.exc_info()) # close stream stream.close(Gio.Cancellable()) # change modification time to newest time newest_time = int(mktime(self.__handshake_newest.timetuple())) os.utime(cache_filename, (newest_time, newest_time)) # process next playlist download_iterate() def open_append_cb(file, result, data): try: stream = file.append_to_finish(result) except Exception as e: print("error opening file for writing %s" % (cache_filename)) sys.excepthook(*sys.exc_info()) stream.write_bytes_async( data, GLib.PRIORITY_DEFAULT, Gio.Cancellable(), cache_saved_cb, None) print("write to cache file: %s" % (cache_filename)) def songs_downloaded_cb(file, result, data): try: (ok, contents, etag) = file.load_contents_finish(result) except Exception as e: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Songs response: %s') % e) edlg.run() edlg.destroy() self.__activated = False return new_offset = data[0] + self.__limit self.__progress = float(new_offset) / float(items) self.notify_status_changed() if new_offset < items: # download subsequent chunk of songs download_songs_chunk(new_offset, data[1]) else: self.__text = '' self.__progress = 1 self.notify_status_changed() # instantiate songs parser parser = xml.sax.make_parser() parser.setContentHandler(SongsHandler( is_playlist, source, self.__db, self.__entry_type, self.__albumart, self.__handshake_auth, self.__entries)) try: parser.feed(contents) except xml.sax.SAXParseException as e: print("error parsing songs: %s" % e) # remove enveloping and tags # as needed to regenerate one full .xml lines = contents.decode('utf-8').splitlines(True) if data[0] > 0: del lines[:2] if new_offset < items: del lines[-2:] data[1].append_to_async( Gio.FileCreateFlags.NONE, GLib.PRIORITY_DEFAULT, Gio.Cancellable(), open_append_cb, GLib.Bytes.new(''.join(lines).encode('utf-8'))) def download_songs_chunk(offset, cache_file): ampache_server_uri = ''.join([uri, '&offset=%s&limit=%s' % (offset, self.__limit)]) ampache_server_file = Gio.file_new_for_uri(ampache_server_uri) ampache_server_file.load_contents_async( Gio.Cancellable(), songs_downloaded_cb, (offset, cache_file)) print("downloading songs: %s" % (ampache_server_uri)) self.__text = 'Download songs from Ampache server...' self.__progress = 0 self.notify_status_changed() cache_file = Gio.file_new_for_path(cache_filename) # cache_file = open(cache_filename, 'wt', encoding='utf-8') # download first chunk of songs download_songs_chunk(0, cache_file) def download_iterate(): try: playlist = self.__playlists.popleft() print('process playlist: %s' % playlist[1]) if playlist[0] == 0: download_songs( '%s/server/xml.server.php?action=songs&auth=%s' % (self.__settings['url'], self.__handshake_auth), self.__handshake_songs, False, self, self.__songs_cache_filename) else: # create AmpachePlaylist source playlist_source = GObject.new( AmpachePlaylist, shell=self.__shell, entry_type=self.__entry_type, name=_(playlist[1]) ) self.__playlist_sources.append(playlist_source) # insert AmpachePlaylist source into AmpacheBrowser source self.__shell.append_display_page(playlist_source, self) download_songs( '%s/server/xml.server.php?action=playlist_songs&filter=%d&auth=%s' % \ (self.__settings['url'], playlist[0], self.__handshake_auth), playlist[2], True, playlist_source, os.path.join( self.__cache_directory, ''.join([playlist[1], '.xml']))) except Exception as e: print('no more playlists to process') return def playlists_cb(file, result, param): try: (ok, contents, etag) = file.load_contents_finish(result) except Exception as e: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Playlists response: %s') % e) edlg.run() edlg.destroy() self.__activated = False return if len(contents) <= 0: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Playlists response size: 0\nCheck ampache server logs for cause.")) edlg.run() edlg.destroy() self.__activated = False self.__text = '' self.notify_status_changed() return # instantiate playlists parser parser = xml.sax.make_parser() parser.setContentHandler(PlaylistsHandler( self.__playlists, self.__settings['username'])) try: parser.feed(contents) except xml.sax.SAXParseException as e: print("error parsing playlists: %s" % e) download_iterate() ### load songs from cache def load_songs(filename, is_playlist, source): def songs_loaded_cb(file, result, data): try: (ok, contents, etag) = file.load_contents_finish(result) except Exception as e: RB.error_dialog( title=_("Unable to load songs"), message=_("Rhythmbox could not load the Ampache songs.")) return try: # instantiate songs parser parser = xml.sax.make_parser() parser.setContentHandler( SongsHandler( is_playlist, source, self.__db, self.__entry_type, self.__albumart, self.__handshake_auth, self.__entries)) parser.feed(contents) except xml.sax.SAXParseException as e: print("error parsing songs: %s" % e) self.__text = '' self.__progress = 1 self.notify_status_changed() # load next cache load_iterate() self.__text = 'Load from cache "%s"...' % filename self.__progress = 0 self.notify_status_changed() cache_file = Gio.file_new_for_path(filename) cache_file.load_contents_async( Gio.Cancellable(), songs_loaded_cb, None) def load_iterate(): try: cache = self.__caches.popleft() print('process playlist: %s' % cache) if cache == self.__songs_cache: load_songs( self.__songs_cache_filename, False, self) else: # create AmpachePlaylist source playlist_source = GObject.new( AmpachePlaylist, shell=self.__shell, entry_type=self.__entry_type, name=_(cache) ) self.__playlist_sources.append(playlist_source) # insert AmpachePlaylist source into AmpacheBrowser source self.__shell.append_display_page(playlist_source, self) load_songs( os.path.join( self.__cache_directory, ''.join([cache, '.xml'])), True, playlist_source) except Exception as e: print('no more playlists to process') return def enumerate_cache_files(): for filename in os.listdir( os.path.join(RB.user_cache_dir(), 'ampache')): name = os.path.splitext(filename)[0] if name == self.__songs_cache: self.__caches.appendleft(name) else: self.__caches.append(name) print('caches: %s' % self.__caches) # start processing first cache load_iterate() def handshake_cb(file, result, parser): try: (ok, contents, etag) = file.load_contents_finish(result) except Exception as e: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Handshake response: %s') % e) edlg.run() edlg.destroy() self.__activated = False return if len(contents) <= 0: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Handshake response size: 0\nCheck ampache server logs for cause.")) edlg.run() edlg.destroy() self.__activated = False self.__text = '' self.notify_status_changed() return try: parser.feed(contents) except xml.sax.SAXParseException as e: print("error parsing handshake: %s" % e) # convert handshake update time into datetime handshake_update = datetime.strptime( handshake['update'][0:18], '%Y-%m-%dT%H:%M:%S') self.__handshake_newest = handshake_update handshake_add = datetime.strptime( handshake['add'][0:18], '%Y-%m-%dT%H:%M:%S') if handshake_add > self.__handshake_newest: self.__handshake_newest = handshake_add handshake_clean = datetime.strptime( handshake['clean'][0:18], '%Y-%m-%dT%H:%M:%S') if handshake_clean > self.__handshake_newest: self.__handshake_newest = handshake_clean self.__handshake_auth = handshake['auth'] self.__handshake_songs = int(handshake['songs']) # cache file mtime >= handshake newest time: load cached if not force_download and \ os.path.exists(self.__songs_cache_filename) and \ datetime.fromtimestamp(os.path.getmtime( self.__songs_cache_filename)) >= \ self.__handshake_newest: enumerate_cache_files() else: # delete all cache files for filename in os.listdir(self.__cache_directory): abs_filename = os.path.join( self.__cache_directory, filename) try: if os.path.isfile(abs_filename): os.unlink(abs_filename) except Exception as e: print(e) # download playlists ampache_server_uri = \ '%s/server/xml.server.php?action=playlists&auth=%s' % \ (self.__settings['url'], self.__handshake_auth) ampache_server_file = \ Gio.file_new_for_uri(ampache_server_uri) ampache_server_file.load_contents_async( Gio.Cancellable(), playlists_cb, None) print("downloading playlists: %s" % (ampache_server_uri)) # check for errors if not self.__settings['url']: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('URL missing')) edlg.run() edlg.destroy() self.__activated = False return if not self.__settings['password']: edlg = Gtk.MessageDialog( None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Password missing')) edlg.run() edlg.destroy() self.__activated = False return self.__text = 'Update songs...' self.notify_status_changed() handshake = {} # instantiate handshake parser parser = xml.sax.make_parser() parser.setContentHandler(HandshakeHandler(handshake)) # build handshake url timestamp = int(time.time()) password = hashlib.sha256(self.__settings['password'].encode('utf-8')).hexdigest() authkey = hashlib.sha256((str(timestamp) + password).encode('utf-8')).hexdigest() # execute handshake ampache_server_uri = \ '%s/server/xml.server.php?action=handshake&auth=%s×tamp=%s&user=%s&version=350001' % \ (self.__settings['url'], authkey, timestamp, self.__settings['username']) ampache_server_file = Gio.file_new_for_uri(ampache_server_uri) ampache_server_file.load_contents_async( Gio.Cancellable(), handshake_cb, parser) print("downloading handshake: %s" % (ampache_server_uri)) # Source is activated def do_activate(self): # activate source if inactive if not self.__activated: self.__activated = True self.__shell = self.props.shell self.__db = self.__shell.props.db self.__entry_type = self.props.entry_type # connect playing-song-changed signal self.__art_store = RB.ExtDB(name="album-art") self.__art_request = self.__art_store.connect("request", self.__album_art_requested) # create cache directory if it doesn't exist cache_path = os.path.dirname(self.__songs_cache_filename) if not os.path.exists(cache_path): os.mkdir(cache_path, 0o700) self.update(False) # Shortcut for single click def do_selected(self): self.do_activate() def __album_art_requested(self, store, key, last_time): artist = key.get_field('artist') album = key.get_field('album') uri = self.__albumart[artist + album] print('album art uri: %s' % uri) if uri: storekey = RB.ExtDBKey.create_storage('album', album) storekey.add_field('artist', artist) store.store_uri(storekey, RB.ExtDBSourceType.SEARCH, uri) def do_get_status(self, status, progress_text, progress): return (self.__text, self.__progress_text, self.__progress) def clean_db(self): self.__db.entry_delete_by_type(self.__entry_type) self.__db.commit() # self.__entries should be deleted, but here it's too soon, now it just grows on each update def refetch_ampache(self, parameter, user_data): self.clean_db() self.update(True) def do_delete_thyself(self): # delete source if active if self.__activated: self.__activated = False # disconnect from art store self.__art_store.disconnect(self.__art_request) self.__art_store = None # remove playlists for playlist_source in self.__playlist_sources: # delete Playlist source playlist_source.delete_thyself() playlist_source = None # remove all AmpacheEntryTypes from database self.clean_db() RB.BrowserSource.do_delete_thyself(self) GObject.type_register(AmpacheBrowser) rhythmbox-ampache-0.11.1+svn43/ampache.py0000644000000000000000000000554412263316345016646 0ustar rootroot# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*- # vim: expandtab shiftwidth=8 softtabstop=8 tabstop=8 import rb from gi.repository import RB from gi.repository import GObject, Peas, Gtk, Gio, GdkPixbuf from AmpacheConfigDialog import AmpacheConfigDialog from AmpacheBrowser import AmpacheBrowser class AmpacheEntryType(RB.RhythmDBEntryType): def __init__(self): RB.RhythmDBEntryType.__init__( self, name='AmpacheEntryType', save_to_disk=False) def can_sync_metadata(self, entry): return True def sync_metadata(self, entry, changes): return class AmpachePlugin(GObject.Object, Peas.Activatable): __gtype_name__ = 'AmpachePlugin' object = GObject.property(type=GObject.Object) def __init__ (self): super(AmpachePlugin, self).__init__() def do_activate(self): shell = self.object db = shell.props.db # load icon theme = Gtk.IconTheme.get_default() what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) icon = GdkPixbuf.Pixbuf.new_from_file_at_size(rb.find_plugin_file(self, 'ampache.ico'), width, height) # register AmpacheEntryType self.__entry_type = AmpacheEntryType() db.register_entry_type(self.__entry_type) # fetch plugin settings settings = Gio.Settings("org.gnome.rhythmbox.plugins.ampache") menu = Gio.Menu() menu.append('Refetch Ampache Library', 'app.refetch-ampache') # create AmpacheBrowser source self.__source = GObject.new( AmpacheBrowser, shell=shell, entry_type=self.__entry_type, icon=icon, plugin=self, settings=settings.get_child("source"), toolbar_menu=menu, name=_("Ampache") ) self.__first = 1 # assign AmpacheEntryType to AmpacheBrowser source shell.register_entry_type_for_source( self.__source, self.__entry_type) # insert AmpacheBrowser source into Shared group shell.append_display_page( self.__source, RB.DisplayPageGroup.get_by_id("shared")) def do_deactivate(self): # destroy AmpacheBrowser source self.__source.delete_thyself() self.__source = None # destroy entry type self.__entry_type = None rhythmbox-ampache-0.11.1+svn43/WARNING0000644000000000000000000000020512263316345015713 0ustar rootrootThis branch will not be maintained anymore. Further development will take place here: https://github.com/lotan/rhythmbox-ampache rhythmbox-ampache-0.11.1+svn43/org.gnome.rhythmbox.plugins.ampache.gschema.xml0000644000000000000000000000124012263316345026006 0ustar rootroot '' URL for ampache server URL for ampache server '' Username Username '' Password Password rhythmbox-ampache-0.11.1+svn43/README0000644000000000000000000000372212263316345015552 0ustar rootrootINFO Plase see http://code.google.com/p/rhythmbox-ampache/ for the latest version Ampache setup Read Ampache Access Control Lists documentation and create an ACL for RPC (XML API) http://ampache.org/wiki/config:acl Rhythmbox setup Untar and put the ampache directory into $HOME/.gnome2/rhythmbox/plugins or /usr/lib/rhythmbox/plugins Run rhythmbox (preferable with "-D ampache" from command line) Click Edit, select Plugins dialog box, enable "Ampache Library" Click Configure, enter your infromation, for example URL: http://test.com/server/xml.server.php Click on Ampache under Library, songs should appear in the browser COPYRIGHT Copyright (C) 2008-2010 Rhythmbox Ampache plugin team 20-04-2010 - Philip Langdale I did some work over the weekend to fix the blocking nature of the plugin. I switched to using async gio to make the http transfers and dropped the per-request limit to 100. The net result is a much more responsive UI that also shows progress more often. I also fixed the reference leaks that prevent rhythmbox exiting with the plugin today. 19-04-2010 - Graham Grindlay * Added a few small fixes to keep the plugin from choking on bad/empty tag data. * Genre tags didn't seem to be coming through properly so I set them using the "tag" field instead. This seems to work fine, although if multiple tags are associated with a track, only the first one will be used. If you don't like this, you can just comment out line 148 (self.db.set(e, rhythmdb.PROP_GENRE, e_genre)) Patched to work with Ampache 3.5.x by Massimo Mund Copyright (C) 2008 Seva Portions from Magnatune Rhythmbox plugin Copyright (C) 2006 Adam Zimmerman Copyright (C) 2006 James Livingston Portions from 'git clone http://quickplay.isfound.at' Copyright (C) 2008 Kevin James Purdy irc://irc.freenode.org/purdyk,isnick rhythmbox-ampache-0.11.1+svn43/ampache.png0000644000000000000000000001172412263316345016777 0ustar rootrootPNG  IHDRTs汯sRGBPLTE  !!!"""###$$$%%%&&&'''((()))***+++,,,---...///000111222333444555666777888999:::;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz{{{|||}}}~~~7}ftRNS@fbKGDH pHYs  tIME `##IDATx[YS;;3ݸ 6/QQqӀ7TTeÒ@}IXVSUI% hty#}yVNᰰ?fza"P:Ǩ|Ifz*VyhA ȿ. y}A5t|-)HJOխvkR6qZmK|ۚQh_;{y88{٤Rک/~r*'ɓtum.pc/t܅:s|3\wa$T>$Zƨ:2+<6Cbnܪ}&} }r#Hl.EozCCrzrbr 郟)f^LL_>8ϙ2{]FBEO~'۵NE"COCۧE25159E-Rp]5B})]Jcݝ"6 çO)i]7pQmk-ӄ[l6M6hhUحDݝڳkOS7FL4}33jvf[2ڧGj$rlj-/-nӘ=.)iW#'%_Mܛr0Mw,%ͽk ͚1)e͛o_Z'nfJ{b6 YG,kZ'&'huMV04=>r/wM&:>On2=E(0[YJbB&Y  ?n##lPі i0k׮Z, c(393F~!wѠGhOlc&m ͇@kg` a-4FC.l[o0Hw^ 2mT׵ϪF{Ę|f|̏^+m:/hVvP--2;Fɒq_ad@uk8^y37oёRx'Z}U7̂)ִq?K{MeeEeF,ZD $Z誆u˜Z ZɏGFplk2iݫ*knq Waf} !DGU*F)>\D! Tn (aAHE3fG2\:ҳ_eA>< #۴rɬltdPh4j2Ҏ3"ZjR]C[!>7xëGP-k_5Bܠ== 3Z`Bm'32Nd@<ҫ<Q51Q|5 .!fESݸkܑZqyyyD69A RIk?xGѕ/7@OZ( JDV̰Jm'\+*Yx{&NߟJuVt6dkX.6.*rŊyBtx+۴u22=2'3XQAhF *vdE;@P+(܏}w]X%u|Gﺈ)ѮuQ)H=֨}hF[v|wZAE7nh%֎0Wtbr~-h8Їx hAK0mvw~IG^R^;Gq^8NuE_zry/9A\ |{V>71fa/}wtvuR푑V;yMCIQurA_(H1VBs1zY"$5iWQYMο*{zў S~b>`h(pJ!nЮH2TK|qrEQHZ6eV3+P8ڱ鳨EFSiq B!m>kg^7^J{[/ܠDwHRupTGeJ\9 iۙ }Ow]=Ir.hQ@fFT9lTqx?Fg*=ĭF;:;;#NdE,!w;i.)^`НkCDt:H?{qEh+G҅F^ghw*z{9 ׆``43VkiRݠ].AEvE'YP`gwHTBS)|r%Kֈn[pyO[TUM(6OYF92V'QU7ooxw.m8v,5Oggif9~>~BԴRΝ 9@E~ ;Ji9'e\P%G^ֱ4F/i--O$+Gr3P,$NqߩidPN;~3v#]anw3cImnbhx[Þ!~Fy;5xa-<<#w@ 75vذg$1?9ki/nK~73>ͼ1: :&uH~zODAC]^G&=.Z{>%zaQ~\vt?AUYOx;2aۋVHq>Q./lY=Ir ˜P/gI݂SJ԰쌱DZv3'\D׋~a3=st4YHvs^9yk~뾼!v! nU[Nŵ/a3O__(f/xt!ܷ/"m{hdw1ID/0BDco,,,,,,,,,,,,,,,,,,,,,,ǂ#1IENDB`