metube icon indicating copy to clipboard operation
metube copied to clipboard

how to delete a file using the API?

Open lfnt3 opened this issue 1 year ago • 2 comments

Hi,

how can i delete a file using the API?

Something along the lines of: curl -X POST "https://metube.local.example.com/delete?file=/downloads/audio/myaudio.ogg"?

(this didn't work)

lfnt3 avatar Dec 08 '24 23:12 lfnt3

This doesn't work either:

curl -X POST "https://metube.local.example.com/delete"
-H "Content-Type: application/json"
-d '{ "ids": ["/downloads/audio/myaudio.ogg"], "where": "done" }'

At least I get a 200 response code with {"status": "ok"}, but the file is not deleted.

The idea above is based on this function in this delete function in /app/main.py:

@routes.post(config.URL_PREFIX + 'delete') async def delete(request): post = await request.json() ids = post.get('ids') where = post.get('where') if not ids or where not in ['queue', 'done']: raise web.HTTPBadRequest() status = await (dqueue.cancel(ids) if where == 'queue' else dqueue.clear(ids)) return web.Response(text=serializer.encode(status))

lfnt3 avatar Dec 09 '24 20:12 lfnt3

Try to get the history from: curl -s -X GET 'https://your.local.metube/history' --header 'Content-Type: application/json'

This will return a JSON similar to: { "done": [ { "id": "partOfTheUrl", "title": "....", "url": "https://www.theurl.com/?p=partOfTheUrl", "quality": "best", "format": "mp3", "folder": null, "custom_name_prefix": "", "msg": null, "percent": 100.0, "speed": null, "eta": null, "status": "finished", "size": 5375677, "timestamp": 1746182276347947839, "error": null, "filename": "...." } ], "queue": [], "pending": [] }

and in my case for the delete call, for the property ids: I sent an array with the value of the urls from the above JSON

Ex. curl -s -X POST 'https://your.local.metube/delete' --header 'Content-Type: application/json' --data "{"where":"done","ids": [ "url" ]}"

lebdim avatar May 02 '25 16:05 lebdim