Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files with ':' in name fail to download on Windows #266

Closed
jkctech opened this issue Jul 6, 2022 · 5 comments
Closed

Files with ':' in name fail to download on Windows #266

jkctech opened this issue Jul 6, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@jkctech
Copy link

jkctech commented Jul 6, 2022

On Windows, filenames cannot contain the character ':' (Colon).
When running the downloader, all downloads for "video_note" failed since they are named using a date AND a timestamp.
E.g. C:\\telegram_media_downloader\\video_note\\video_note_2022-05-01T11:18:31.mp4

To Reproduce
Run the downloaded under Windows and on a chat with video notes.

Python Version
Python 3.10.2

OS:
Windows 10

Logs

ERROR    [Errno 22] Invalid argument: 'C:\\telegram_media_downloader\\video_note\\video_note_2022-05-04T08:00:05.mp4'                                                                                 client.py:516                    Traceback (most recent call last):
                      File "C:\Program Files\Python310\lib\shutil.py", line 805, in move
                        os.rename(src, real_dst)
                    OSError: [WinError 87] The parameter is incorrect: 'C:\\Users\\Jeffrey\\AppData\\Local\\Temp\\tmpc5mpo93g' ->
                    'C:\\telegram_media_downloader\\video_note\\video_note_2022-05-04T08:00:05.mp4'

                    During handling of the above exception, another exception occurred:

                    Traceback (most recent call last):
                      File "C:\telegram_media_downloader\venv\lib\site-packages\pyrogram\client.py", line 514, in handle_download
                        shutil.move(temp_file_path, final_file_path)
                      File "C:\Program Files\Python310\lib\shutil.py", line 825, in move
                        copy_function(src, real_dst)
                      File "C:\Program Files\Python310\lib\shutil.py", line 434, in copy2
                        copyfile(src, dst, follow_symlinks=follow_symlinks)
                      File "C:\Program Files\Python310\lib\shutil.py", line 256, in copyfile
                        with open(dst, 'wb') as fdst:
                    OSError: [Errno 22] Invalid argument: 'C:\\telegram_media_downloader\\video_note\\video_note_2022-05-04T08:00:05.mp4'

Fix
I managed to "fix" the issue by force, replacing the : character on output filenames to an underscore.
This however broke the complete path under windows since 'C:' gets replaced by 'C_' but it's a quick workaround and proves to me the sole issue is the colon in the filename, but this bug should be handled a little better than I am doing now 🙃

I made the following change in media_downloader.py:

download_path = await client.download_media(
    message, file_name=file_name
)

becomes

download_path = await client.download_media(
    message, file_name=file_name.replace(":","_")
)

(2 changes on lines 188 and 194)

If you want I can make a better fix for this issue and make a PR

@Dineshkarthik
Copy link
Owner

@jkctech thanks for reporting and the clear issue description and fix. Is it possible for you run the same in python 3.9 without your fix and see if the same issue is still happening?
I run unit-tests in GitHub Actions for windows and from 3.6 to 3.9 and all tests passed, i haven't added test for 3.10 so want to confirm it this is related to the Windows 3.10

@Dineshkarthik Dineshkarthik added the bug Something isn't working label Jul 7, 2022
@Dineshkarthik Dineshkarthik added the question Further information is requested label Jul 19, 2022
@Dineshkarthik
Copy link
Owner

@jkctech can you confirm if this issue still exists with the new version of the telegram media downloader?

@Dineshkarthik Dineshkarthik removed the bug Something isn't working label Jul 19, 2022
@jkctech
Copy link
Author

jkctech commented Jul 19, 2022

Hey, sorry for the delay!

I think it has been fixed but I am not 100% sure, I made a fresh install of your software and I am now getting a lot of timeout errors:

85863c300a28ca270c6c79ce3e4a09d9

After completion, I had 55 files that were not downloaded.

After running your program for a second time, using the id's added to the config, to make sure it was not a connection issue, the same 55 files were not downloaded.

I made the change I previously did on the older version as well on this newer one just for a test, (Lines 178 & 193 this time) and the same 55 files are missing so I presume this issue is fixed and I am running into another issue? 😂

I have been trying consistently using a fresh session and fresh install but the same files are missing all the times so I think this issue can be marked as resolved, thankyou for your work 💯

@jkctech
Copy link
Author

jkctech commented Jul 19, 2022

Now I am looking at it, I am missing the folders for voice and video notes and they don't seem to be downloaded at all... It might be that the problem is still somehow relevant and thus these exact files are skipped? They are enabled in the config but no folders showed up while they did on the previous version on the same exact chat

@Dineshkarthik Dineshkarthik added bug Something isn't working and removed question Further information is requested labels Jul 20, 2022
@Dineshkarthik
Copy link
Owner

@jkctech the file download error should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants