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

Error exporting my library #51

Closed
LawnGnome opened this issue Mar 4, 2015 · 4 comments
Closed

Error exporting my library #51

LawnGnome opened this issue Mar 4, 2015 · 4 comments

Comments

@LawnGnome
Copy link

Using 1.4alpha1, I'm getting the following error when I try to export My Library:

16:00:20 T:1722430624   DEBUG: bool CApplication::OnKey(const CKey&): 11 (0x0b) pressed, action is Select
16:00:20 T:1722430624   DEBUG: ------ Window Deinit (DialogContextMenu.xml) ------
16:00:20 T:1722430624   DEBUG: static bool XFILE::CPluginDirectory::RunScriptWithParams(const string&) - calling plugin Google Music EXP('plugin://plugin.audio.googlemusic.exp/','-1','?action=export_library')
16:00:20 T:1900065072  NOTICE: Thread LanguageInvoker start, auto delete: false
16:00:20 T:1900065072    INFO: initializing python engine.
16:00:20 T:1900065072   DEBUG: CPythonInvoker(67, /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py): start processing
16:00:20 T:1900065072  NOTICE: -->Python Interpreter Initialized<--
16:00:20 T:1900065072   DEBUG: CPythonInvoker(67, /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py): the source file to load is "/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py"
16:00:20 T:1900065072   DEBUG: CPythonInvoker(67, /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py): setting the Python path to /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp:/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.decorator/lib:/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.requests/lib:/:/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python26.zip:/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python2.6:/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python2.6/plat-linux3:/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python2.6/lib-tk:/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python2.6/lib-old:/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python2.6/lib-dynload
16:00:20 T:1900065072   DEBUG: CPythonInvoker(67, /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py): entering source directory /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp
16:00:20 T:1900065072   DEBUG: CPythonInvoker(67, /storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py): instantiating addon using automatically obtained id of "plugin.audio.googlemusic.exp" dependent on version 2.1.0 of the xbmc.python api
16:00:20 T:1900065072  NOTICE: [GoogleMusicEXP-1.4~alpha1]  ARGV: ['plugin://plugin.audio.googlemusic.exp/', '-1', '?action=export_library']
16:00:21 T:1900065072   DEBUG: DialogProgress::StartModal called
16:00:21 T:1900065072   DEBUG: ------ Window Init (DialogProgress.xml) ------
16:00:21 T:1900065072   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.UnicodeEncodeError'>
                                            Error Contents: 'ascii' codec can't encode character u'\xe7' in position 121: ordinal not in range(128)
                                            Traceback (most recent call last):
                                              File "/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/default.py", line 18, in <module>
                                                GoogleMusicActions.GoogleMusicActions().executeAction(action, params)
                                              File "/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/GoogleMusicActions.py", line 42, in executeAction
                                                self.exportLibrary(utils.addon.getSetting('export_path'))
                                              File "/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.audio.googlemusic.exp/GoogleMusicActions.py", line 145, in exportLibrary
                                                with open(os.path.join(path,artist,album,str(song[11])+'-'+self._sanitizePath(song[8])+'.strm'), "w") as strm:
                                            UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 121: ordinal not in range(128)
                                            -->End of Python script error report<--

Since I have a few artists and albums in my library that have non-ASCII characters in them (Sigur Rós and f♯a♯∞ being the obvious ones that come to mind), I'm guessing the Python script is choking on one of them.

@LawnGnome
Copy link
Author

Did some experimenting. I can turn one of these into a PR if you want.

Basically, GoogleMusicActions._sanitizePath should return either a properly encoded UTF-8 string (which works great for me on Android, but might fail miserably on Windows — I don't really know anything about how Python and Windows interact on that front) or the lowest common denominator ASCII string. Both options are below.

UTF-8 version

def _sanitizePath(self, name):
    name = "".join(i for i in name if i not in "\/:*?<>|,;$%\"\'.`")
    if len(name) > 50: name = name[:50]
    return name.decode("utf8", "ignore").encode("utf8").strip()

As I said, this works really nicely on Android (and should be fine on Linux), but I don't know how portable this will be.

ASCII version

def _sanitizePath(self, name):
    name = "".join(i for i in name if i not in "\/:*?<>|,;$%\"\'.`")
    if len(name) > 50: name = name[:50]
    return name.decode("utf8", "ignore").encode("ascii", "backslashreplace").replace("\\x", "_x").replace("\\u", "_u").strip()

This results in ugly file names (for instance, Sigur Rós becomes Sigur R_xf3s) but should work everywhere.

@foreverguest
Copy link
Collaborator

Thank you, I'll add your fix for the next version.

@foreverguest
Copy link
Collaborator

Please test this version:
https://app.box.com/s/d0h56sddqomwj46f8amipcebjikpf2w5

@foreverguest
Copy link
Collaborator

closing for inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants