E
E
Evgeny Petryaev2020-04-22 15:38:26
Python
Evgeny Petryaev, 2020-04-22 15:38:26

Problem with python encoding?

There is a day of victory 2.m3u8 file with reports of the following structure:

Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 2 Федоринов.mp3
Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 3 Сад Пионеров.mp3
Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 4 Шейникова.mp3
Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 5 В землянке.mp3
Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 6 Божко.mp3
Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 7 Чеботарёва.mp3
Z:\Радио\75 лет Победы - 1\75 лет Победы - 1\Сюжет 8 Песчаный лог.mp3

I use this code:
print('hello world!')
from mutagen.mp3 import MP3
ff = open('D:\\git\\Tropic-Island\\Tropic-Island\\Java\\Projects\\Example\\day of victory 2.m3u8', 'r')
array_of_strings = ff.read().split('\n')
ff.close()
ff = open('D:\\git\\Tropic-Island\\Tropic-Island\\Java\\Projects\\Example\\day of victory 3.m3u8','w')
for i in range(len(array_of_strings)):
        f = MP3(array_of_strings[i])
        ff.write(array_of_strings[i]+'\n')
        ff.write(str(f.info.length)+'\n')
ff.close()
print('hello world!')

Gives these errors:
C:\Users\User\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/User/.PyCharmCE2019.1/config/scratches/scratch.py
hello world!
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mutagen\_util.py", line 235, in _openfile
    fileobj = open(filename, "rb+" if writable else "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Z:\\Р\xa0адио\\75 лет Победы - 1\\75 лет Победы - 1\\Сюжет 2 Федоринов.mp3'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/User/.PyCharmCE2019.1/config/scratches/scratch.py", line 8, in <module>
    f = MP3(array_of_strings[i])
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mutagen\_file.py", line 49, in __init__
    self.load(*args, **kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mutagen\_util.py", line 138, in wrapper
    with _openfile(self, filething, filename, fileobj,
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mutagen\_util.py", line 256, in _openfile
    raise MutagenError(e)
mutagen.MutagenError: [Errno 2] No such file or directory: 'Z:\\Р\xa0адио\\75 лет Победы - 1\\75 лет Победы - 1\\Сюжет 2 Федоринов.mp3'

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-04-22
@hottabxp

Resave the day of victory 2.m3u8 file to utf-8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question