本文整理汇总了Python中soundcloud.com方法的典型用法代码示例。如果您正苦于以下问题:Python soundcloud.com方法的具体用法?Python soundcloud.com怎么用?Python soundcloud.com使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类soundcloud
的用法示例。
在下文中一共展示了soundcloud.com方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: title_from_youtube
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def title_from_youtube(bot, url):
try:
youtube_api_key = bot.config.get_by_path(["spotify", "youtube"])
youtube_client = build("youtube", "v3", developerKey=youtube_api_key)
except (KeyError, TypeError) as e:
logger.error("<b>YouTube API key isn't configured:</b> {}".format(e))
return ""
# Regex by mantish from http://stackoverflow.com/a/9102270 to get the
# video id from a YouTube URL.
match = re.match(
r"^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*", url)
if match and len(match.group(2)) == 11:
video_id = match.group(2)
else:
logger.error("Unable to extract video id: {}".format(url))
return ""
# YouTube response is JSON.
try:
response = youtube_client.videos().list( # pylint: disable=no-member
part="snippet", id=video_id).execute()
items = response.get("items", [])
if items:
return items[0]["snippet"]["title"]
else:
logger.error("<b>YouTube response was empty:</b> {}"
.format(response))
return ""
except YouTubeHTTPError as e:
logger.error("Unable to get video entry from {}, {}".format(url, e))
return ""
示例2: extract_music_links
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def extract_music_links(text):
"""Returns an array of music URLs. Currently searches only for YouTube,
Soundcloud, and Spotify links."""
m = re.compile((r"(https?://)?([a-z0-9.]*?\.)?(youtube.com/|youtu.be/|"
r"soundcloud.com/|spotify.com/track/)"
r"([\w.,@?^=%&:/~+#-]*[\[email protected]?^=%&/~+#-])"))
links = m.findall(text)
links = ["".join(link) for link in links]
# Turn all URIs into URLs (necessary for the Spotify API).
return [l if re.match("https?://", l) else "https://" + l for l in links]
示例3: spotify
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def spotify(bot, event, *args):
"""Commands to manage the Spotify playlist.
<b>/bot spotify</b> Returns whether Spotify is on or off.
<b>/bot spotify on/off</b> Turns Spotify on or off.
<b>/bot spotify playlist</b> Returns the chat's playlist URL.
<b>/bot spotify <query></b> Directly adds a track to the playlist.
<b>/bot spotify remove <track></b> Removes the track from the playlist.
"""
# Start with Spotify off.
enabled = bot.conversation_memory_get(event.conv_id, "spotify_enabled")
if enabled == None:
enabled = False
bot.conversation_memory_set(event.conv_id, "spotify_enabled", enabled)
if not args:
s = "on" if enabled else "off"
result = _("<em>Spotify is <b>{}</b>.</em>".format(s))
else:
command = args[0]
if command == "on" or command == "off":
s = "was" if enabled else "wasn't"
enabled = command == "on"
result = _("<em>Spotify {} on. Now it's <b>{}</b>.</em>"
.format(s, command))
bot.conversation_memory_set(
event.conv_id, "spotify_enabled", enabled)
elif not enabled:
result = _(("<em>Spotify is <b>off</b>. To turn it on, "
"use <b>/bot spotify on</b></em>"))
elif command == "help" and len(args) == 1:
result = _("<em>Did you mean <b>/bot help spotify</b>?</em>")
elif command == "playlist" and len(args) == 1:
playlist = chat_playlist(bot, event)
result = _("<em>Spotify playlist: {}</em>".format(playlist.url))
elif command == "remove" and len(args) < 3:
if len(args) == 1 or not "spotify.com/track/" in args[1]:
result = _("<em>You must specify a Spotify track.</em>")
else:
result = remove_from_playlist(bot, event, args[1])
else:
query = " ".join(args)
result = add_to_spotify(bot, event, query)
return result
示例4: main
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def main():
with cloud_speech.beta_create_Speech_stub(
make_channel('speech.googleapis.com', 443)) as service:
# For streaming audio from the microphone, there are three threads.
# First, a thread that collects audio data as it comes in
with record_audio(RATE, CHUNK) as buffered_audio_data:
# Second, a thread that sends requests with that data
requests = request_stream(buffered_audio_data, RATE)
# Third, a thread that listens for transcription responses and playback
recognize_stream = service.StreamingRecognize(
requests, DEADLINE_SECS)
# Exit things cleanly on interrupt
signal.signal(signal.SIGINT, lambda *_: recognize_stream.cancel())
# Now, put the transcription responses to use.
try:
listen_print_loop(recognize_stream)
recognize_stream.cancel()
except face.CancellationError:
# This happens because of the interrupt handler
pass
示例5: download_song
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def download_song(id, format):
"""Download a song from soundcloud.
Parameters
----------
id : str
The song's soundcloud id (download id).
format : str
The format in which to convert the song after downloading.
Raises
------
ValueError
If `format` is not supported.
"""
if format not in SUPPORTED_FORMATS:
raise ValueError('Format not supported: {}'.format(format))
with downloaders[format] as ydl:
return ydl.download(['http://soundcloud.com/' + id])
示例6: get_dummy_songs
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def get_dummy_songs():
links = ["https://open.spotify.com/track/7eRhdHZPcndoK0C9K4rLM5",
"https://www.youtube.com/watch?v=au0PRVF_RzU",
"https://soundcloud.com/joshpan/killshot",
"https://www.youtube.com/watch?v=YMi8pXOaR9M",
"https://open.spotify.com/track/2djY65hifu2a4R2WqcXqKL",
"https://soundcloud.com/retrojace/my-boys-ft-yung-lean-prod-by-ducko-mcfli",
"https://www.youtube.com/watch?v=YBUZNfbJnp4",
"https://www.youtube.com/watch?v=9vRtx8cICvs",
"https://www.youtube.com/watch?v=FbO_H4at5Gs",
"https://soundcloud.com/activexmike/im-a-nobody",
"https://open.spotify.com/track/6plT7nFGiXKSBP9HFSI4ef",
"https://soundcloud.com/bip-ling/bip-burger-1",]
return links
示例7: verify_soundcloud
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def verify_soundcloud(url):
try:
if "/sets/" in url:
print("THIS ISN'T SUPPORTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") # TODO: this is gross
raise HTTPError
track = client.get('/resolve', url=url)
except HTTPError:
# The soundcloud API will randomly fail on some tracks for no apparent reason
# see: http://stackoverflow.com/questions/36360202/soundcloud-api-urls-timing-out-and-then-returning-error-403-on-about-50-of-trac
return False
return True
示例8: render_soundcloud
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def render_soundcloud(url):
# render a soundcloud embed
if "/sets/" in url:
print("THIS ISN'T SUPPORTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") # TODO: this is gross
try:
track = client.get('/resolve', url=url)
except HTTPError:
# The soundcloud API will randomly fail on some tracks for no apparent reason
# see: http://stackoverflow.com/questions/36360202/soundcloud-api-urls-timing-out-and-then-returning-error-403-on-about-50-of-trac
pass
return render_template("soundcloud.html", URI=track.id)
示例9: SoundCloudSearch
# 需要导入模块: import soundcloud [as 别名]
# 或者: from soundcloud import com [as 别名]
def SoundCloudSearch(text):
text = str(text).replace(' ',"%20")
search_link = "https://soundcloud.com/search?q=" + text
print(search_link)
webbrowser.open(search_link)