Merge pull request #1158 from hairmare/fix/remove-soundcloud

fix(soundcloud): remove broken integration
This commit is contained in:
Kyle Robbertze 2021-01-24 23:09:30 +02:00 committed by GitHub
commit 90e5005c76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
85 changed files with 133081 additions and 118229 deletions

View file

@ -29,7 +29,6 @@ CELERY_RESULT_PERSISTENT = True # Persist through a broker restart
CELERY_TASK_RESULT_EXPIRES = 900 # Expire task results after 15 minutes
CELERY_RESULT_EXCHANGE = "celeryresults" # Default exchange - needed due to php-celery
CELERY_QUEUES = (
Queue("soundcloud", exchange=Exchange("soundcloud"), routing_key="soundcloud"),
Queue("podcast", exchange=Exchange("podcast"), routing_key="podcast"),
Queue(exchange=Exchange("celeryresults"), auto_delete=True),
)

View file

@ -5,7 +5,6 @@ install_aliases()
import os
import json
import requests
import soundcloud
import cgi
import posixpath
import shutil
@ -23,134 +22,6 @@ celery = Celery()
logger = get_task_logger(__name__)
@celery.task(name="soundcloud-upload", acks_late=True)
def soundcloud_upload(data, token, file_path):
"""
Upload a file to SoundCloud
:param data: associative array containing SoundCloud metadata
:param token: OAuth2 client access token
:param file_path: path to the file being uploaded
:return: JSON formatted string of the SoundCloud response object
:rtype: string
"""
client = soundcloud.Client(access_token=token)
# Open the file with requests if it's a cloud file
data["asset_data"] = (
open(file_path, "rb")
if os.path.isfile(file_path)
else requests.get(file_path).content
)
try:
logger.info("Uploading track: {0}".format(data))
track = client.post("/tracks", track=data)
except Exception as e:
logger.info("Error uploading track {title}: {0}".format(e.message, **data))
raise e
data["asset_data"].close()
return json.dumps(track.fields())
@celery.task(name="soundcloud-download", acks_late=True)
def soundcloud_download(token, callback_url, api_key, track_id):
"""
Download a file from SoundCloud
:param token: OAuth2 client access token
:param callback_url: callback URL to send the downloaded file to
:param api_key: API key for callback authentication
:param track_id: SoundCloud track identifier
:return: JSON formatted string of file identifiers for the downloaded tracks
:rtype: string
"""
client = soundcloud.Client(access_token=token)
obj = {}
try:
track = client.get("/tracks/%s" % track_id)
obj.update(track.fields())
if track.downloadable:
re = None
with closing(
requests.get(
"%s?oauth_token=%s" % (track.download_url, client.access_token),
verify=True,
stream=True,
)
) as r:
filename = get_filename(r)
re = requests.post(
callback_url,
files={"file": (filename, r.content)},
auth=requests.auth.HTTPBasicAuth(api_key, ""),
)
re.raise_for_status()
try:
response = re.content.decode()
except (UnicodeDecodeError, AttributeError):
response = re.content
f = json.loads(
response
) # Read the response from the media API to get the file id
obj["fileid"] = f["id"]
else:
# manually update the task state
self.update_state(
state=states.FAILURE,
meta="Track %s is not flagged as downloadable!" % track.title,
)
# ignore the task so no other state is recorded
raise Ignore()
except Exception as e:
logger.info("Error during file download: {0}".format(e.message))
raise e
return json.dumps(obj)
@celery.task(name="soundcloud-update", acks_late=True)
def soundcloud_update(data, token, track_id):
"""
Update a file on SoundCloud
:param data: associative array containing SoundCloud metadata
:param token: OAuth2 client access token
:param track_id: SoundCloud ID of the track to be updated
:return: JSON formatted string of the SoundCloud response object
:rtype: string
"""
client = soundcloud.Client(access_token=token)
try:
logger.info("Updating track {title}".format(**data))
track = client.put("/tracks/%s" % track_id, track=data)
except Exception as e:
logger.info("Error updating track {title}: {0}".format(e.message, **data))
raise e
return json.dumps(track.fields())
@celery.task(name="soundcloud-delete", acks_late=True)
def soundcloud_delete(token, track_id):
"""
Delete a file from SoundCloud
:param token: OAuth2 client access token
:param track_id: SoundCloud track identifier
:return: JSON formatted string of the SoundCloud response object
:rtype: string
"""
client = soundcloud.Client(access_token=token)
try:
logger.info("Deleting track with ID {0}".format(track_id))
track = client.delete("/tracks/%s" % track_id)
except Exception as e:
logger.info("Error deleting track!")
raise e
return json.dumps(track.fields())
@celery.task(name="podcast-download", acks_late=True)
def podcast_download(
id, url, callback_url, api_key, podcast_name, album_override, track_title

View file

@ -48,7 +48,7 @@ setup(
author_email="duncan.sommerville@sourcefabric.org",
license="MIT",
packages=["airtime-celery"],
install_requires=["soundcloud", "celery==4.4.7", "kombu==4.6.10", "configobj"],
install_requires=["celery==4.4.7", "kombu==4.6.10", "configobj"],
zip_safe=False,
data_files=data_files,
)