diff --git a/src/audio_services/services.py b/src/audio_services/services.py index 3860deeb..8c89e7cf 100644 --- a/src/audio_services/services.py +++ b/src/audio_services/services.py @@ -1,8 +1,8 @@ from audio_services import matches_url -import json -import re -import urllib import youtube_utils +import requests + + @matches_url('https://audioboom.com') def convert_audioboom(url): @@ -14,16 +14,14 @@ def convert_audioboom(url): @matches_url ('https://soundcloud.com/') def convert_soundcloud (url): client_id = "df8113ca95c157b6c9731f54b105b473" - permalink = urllib.urlopen ('http://api.soundcloud.com/resolve.json?client_id=%s&url=%s' %(client_id, url)) - if permalink.getcode () == 404: - permalink.close () - raise TypeError('%r is not a valid URL' % url) - else: - resolved_url = permalink.geturl () - permalink.close () - track_url = urllib.urlopen (resolved_url) - track_data = json.loads (track_url.read ()) - track_url.close () + with requests.get('http://api.soundcloud.com/resolve.json', client_id=client_id, url=url) as permalink: + if permalink.status_code==404: + raise TypeError('%r is not a valid URL' % permalink.url) + else: + resolved_url = permalink.url + with requests.get(resolved_url) as track_url: + track_data = track_url.json() + if track_data ['streamable']: return track_data ['stream_url'] + "?client_id=%s" %client_id else: diff --git a/src/youtube_utils.py b/src/audio_services/youtube_utils.py similarity index 100% rename from src/youtube_utils.py rename to src/audio_services/youtube_utils.py diff --git a/src/controller/buffers/twitterBuffers.py b/src/controller/buffers/twitterBuffers.py index 1cce2ce1..25f3a6be 100644 --- a/src/controller/buffers/twitterBuffers.py +++ b/src/controller/buffers/twitterBuffers.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import time import platform if platform.system() == "Windows": @@ -17,7 +17,7 @@ import config import sound import languageHandler import logging -import youtube_utils +from audio_services import youtube_utils from controller.buffers import baseBuffers from sessions.twitter import compose, utils from mysc.thread_utils import call_threaded diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 95345826..81abcf3b 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -4,7 +4,7 @@ import platform system = platform.system() import application import requests -import youtube_utils +from audio_services import youtube_utils import arrow if system == "Windows": from update import updater diff --git a/src/snapshot.zip b/src/snapshot.zip new file mode 100644 index 00000000..41a65de4 Binary files /dev/null and b/src/snapshot.zip differ diff --git a/src/sound.py b/src/sound.py index 2926e867..68b3f039 100644 --- a/src/sound.py +++ b/src/sound.py @@ -11,7 +11,7 @@ import audio_services import paths import sound_lib import output -import youtube_utils +from audio_services import youtube_utils import application system = platform.system() if system=="Windows" and not hasattr(sys, 'frozen'): # We are running from source on Windows