0

I'd like to upload an mp3 file from hotfolder without knowing the name of the file. (such as *.mp3)

here's what I tried (to upload specific file / known file name)

    import soundcloud

# create client object with app and user credentials
    client = soundcloud.Client(client_id='***',
    client_secret='***',
    username='***',
    password='***')

# print authenticated user's username
    print client.get('/me').username

    mp3_file=('test.mp3')

# upload audio file
    track = client.post('/tracks', track={
    'title': 'Test Sound',
    'asset_data': open(mp3_file, 'rb')

    })

# print track link
    print track.permalink_url

how can I make the script upload any mp3 file in that folder ? (script and files are located in the same folder)

Mak K
  • 1
  • 1

1 Answers1

0

From the language as written here, it's not precisely clear what you mean by "upload any mp3 file in that folder." Does uploading the first file in the folder satisfy your need, or does it need to be a different file each time the script executes? If the latter, my suggestion is to get a list of files and then randomly select one of them.

To get a list of all files in python,

from os import listdir
from os.path import isfile, join

onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]

and then to randomly select one of them:

import random

print(random.choice(onlyfiles))

Hope this helps

Community
  • 1
  • 1
rodamn
  • 2,191
  • 19
  • 24