The plugins system does not support unicode

Bug #348911 reported by Raa
2
Affects Status Importance Assigned to Milestone
qBittorrent
Fix Released
High
Christophe Dumez

Bug Description

Thank you for a nice program! qBittorrent becomes popular in Russia. And I've decided to write a search plugin for a russian torrent tracker. And I almost did that! But there is a problem with encoding.

It seems like your program does not expect unicode from search plugins. It produces a Python exception when I pass unicode to prettyPrinter():

exceptions.UnicodeEncodeError()
encoding = 'ascii'

Of course there is no errors without python debugger, just empty search result. This is very confusing, because the search script works well with nova2.py.

It would be great if the calling script set the correct default encoding (utf-8 I guess, or the current encodig that you use). May be this example will be helpfull
http://lxj.endofinternet.net/blog/2009/02/encodings-in-python/

The second half of the problem is that it seems your program reads the data returned by the python script as 'ascii' text. So even if I manually do value.encode('utf-8'), this does not help. The script works well, but russian text in the search result is unreadable. It does not seems like russian text. You probably need to work with the received data as with utf-8 text or as text in the current encoding (depending on your plans to support 1-byte encodings, I saw such request here).

Revision history for this message
Raa (lonefeel) wrote :
Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

Could you provide me with your script please? This way I can run some tests of my own and make sure I fix it right.

Revision history for this message
Raa (lonefeel) wrote :

Excuse me pleaese for code. It is not well formed because on the development stage. :-)
You need to register at torrents.ru and insert the login name and password to the script. Please note that the registration works from 6:00 to 8:00 and from 15:00 to 16:00 by Moscow time (+3). So you have to wait about 10 minutes before the registration will be opened today.

http://torrents.ru/forum/profile.php?mode=register

The script is attached

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

I commited a lot of unicode fixes for search engine today. Could you please try svn?
v1_3_x branch.

Please fix your script according to the new guidelines:
# New import
from helpers import retrieve_url
#import urllib is not longer needed
use retrieve_url(url) to get the source code of the url page.

If it works on your side, then I will probably release a bugfix version soon.

Changed in qbittorrent:
assignee: nobody → hydr0g3n
importance: Undecided → High
milestone: none → 1.3.3
status: New → In Progress
Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

I have just made some other search engine fixes today (including one for unicode).

Feedback on your part would be great ;)

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

I will mark this as fixed. Do not hesitate to reopen if you still experience problem with svn. Please also confirm if it works. I'm uploading a screenshot as proof that my search plugins now support russian.

As soon as you confirm, I will release a bugfix version.

Changed in qbittorrent:
status: In Progress → Fix Committed
Revision history for this message
Raa (lonefeel) wrote :

Thank you very much! I will test it asap! Maybe tomorrow. And of course you will be notified.

In my case I can not use retrieve_url() because my favorite torrent tracker requires loggin in. So I have to use urllib2 and cookielib.

There is another small problem. It is not related to this bug, but it is not a bug at all. If I just return a link to the torrent to qBittorrent, it will not work in my case, because the tracker also requires loggin in to download a torrent. (It tracks downloading and uploading such way, and requires anyone to be a seeder, not leecher only). So I will have to create some small kind of proxy for downloading torrents trought... Or you can help me if you provide me with ability to write not only method search() but also method get_torrent(). So if I do not return filed "link", but return "id", then qBittorrent get the torents file by calling get_torrent(id) instead of doing an http request itself. What do you thing? Is it easy?

Revision history for this message
Raa (lonefeel) wrote :

The screenshot looks very nice! There is really russian text in the search result :-)

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

Ok. I'm on it. I'm will try to finish this by tomorrow.

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

Ok. I commited a big patch to svn :) Thanks for the idea. qBittorrent search engine plugin system is much more flexible that way.

You should add a "download_torrent(self, id)" method to your engine plugin class which downloads the torrent and prints "file_path torrent_url" (separated by a space).

Please have a look at download_file() from helpers.py and download_torrent() from my plugins for more information.

Revision history for this message
Raa (lonefeel) wrote :

Hi Chris!

I was trying to compile libtorrent entire day, and finally finished with success! There was a problem with autoheader. It seems libtorrent requires autoheader 2.60 or above, but 2.59 is the highest on Debian.

But unfortunately I can not compile qbittorrent.

$ make
cd src/ && make -f Makefile
make[1]: Entering directory `/home/raa/distrib/linux/internet/qbittorrent/v1_3_x/src'
g++ -c -pipe -O2 -DTORRENT_USE_OPENSSL -DTORRENT_LINKING_SHARED -g -O2 -DHAVE_SSL -I/usr/include/libtorrent -I/usr/include/openssl -D_REENTRANT -Wall -W -DVERSION=\"v1.3.3\" -DVERSION_MAJOR=1 -DVERSION_MINOR=3 -DVERSION_BUGFIX=3 -DQT_NO_DEBUG_OUTPUT -DQT_4_4 -DHAVE_ZZIP -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtXml -I/usr/include/qt4/QtXml -I/usr/include/qt4 -I/usr/include -I/usr/include/libtorrent -I/usr/include -I/usr/include -I/usr/include -I/usr/X11R6/include -I. -I. -o searchEngine.o searchEngine.cpp
searchEngine.cpp: In member function 'void SearchEngine::downloadFinished(int, QProcess::ExitStatus)':
searchEngine.cpp:256: error: 'class QStringList' has no member named 'length'
make[1]: *** [searchEngine.o] Error 1
make[1]: Leaving directory `/home/raa/distrib/linux/internet/qbittorrent/v1_3_x/src'
make: *** [sub-src-make_default] Error 2

How to fix this?

Revision history for this message
Raa (lonefeel) wrote :

Those error occured because I have qt4.4.3. I just replaced length() with size() and this resolved the problem. Testing now.

Revision history for this message
Raa (lonefeel) wrote :

I have finished testing. It seems the program works well with unicode now.

download_torrent() works well too. There is only small bug: download_torrent() receives empty url when the search result is ordered by size.

I also reviwed download_file() from helpers.py. I can not use it, because it does not support authentication. So I just copied the code of function and replaced urllib2.urlopen() with opener.open()

The latest version of my search script is attached.

I have another small problem. Could you please advise? As I told many times, my favorite torrent tracker requies authentication to track the downloads/uploads rate. So I need to save login and password somewhere. It is hardcoded right now. But it is not user friendly. It may be very hard for some users to understand how they should set their passwords. Do you have any ideas?

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

I have just fixed sorting problem in svn. Thanks for the report ;)

Regarding the authentication problem. I guess hardcoding is the best way for now. Most scripts do not require authentication. Handling credentials on qBittorrent's part would mean quite a lot of recoding and I don't think this is a priority for now.

Revision history for this message
Raa (lonefeel) wrote :

ok! Thank you very much!

I will write to my blog about your great program :-)

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

v1.3.3 is out :)

Changed in qbittorrent:
status: Fix Committed → Fix Released
Revision history for this message
Raa (lonefeel) wrote :

Great! Thank you! :)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.