def set_mpd_uri(service, action, uri): MPDCLIENT = get_client() LIBRARY = get_library() print "Playing %s" % uri match = re.search("/file\/(.*)$", uri) if not match: action.return_error(0, "Invalid URI") itemid = int(match.groups()[0]) song = LIBRARY.get_by_id(itemid) if not isinstance(song, MPDSong): action.return_error() return MPDCLIENT.connect() songdata = MPDCLIENT.playlistfind('file', song.file) if songdata: # If the song is in the current playlist move to it and play it MPDCLIENT.seek(songdata[0]['pos'], 0) else: # Else add it to the playlist then play it MPDCLIENT.add(song.file) songdata = MPDCLIENT.playlistfind('file', song.file) if not songdata: action.return_error() return MPDCLIENT.seek(songdata[0]['pos'], 0) MPDCLIENT.disconnect() getattr(action, "return")()
def handle_position_request(service, action): LIBRARY = get_library() MPDCLIENT = get_client() print "Position" MPDCLIENT.connect() status = MPDCLIENT.status() if not "songid" in status: MPDCLIENT.disconnect() getattr(action, "return")() return songinfo = MPDCLIENT.playlistid(status['songid']) MPDCLIENT.disconnect() w = GUPnPAV.GUPnPDIDLLiteWriter.new("English") song = LIBRARY.songs_by_file.get(songinfo[0]['file'], None) song_id = "0" if song: song.writeself(w) song_id = str(song.id) action.set_values(["Track", "TrackMetaData", "TrackURI"], [song_id, w.get_string(), getattr(song, "url", "")]) action.set_value("TrackDuration", int_to_time(status.get("time", "0:0").split(":")[1])) curtime = int_to_time(status.get("time", "0:0").split(":")[0]) action.set_value("RelTime", curtime) action.set_value("AbsTime", curtime) getattr(action, "return")()
def main(): import sys if len(sys.argv) != 2: print "usage: %s article_title" % __file__ return login_cookie = load_login_cookie library = get_library(login_cookie) uad = None for article in library: if sys.argv[1].lower() == article["title"].lower(): uad = article["user_article_id"] break print uad
def call(self, context, user, **args): if not self.registered: return {} lib = get_library(self.app) call = lib.get_plugin_point_call(self.name) options = call.options base = [self,] if options.get('takes_context', False): base.append(context) if options.get('takes_user', False): base.append(user) if options.get('takes_args', False): return call(*base, **args) return call(self, *base)
def library(self): '''Return the library set for the bundle, or local library from get_library() if one was not set. ''' import library if self._library: l = self._libarary else: l = library.get_library() l.logger = self.logger l.database.logger = self.logger l.bundle = self return l
def handle_state_request(service, action): MPDCLIENT = get_client() LIBRARY = get_library() print "Status" MPDCLIENT.connect() status = MPDCLIENT.status() MPDCLIENT.disconnect() if status and status['state'] == "pause": state = "PAUSED_PLAYBACK" elif status and status['state'] == "play": state = "PLAYING" else: state = "STOPPED" action.set_value("CurrentTransportState", state) action.set_value("CurrentTransportStatus", "OK") action.set_value("CurrentSpeed", "1") getattr(action, "return")()
def set_http_uri(service, action, uri): """ This is a bit tricker. We need to download the file from the local network (hopefully its quick), add the file to MPD (the file has to be 100% downloaded first) then add the file to the playlist and seek to it. 1) Download file 2) Add file to DB 3) Load file to local library 4) Generate an MPD uri and then call set_mpd_uri """ LIBRARY = get_library() MPDCLIENT = get_client() from server import get_context, MUSIC_PATH CONTEXT = get_context() path = uri.replace("http:/", "") filename = os.path.basename(path) if not "." in filename: filename += ".mp3" # assume mp3 for now os.system("wget %s -O %s/%s" % (uri, MUSIC_PATH, filename)) LIBRARY.connect() MPDCLIENT.update(filename) songdata = MPDCLIENT.find('file', filename) if not songdata: action.return_error(0, "Couldn't add file to MPD database") return song_id = LIBRARY.register_song(LIBRARY.song_from_dict(songdata[0])) LIBRARY.disconnect() set_mpd_uri(service, action, "http://%s:%s/file/%s" % ( CONTEXT.get_host_ip(), CONTEXT.get_port(), song_id) )
def browse_action(service, action): itemid = action.get_value('ObjectID', GObject.TYPE_INT) LIBRARY = library.get_library() while not getattr(LIBRARY, "ever_updated", ""): print "Library never updated. Waiting for update to finish..." time.sleep(1) w = GUPnPAV.GUPnPDIDLLiteWriter.new("English") if itemid == 0: for playlist in LIBRARY.playlists: playlist.writeself(w) else: obj = LIBRARY.get_by_id(itemid) if not isinstance(obj, MPDPlaylist): action.return_error() return obj.writeall(w) action.set_value("Result", w.get_string()) action.set_value("NumberReturned", 1) action.set_value("TotalMatches", 1) action.set_value("UpdateID", "0") getattr(action, "return")()
import time import os import clip import library # Global variables LIBPATH = './clippings-library/' FILEDIR = './' FILENAME = 'My Clippings.txt' CLIPPING_END_STRING = '=' * 10 # See if library exists in path lib = '' try: lib = library.get_library(LIBPATH) print('Library found:', lib.get_clip_count(), 'clips') except FileNotFoundError: print('Library doesn\'t exist at', os.path.abspath(LIBPATH)) choice = input('Create new library here? [y/N] ') if choice.lower() == 'y': os.mkdir(LIBPATH) # Create library lib = library.get_library(LIBPATH) print('Library initialized.') else: exit(1) # Read the source file # Open the file, read the data line by line into a list try: file = open(FILEDIR + FILENAME, 'r', encoding='utf-8')
def get_options(self): if not self.registered: return {} lib = get_library(self.app) call = lib.get_plugin_point_call(self.name) return call.options
def library_command(args, rc): import library l = library.get_library(name=args.name) if args.subcommand == 'init': print "Initialize Library" l.database.create() elif args.subcommand == 'server': from databundles.server.main import production_run def run_server(args, rc): production_run(rc, name = args.name) if args.daemonize: daemonize(run_server, args, rc) else: production_run(rc, name = args.name) elif args.subcommand == 'drop': print "Drop tables" l.database.drop() elif args.subcommand == 'clean': print "Clean tables" l.database.clean() elif args.subcommand == 'purge': print "Purge library" l.purge() elif args.subcommand == 'rebuild': print "Rebuild library" l.rebuild() elif args.subcommand == 'info': print "Library Info" print "Database: {}".format(l.database.dsn) print "Remote: {}".format(l.remote) print "Cache: {}".format(l.cache.cache_dir) elif args.subcommand == 'push': if args.force: state = 'all' else: state = 'new' files_ = l.database.get_file_by_state(state) if len(files_): print "-- Pushing to {}".format(l.remote) for f in files_: print "Pushing: {}".format(f.path) l.push(f) elif args.subcommand == 'files': files_ = l.database.get_file_by_state(args.file_state) if len(files_): print "-- Display {} files".format(args.file_state) for f in files_: print "{0:11s} {1:4s} {2}".format(f.ref,f.state,f.path) elif args.subcommand == 'find': dataset, partition = l.get_ref(args.term) if not dataset: print "{}: Not found".format(args.term) else: print "Rel Path : ",dataset.identity.cache_key print "Abs Path : ",l.cache.exists(dataset.identity.cache_key) print "Dataset : ",dataset.id, dataset.name print "Partition : ",(partition.id, partition.name )if partition else '' print "D Is Local: ",l.cache.exists(dataset.identity.cache_key) is not False print "P Is Local: ",(l.cache.exists(partition.identity.cache_key) is not False) if partition else '' elif args.subcommand == 'get': # This will fetch the data, but the return values aren't quite right r = l.get(args.term) if not r: print "{}: Not found".format(args.term) else: print "Rel Path : ",r.bundle.identity.cache_key print "Abs Path : ",l.cache.exists(r.bundle.identity.cache_key) print "Dataset : ",r.bundle.identity.id_, r.bundle.identity.name if r.partition: print "Partition : ",r.partition.identity.id_, r.partition.name else: print "Partition : " print "D Is Local: ",l.cache.exists(r.bundle.identity.cache_key) is not False print "P Is Local: ",(l.cache.exists(r.partition.identity.cache_key) is not False) if r.partition else '' if r and args.open: if r.partition: abs_path = os.path.join(l.cache.cache_dir, r.partition.identity.cache_key) else: abs_path = os.path.join(l.cache.cache_dir, r.bundle.identity.cache_key) print "\nOpening: {}\n".format(abs_path) os.execlp('sqlite3','sqlite3',abs_path ) elif args.subcommand == 'listremote': print 'List Remote' datasets = l.api.list() for id_, data in datasets.items(): print "{0:11s} {1:4s} {2}".format(id_,'remote',data['name']) else: print "Unknown subcommand" print args
def kill_library(): library.get_library().stop_updating()