deepjyoti30 / ytmdl

A simple app to get songs from YouTube in mp3 format with artist name, album name etc from sources like iTunes, Spotify, LastFM, Deezer, Gaana etc.
https://ytmdl.deepjyoti30.dev
MIT License
3.22k stars 164 forks source link

"UnicodeEncodeError: 'charmap' codec can't encode character" when trying to download a song. #291

Open SaqinNoor opened 11 months ago

SaqinNoor commented 11 months ago

Bug report

Checklist

Version Info

How Ytmdl was installed?

pip install ytmdl --upgrade

Console Log

User@User MINGW64 ~
$  ==> Searching to see if already present in C:\Users\User\Music
 ==> Searching Youtube for https://music.youtube.com/watch?v=R4wbjdrbDa4
 ==> Choose One (One with [M] is verified music)
 [1] tomorrow tonight by LooteMusic with dur 3:23
 [2] Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Scripts\ytmdl.exe\__main__.py", line 7, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\main.py", line 614, in entry
    extract_data()
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\main.py", line 609, in extract_data
    main(args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\main.py", line 275, in main
    link, yt_title = search(song_name=song_name, args=args)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\core.py", line 63, in search
    choice = song.getChoice(data, 'mp3')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\song.py", line 166, in getChoice
    print_choice(beg, results, SONG_INFO, type)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\song.py", line 98, in print_choice
    print(SONG_INFO[beg]['title'], end='')
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\uff01' in position 21: character maps to <undefined>

Description

UnicodeEncodeError: 'charmap' codec can't encode character '\uff01' in position 21: character maps to when trying to download a song (https://music.youtube.com/watch?v=R4wbjdrbDa4&si=Bgu1QI__9JIyMjG1)

Username replaced with "User" for privacy.

SaqinNoor commented 11 months ago

Windows 11 (64-bit) Python 3.12.1 Git Bash

Tried two songs, both of them return similar errors

User@User MINGW64 ~
$ ytmdl https://music.youtube.com/watch?v=uw9ABw6-gis&si=CV8OFdMd7qtSkHx4
[1] 131

User@User MINGW64 ~
$  ==> Searching to see if already present in C:\Users\User\Music
 ==> Searching Youtube for https://music.youtube.com/watch?v=uw9ABw6-gis
 ==> Choose One (One with [M] is verified music)
 [1] Channel 1 by The Chainsmokers with dur 3:20
 [2] ▒The Chainsmokers - Channel 1 (Nightcore)▒ by Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Scripts\ytmdl.exe\__main__.py", line 7, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\main.py", line 614, in entry
    extract_data()
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\main.py", line 609, in extract_data
    main(args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\main.py", line 275, in main
    link, yt_title = search(song_name=song_name, args=args)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\core.py", line 63, in search
    choice = song.getChoice(data, 'mp3')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\song.py", line 166, in getChoice
    print_choice(beg, results, SONG_INFO, type)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmdl\song.py", line 105, in print_choice
    print(SONG_INFO[beg]['author_name'], end='')
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\colorama\ansitowin32.py", line 210, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: character maps to <undefined>
SaqinNoor commented 10 months ago

Hello? It's been 2 weeks and you've commented on all recent issues except this one. What's wrong man.

deepjyoti30 commented 7 months ago

Hey @SaqinNoor I am not sure why I might have skipped this one earlier but looking back at the issue, I am afraid I might have skipped it because it's an Windows specifc issue. ytmdl has had issues running on windows from the past and I don't have access to a Win machine to reproduce/debug/fix this on my end thus I find it quite hard to debug these issues.

Also, the issue seems specific to the usage of the colorama package which supposedly has good support for Win (one of the reasons I went with it) so I am not sure where to start debugging this.

As an alternative, you could try WSL as multiple users have reported in the past that it works fine for them on there.