当前位置: 首页>>代码示例>>Python>>正文


Python MPDClient.add方法代码示例

本文整理汇总了Python中mpd.MPDClient.add方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.add方法的具体用法?Python MPDClient.add怎么用?Python MPDClient.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpd.MPDClient的用法示例。


在下文中一共展示了MPDClient.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def run():
	if not request.form['url']:
		flash('Please provide an URL')
		return redirect(url_for('welcome'))
	# do stuff
	try:
		p = subprocess.check_output(['/usr/bin/python', 'youtube-dl', '-t', '--no-progress', '--extract-audio', '--max-quality=18', '--audio-format=mp3', '--', request.form['url']])
	except:
		flash("Nice try.")
		return redirect(url_for('welcome'))
	m = re.search("\[ffmpeg\] Destination: (.+?)\s", p)
	myfile = m.group(1)
	shutil.move(myfile, "static/%s" % myfile)
	try:
		mpd = MPDClient()
		try:
			mpd.connect(host="trillian", port="6600")
			mpd.add("http://toolbox.labor.koeln.ccc.de/static/%s" % myfile)
		except:
			raise
	except:
		flash('mpd failure')
		return redirect(url_for('welcome'))
	flash('your song has been added to the playlist')
	return redirect(url_for('welcome'))
开发者ID:MechanisM,项目名称:youconv,代码行数:27,代码来源:youconv.py

示例2: onevent

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def onevent(msg):
    # add song if needed
    client = MPDClient()
    client.connect("localhost", 6600)
    client.use_unicode = True
    if client.status()["playlistlength"] == '0' and autoaddstate == 1:
        song = choose_from_list(current_list)
        client.add(song)
        # while client.status()['state']=='stop':
        client.play()

    # currentsong info
    if 'player' in msg or 'playlist' in msg:
        print("publish currentsong")
        currentsong = client.currentsong()
        print(currentsong)
        # pre-treat the data if artist/title not present:
        if 'title' not in currentsong.keys():
            currentsong['artist'] = "?"
            if 'file' in currentsong.keys():
                currentsong['title'] = currentsong['file'].split('/')[-1]
        yield app.session.publish('radio.updatesong', currentsong)

        # player status info
    if ('player' in msg or
            'mixer' in msg or
            'options' in msg or
            'playlist' in msg):
        print("publish player status")
        status = client.status()
        status[u'autoadd'] = autoaddstate
        yield app.session.publish('radio.updatestatus', status)

    # playlist info
    if 'playlist' in msg:
        print("publish playlist")
        playlist = client.playlistinfo()
        print(playlist)
        playlist_trim = []
        for song in playlist:
            song_trim = {}
            if 'http' in song['file']:
                song_trim['artist'] = song['file']
                song_trim['title'] = ''
                song_trim['time'] = 9999
                song_trim['id'] = song['id']
            else:
                if 'title' not in song.keys() or 'artist' not in song.keys():
                    song_trim['artist'] = "?"
                    if 'file' in song.keys():
                        song_trim['title'] = song['file'].split('/')[-1]
                else:
                    song_trim['artist'] = song['artist']
                    song_trim['title'] = song['title']
                song_trim['id'] = song['id']
                song_trim['time'] = song['time']
            playlist_trim.append(song_trim)
        yield app.session.publish('radio.updateplaylist', playlist_trim)

    client.close()
开发者ID:crazyiop,项目名称:hipsterRadio,代码行数:62,代码来源:autoadd_update.py

示例3: Radio

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
class Radio(object):
    stations = None
    mpd = None
    position = 1
    volume = 50

    def __init__(self, stations):
        self.mpd = MPDClient()
        self.mpd.timeout = 10
        self.mpd.idletimeout = None
        self.mpd.connect("localhost", 6600)
        self.mpd.clear()
        for station in iter(stations):
            if (station != None) and (station != ""):
                self.mpd.add(station)
        self.stations = self.mpd.playlist()
        print("Successfully loaded the following playlist:")
        print(self.stations)
        print("-------")

    def increaseVolume(self):
        if self.volume < 100:
            self.volume = self.volume + 10
            self.setVolume()

    def decreaseVolume(self):
        if self.volume > 0:
            self.volume = self.volume - 10
            self.setVolume()

    def setVolume(self):
        system("amixer sset 'Master' " + str(self.volume) + "%")

    def play(self):
        system("mpc play " + str(self.position))

    def stop(self):
        system("mpc stop")

    def next(self):
        self.position = self.position + 1
        if self.position > len(self.stations):
            self.position = 1
        system("mpc play " + str(self.position))

    def prev(self):
        self.position = self.position - 1
        if self.position < 1:
            self.position = len(self.stations)
        system("mpc play " + str(self.position))

    def selectTrackUpdate(self):
        self.mpd.send_idle("currentsong")
        select([self.mpd], [], [], 10)
        self.mpd.fetch_idle()
        return self.mpd.currentsong()

    def currentStreamName(self):
        return self.streams.keys()[self.position - 1]
开发者ID:kr1schan,项目名称:tube,代码行数:61,代码来源:radio.py

示例4: Play

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
class Play():

    def __init__(self):
        self.client = MPDClient()               # create client object
        #client.timeout = 10                # network timeout in seconds (floats allowed), default: None
        #client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None

    def connect(self):
        try:
            self.client.connect(mpd_host, mpd_port)
            print("MPD Version: " + self.client.mpd_version)          # print the MPD version
        except OSError:
            print("Error connecting to MPD")
        except mpd.ConnectionError:
            # Already connected?
            pass

    def current_track_info(self):
        self.connect()
        try:
            return self.client.currentsong()
        except mpd.ConnectionError:
            print("[ERROR] current_track_info(): mpd.ConnectionError")
            return None
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")
            return None

    def next_track(self):
        self.connect()
        try: 
            self.client.next()
        except mpd.ConnectionError:
            print("[ERROR] next_track(): mpd.ConnectionError")
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")

    def pause(self):
        self.connect()
        try:
            self.client.pause()
        except mpd.ConnectionError:
            print("[ERROR] pause(): mpd.ConnectionError")
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")

    def play_album(self, album_path):
        self.connect()
        # mpc -h 192.168.1.80 -p 6600 listall Yeah_Yeah_Yeahs/
# Maybe you need album_path[1:]?
        print("Requesting mpd play album: {}".format(album_path[1:]))
        try: 
            self.client.clear()
            self.client.add(album_path)     # [1:] to strip leading /
            self.client.play()
        except mpd.ConnectionError:
            print("[ERROR] play_album(): mpd.ConnectionError")
        except mpd.CommandError:
            print("[ERROR] play_album(): mpd.CommandError")
开发者ID:equant,项目名称:jukebox,代码行数:61,代码来源:SubiPlay.py

示例5: item_chosen

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def item_chosen(button, choice):

    client = MPDClient()               # create client object
    client.timeout = 10                # network timeout in seconds (floats allowed), default: None
    client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
    host = os.environ.get('MPD_HOST','localhost')
    client.connect(host, 6600)  # connect to localhost:6600

    client.add(choice)
开发者ID:kstock,项目名称:mu,代码行数:11,代码来源:bran.py

示例6: MyMPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
class MyMPDClient():
    def __init__(self):
	## MPD object instance
	self.client = MPDClient()
	if mpdConnect(self.client, CON_ID):
	    print 'Got connected!'
	else:
	    print 'fail to connect MPD server.'
	    sys.exit(1)

	# Auth if password is set non False
	if PASSWORD:
	    if mpdAuth(client, PASSWORD):
		print 'Pass auth!'
	    else:
		print 'Error trying to pass auth.'
		self.client.disconnect()
		sys.exit(2)
	
    def getCurrentsong(self):
	return self.client.currentsong()
	
    def pause(self):
	return self.client.pause()
    def previous(self):
	return self.client.previous()
    def _next(self):
	return self.client.next()
    def stop(self):
	return self.client.stop()

    def play(self):
	return self.client.play()

    def getStatus(self):
	return self.client.status()
    
    def add(self, item):
	self.client.add(item)
    
    def playlist(self):
	return self.client.playlist()
      
    def getPlaylistid(self):
	return self.client.playlistid()
	
    def playId(self,_id):
	self.client.playid(_id)
    
    def getItemIdInPLaylist(self, item):
      
	playlist =  self.getPlaylistid()
	for pos in playlist:
	      if pos['file'] == item:
		  return pos['id']
	return '-1'
开发者ID:9ex8,项目名称:ArduinoGround,代码行数:58,代码来源:threadedServer.py

示例7: play_MPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def play_MPD(path):
    """ Joue MPD avec comme argument le chemin du fichier à jouer  """
    client = MPDClient()               # create client object
    client.timeout = 10                # network timeout in seconds (floats allowed), default: None
    client.idletimeout = None
    client.connect("localhost", 6600)  # connect to localhost:6600

    MPDClient.add(path)
    client.play(0)
    print MPDClient.playlistinfo()
开发者ID:mike-perdide,项目名称:apiclock,代码行数:12,代码来源:jouer_mpd.py

示例8: jouerMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def jouerMPD(path ='http://audio.scdn.arkena.com/11010/franceculture-midfi128.mp3'):
    """ play mpd with url playlist in arg """
    client             = MPDClient()   # create client object
    client.timeout     = 10            # network timeout in seconds (floats allowed), default: None
    client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
    try:
        client.connect("localhost", 6600)  # connect to localhost:6600
        client.clear()
        client.add(path)
        client.play()
    except Exception :
        print "Can Connect to MPD..."
开发者ID:jeromefiot,项目名称:web_apiclock,代码行数:14,代码来源:functions.py

示例9: addJsonToPlaylist

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def addJsonToPlaylist(jsonToplist):
    mpdClient = MPDClient()
    mpdClient.timeout = 10
    mpdClient.idletimeout = None
    mpdClient.connect(settings.settings["mpdHost"], settings.settings["mpdPort"])
    totalAdded = 0
    for song in jsonToplist:
        songPath = song["path"]
        mpdClient.add(songPath)
        totalAdded += 1
    mpdClient.close()
    mpdClient.disconnect()
    return totalAdded
开发者ID:brantsch,项目名称:mpr,代码行数:15,代码来源:mpdrating.py

示例10: load_radio

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def load_radio():
    pls_url = get_playlist_url(RADIO_FEED_URL)

    client = MPDClient()
    client.timeout = MPD_TIMEOUT
    client.connect(MPD_SERVER, 6600)
    client.setvol(100)
    client.clear()
    client.add(pls_url)
    client.play()
    client.close()
    client.disconnect()

    return ""
开发者ID:j4y-funabashi,项目名称:orac,代码行数:16,代码来源:orac.py

示例11: jouerMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def jouerMPD(path ='http://audio.scdn.arkena.com/11010/franceculture-midfi128.mp3'):
    """Play mpd with url playlist in arg."""
    client = MPDClient()    # create client object
    client.timeout = 10     # network timeout in seconds
    client.idletimeout = None
    try:
        client.connect("localhost", 6600)  # connect to localhost:6600
        client.update()
        client.clear()
        client.add(path)
        client.play()
        global MPDstatut            # get and modify MPD statut in navbar
        MPDstatut = client.status()['state']
        print MPDstatut
    except Exception:
        print "Can't Connect to MPD..."
开发者ID:Badaben,项目名称:APIClock,代码行数:18,代码来源:functions.py

示例12: add_spotify_directory

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def add_spotify_directory(name):
    client=MPDClient()
    mopidyAddress = 'localhost'
    mopidyPort = 6600

    client.timeout = 10
    client.idletimeout = None
    client.connect(mopidyAddress,mopidyPort)
    #client.password('IlPits2013')
    foldername = 'Spotify/{name:s}'.format(name=name)

    files = client.lsinfo(foldername)
    files = [x['file'] for x in files]
    files = sorted(files)
    for f in files:
        client.add(f)
    #print(files)
    client.disconnect()
开发者ID:NilsNoreyson,项目名称:phoneBookServer,代码行数:20,代码来源:get_phonebook_files.py

示例13: main

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def main(files, con_id=None, password=None):

    if len(files) == 0:
        return

    # First, connect to MPD. If that doesn't work, there is no use in
    # creating symlinks or doing anything else

    client = MPDClient()
    client.connect(**(con_id or CON_ID))

    if password or PASSWORD:
        mpdAuth(client, password or PASSWORD)

    # Process the command line arguments and create symlinks
    names = all_links(files)

    # if a DB update is in progress, wait for it to finish
    while still_updating(client):
        pass

    # Update the database
    client.update()

    # Wait for the database update to finish
    while still_updating(client):
        pass

    # Get the position of the first song we're going to add
    # Pos is 0-based, so no need to add 1
    pos = get_playlist_length(client);

    # Add song(s)
    for n in names:
        client.add(n)

    # Start playing if necessary
    if not is_playing(client):
        client.play(pos)

    # Clean up
    client.disconnect()

    return (pos + 1, len(names))
开发者ID:tinuzz,项目名称:traxx,代码行数:46,代码来源:mpdplay.py

示例14: _add_to_mopidy

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
    def _add_to_mopidy(self, track_id):
        """ Play a mopidy compatible track """
        client = MPDClient()
        client.connect(MOPIDY_HOST, MOPIDY_PORT)
        client.single(1)
        client.clear()
        try:
            client.add(track_id)
            client.play(0)
        except CommandError as e:
            self.print_queue.put("Failed to add song to Mopidy: " + str(e))
        client.close()
        client.disconnect()

        def quit():
            mpd_exec("stop")
            interrupt_main()

        def status():
            song = mpd_exec("currentsong")
            status = mpd_exec("status")
            # TODO: make prettier...
            status_line = song['artist'] + ' - ' + song['title'] + '\n' + \
                '[' + status['state'] + '] ' + status['elapsed']
            self.print_queue.put(status_line)

        def toggle():
            mpd_exec("pause")
            status()

        def play():
            mpd_exec("play")

        def stop():
            mpd_exec("stop")

        self.set_cmd_map({"pause":  toggle,
                          "play":   play,
                          "stop":   stop,
                          "toggle": toggle,
                          "quit":   quit,
                          "status": status})

        self._mopidy_idle()
开发者ID:cthit,项目名称:playIT-grails,代码行数:46,代码来源:playIT_client.py

示例15: index

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import add [as 别名]
def index():
    url = request.form.get('url', '')
    try:
        mpd = MPDClient()
        mpd.connect(host=app.config["MPD_HOST"], port=app.config["MPD_PORT"])
        if app.config["MPD_PASSWORD"]:
            mpd.password(app.config["MPD_PASSWORD"])
        if url:
            try:
                yt_info = get_info(url)
                if not 'title' in yt_info:
                    flash("Could not find the video", "danger")
                else:
                    mpd.add(url_for('stream', _external=True) + "?t=%s&v=%s" % (
                        quote(secure_filename(yt_info['title'])), quote(url)))
                    flash("Added '" + yt_info['title'] + "' to the MPD queue.", "success")
            except Exception as e:
                flash("Could not add video to MPD: " + str(e), "danger")
    except Exception as e:
        flash("Could not connect to MPD. " + str(e), "danger")
    return render_template('index.html', url=url, )
开发者ID:ceari,项目名称:mpd_youtube_proxy,代码行数:23,代码来源:mpd_youtube.py


注:本文中的mpd.MPDClient.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。