-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundcloud_service.py
38 lines (32 loc) · 1.38 KB
/
soundcloud_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import soundcloud
from media_entry import MediaEntry
from service_interface import ServiceInterface
import youtube_dl
from FileDownloader import FileDownloader
class SoundCloudService(ServiceInterface):
def __init__(self):
ServiceInterface.__init__(self)
self._client = soundcloud.Client(client_id="a0f302b73e746e103ea4be14fac09677")
self.downloader = None
self._current_feed = None
self._name = "soundcloud"
def search(self, words):
self._current_feed = self._client.get('/tracks', q=words)
return self._createMediaEntries()
def _createMediaEntries(self):
_entries = []
for entry in self._current_feed:
artwork_url = entry.obj["artwork_url"]
if artwork_url is None:
artwork_url = "soundcloud_default.png"
_mediaEntry = MediaEntry(entry.obj["permalink_url"],
[artwork_url],
entry.obj["title"],
str(entry.obj["duration"] / 1000), # Duration is in milliseconds
entry.obj["description"],
self,
audio_only=True)
_entries.append(_mediaEntry)
return _entries
def _get_url_from_infos(self, infos):
return infos["formats"][0]