本文整理汇总了Python中soundcloud.Client方法的典型用法代码示例。如果您正苦于以下问题:Python soundcloud.Client方法的具体用法?Python soundcloud.Client怎么用?Python soundcloud.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类soundcloud
的用法示例。
在下文中一共展示了soundcloud.Client方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: soundcloudirc
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def soundcloudirc(bot, trigger, match=None):
client = soundcloud.Client(client_id=client_id)
match = match or trigger
try:
track = client.get('/resolve', url=match.group(1), client_id=client_id)
except:
return
title = track.title
artist = track.user['username']
hours, ms = divmod(track.duration, 3600000)
minutes, ms = divmod(ms, 60000)
seconds = float(ms)/1000
time = "%02i:%02i" % ( minutes, seconds) if hours is 0 else "%02i:%02i:%02i" % (hours, minutes, seconds)
genre = track.genre
if track.kind == 'track':
plays = track.playback_count
favorites = track.favoritings_count
bot.say(u"{0} - {1} [{2}] ?:{3} ?:{4} {5}".format(artist,title,time,plays,favorites,"Genre: {}".format(genre) if track.genre else ""))
if track.kind == 'playlist':
track_count = track.track_count
bot.say(u"{0} - {1} [{2}] Tracks: {3} {4}".format(artist,title,time,track_count,"Genre: {}".format(genre) if track.genre else ""))
示例2: build_sc_api
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def build_sc_api():
"""Build the SoundCloud API for future use"""
data = datatools.get_data()
if "soundcloud_client_id" not in data["discord"]["keys"]:
logger.warning("No API key found with name 'soundcloud_client_id'")
logger.info("Please add your SoundCloud client id with name 'soundcloud_client_id' "
"in data.json to use Soundcloud features of the music module")
return False
try:
global scclient
scclient = soundcloud.Client(client_id=data["discord"]["keys"]["soundcloud_client_id"])
logger.debug("SoundCloud build successful")
return True
except Exception as e:
logger.exception(e)
return False
示例3: download_sc_data
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def download_sc_data(url):
output = 'cache/'
sc_cli = soundcloud.Client(client_id=SoundCloudClientID)
data = sc_cli.get('/resolve', url=url)
stream_url = sc_cli.get(data.stream_url, allow_redirects=False)
crypt = hashlib.new('md5')
crypt.update(str(data.fields()['id']).encode('utf-8'))
filename = crypt.hexdigest()
file_location = output + filename
if not os.path.exists(file_location):
with open(file_location, 'wb') as data_file:
async with aiohttp.ClientSession() as session:
async with session.get(stream_url.location) as dl_data:
total_data = await dl_data.read()
data_file.write(total_data)
return file_location
示例4: title_from_soundcloud
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def title_from_soundcloud(bot, url):
try:
soundcloud_id = bot.config.get_by_path(["spotify", "soundcloud"])
soundcloud_client = soundcloud.Client(client_id=soundcloud_id)
except (KeyError, TypeError) as e:
logger.error("<b>Soundcloud client ID isn't configured:</b> {}"
.format(e))
return ""
try:
track = soundcloud_client.get("/resolve", url=url)
return track.title
except SoundcloudHTTPError as e:
logger.error("Unable to resolve url {}, {}".format(url, e))
return ""
示例5: get_song_id
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def get_song_id(song_name):
"""Get the soundcloud ids of a song.
Parameters
----------
song_name : str
The song name.
Returns
-------
tuple
First element contains the soundcloud id of the song.
Second element contains the id used for downloading
the song (used by `download_song`).
Raises
------
RuntimeError
If `song_name` id is not found.
"""
client = soundcloud.Client(client_id=SOUNDCLOUD_CLIENT_ID)
tracks = client.get('/tracks', q=song_name)
if len(tracks) > 0:
id = tracks[0].obj['id']
download_id = '{}/{}'.format(
tracks[0].obj['user']['permalink'], tracks[0].obj['permalink'])
return (id, download_id)
raise RuntimeError('Could not find song')
示例6: __init__
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def __init__(self, client_id):
"""
client_id = Client ID, must be registered
"""
self.client_id = client_id
self._api = soundcloud.Client(client_id=self.client_id)
示例7: get_sc_client
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def get_sc_client(fn):
conf = get_yaml_conf(fn)
client = soundcloud.Client(**conf)
return client
示例8: Main
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def Main():
# You need to put your soundcloud email, password, client_id and client_secret into the settings.cfg file
config = ConfigParser.ConfigParser()
try:
config.read('settings.cfg')
print "[+] Read settings"
except:
print "[-] Could not read settings"
sc_id = config.get('soundcloud','client_id')
sc_secret = config.get('soundcloud','client_secret')
sc_username = config.get('soundcloud','username')
sc_password = config.get('soundcloud','password')
client = soundcloud.Client(
client_id=sc_id,
client_secret=sc_secret,
username=sc_username,
password=sc_password
)
print "client credentials ok"
# GENERATE POEM
poemname, newpoem = genPoem()
# MAKE TEMP MP3 FILENAME
temp = tempfile.mkstemp(suffix = ".mp3")
# GET GOOGLE TO SAY IT
v = voice()
makeSpeech(newpoem, temp[1], 'ja')
# SLOW IT
#temp2 = tempfile.mkstemp(suffix = ".mp3")
#makeSlow(temp[1],temp2[1])
#time.sleep(5)
# POST ON SOUNDCLOUD
prettypoem = formatPoem(poemname, newpoem)
postToSC(client,temp[1],poemname,prettypoem)
print("FINISHED")
示例9: __init__
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import Client [as 别名]
def __init__(self):
client = soundcloud.Client(client_id=self.client_id,client_secret = self.cliend_secreat,redirect_url = self.redirect_url)
#if __name__ === '__main__':
# SoundCloudSearch("Eminem Yourself")