odwyersoftware / mega.py

Python library for the https://mega.nz/ API.
https://github.com/odwyersoftware/mega.py
Apache License 2.0
349 stars 170 forks source link

Rename issue #65

Open maciejbak85 opened 3 years ago

maciejbak85 commented 3 years ago

hi,

thanks for this library! I wanted to ask what I am doing wrong, or maybe there is some bug:

files = m.get_files()

for file in files:
    file_details = files[file]
    file_name = str(file_details['a']['n'])
    if (file_name.endswith(".mp4")):
        date_time = time.strftime(
            ' %Y-%m-%d', time.localtime(file_details['ts']))
        new_name = str(file_details['ts']) + "_" + file_name
        print(file_details['k'])
        m.rename(file, new_name)

gives me:

(4095499236, 4227643941, 3790350449, 3961640328)
Traceback (most recent call last):
  File "/home/abc/Dev/xyz/MegaVideosRename/main.py", line 22, in <module>
    m.rename(file, new_name)
  File "/home/abc/Dev/xyz/MegaVideosRename/environments/my_env/lib/python3.8/site-packages/mega/mega.py", line 906, in rename
    encrypt_attribs = base64_url_encode(encrypt_attr(attribs, file['k']))
TypeError: string indices must be integers

any idea why ? looks like under 'k' there are integers..

maciejbak85 commented 3 years ago

btw.

files = m.get_files()

for file in files:
    file_details = files[file]
    # print(file_details)
    file_name = str(file_details['a']['n'])
    if (file_name.endswith(".mp4")):
        date_time = time.strftime(
            ' %Y-%m-%d', time.localtime(file_details['ts']))
        new_name = str(file_details['ts']) + "_" + file_name
        found_file = m.find(file_name)
        m.rename(found_file, new_name)

this works fine, I have to find it again, not from the list.