audio_services should now be completely independent from the source code it's self. #273

This commit is contained in:
paul 2019-02-26 08:50:38 +01:00
parent c82ef1855c
commit fe72fe97b5
2 changed files with 23 additions and 13 deletions

View File

@ -1,8 +1,8 @@
from audio_services import matches_url from audio_services import matches_url
import json
import re
import urllib
import youtube_utils import youtube_utils
import requests
@matches_url('https://audioboom.com') @matches_url('https://audioboom.com')
def convert_audioboom(url): def convert_audioboom(url):
@ -14,16 +14,14 @@ def convert_audioboom(url):
@matches_url ('https://soundcloud.com/') @matches_url ('https://soundcloud.com/')
def convert_soundcloud (url): def convert_soundcloud (url):
client_id = "df8113ca95c157b6c9731f54b105b473" client_id = "df8113ca95c157b6c9731f54b105b473"
permalink = urllib.urlopen ('http://api.soundcloud.com/resolve.json?client_id=%s&url=%s' %(client_id, url)) with requests.get('http://api.soundcloud.com/resolve.json', client_id=client_id, url=url) as permalink:
if permalink.getcode () == 404: if permalink.status_code==404:
permalink.close () raise TypeError('%r is not a valid URL' % permalink.url)
raise TypeError('%r is not a valid URL' % url) else:
else: resolved_url = permalink.url
resolved_url = permalink.geturl () with requests.get(resolved_url) as track_url:
permalink.close () track_data = track_url.json()
track_url = urllib.urlopen (resolved_url)
track_data = json.loads (track_url.read ())
track_url.close ()
if track_data ['streamable']: if track_data ['streamable']:
return track_data ['stream_url'] + "?client_id=%s" %client_id return track_data ['stream_url'] + "?client_id=%s" %client_id
else: else:

View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
import youtube_dl
def get_video_url(url):
ydl = youtube_dl.YoutubeDL({'quiet': True, 'format': 'bestaudio/best', 'outtmpl': u'%(id)s%(ext)s'})
with ydl:
result = ydl.extract_info(url, download=False)
if 'entries' in result:
video = result['entries'][0]
else:
video = result
return video["url"]