mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-23 01:40:08 +00:00
Fix renaming files in add torrent dialog
This commit is contained in:
parent
8bafc9f966
commit
f21dd242f6
@ -4,6 +4,7 @@
|
||||
* Implement #457 progress bars for folders
|
||||
* Implement #1012 httpdownloader supports gzip decoding
|
||||
* #496: Remove deprecated functions in favour of get_session_status()
|
||||
* #1112: Fix renaming files in add torrent dialog
|
||||
|
||||
==== Blocklist ====
|
||||
* Implement local blocklist support
|
||||
|
@ -41,7 +41,6 @@ import os
|
||||
import time
|
||||
import shutil
|
||||
import operator
|
||||
import locale
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.task import LoopingCall
|
||||
@ -57,6 +56,7 @@ from deluge.configmanager import ConfigManager, get_config_dir
|
||||
from deluge.core.torrent import Torrent
|
||||
from deluge.core.torrent import TorrentOptions
|
||||
import deluge.core.oldstateupgrader
|
||||
from deluge.ui.common import utf8_encoded
|
||||
|
||||
from deluge.log import LOG as log
|
||||
|
||||
@ -388,8 +388,7 @@ class TorrentManager(component.Component):
|
||||
if options["mapped_files"]:
|
||||
for index, name in options["mapped_files"].items():
|
||||
log.debug("renaming file index %s to %s", index, name)
|
||||
torrent_info.rename_file(index,
|
||||
name.encode("utf-8").decode(locale.getpreferredencoding(), "ignore"))
|
||||
torrent_info.rename_file(index, utf8_encoded(name))
|
||||
|
||||
add_torrent_params["ti"] = torrent_info
|
||||
add_torrent_params["resume_data"] = ""
|
||||
@ -403,14 +402,8 @@ class TorrentManager(component.Component):
|
||||
else:
|
||||
storage_mode = lt.storage_mode_t(1)
|
||||
|
||||
try:
|
||||
# Try to encode this as utf8 if needed
|
||||
options["download_location"] = options["download_location"].encode("utf8")
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
# Fill in the rest of the add_torrent_params dictionary
|
||||
add_torrent_params["save_path"] = options["download_location"]
|
||||
add_torrent_params["save_path"] = utf8_encoded(options["download_location"])
|
||||
add_torrent_params["storage_mode"] = storage_mode
|
||||
add_torrent_params["paused"] = True
|
||||
add_torrent_params["auto_managed"] = False
|
||||
|
@ -43,6 +43,7 @@ import sys
|
||||
import urlparse
|
||||
|
||||
import chardet
|
||||
import locale
|
||||
|
||||
try:
|
||||
from hashlib import sha1 as sha
|
||||
@ -67,9 +68,25 @@ def decode_string(s, encoding="utf8"):
|
||||
"""
|
||||
|
||||
try:
|
||||
s = s.decode(encoding).encode("utf8")
|
||||
s = s.decode(encoding).encode("utf8", "ignore")
|
||||
except UnicodeDecodeError:
|
||||
s = s.decode(chardet.detect(s)["encoding"]).encode("utf8")
|
||||
s = s.decode(chardet.detect(s)["encoding"], "ignore").encode("utf8", "ignore")
|
||||
return s
|
||||
|
||||
def utf8_encoded(s):
|
||||
"""
|
||||
Returns a utf8 encoded string of s
|
||||
|
||||
:param s: (unicode) string to (re-)encode
|
||||
:type s: basestring
|
||||
:returns: a utf8 encoded string of s
|
||||
:rtype: str
|
||||
|
||||
"""
|
||||
if isinstance(s, str):
|
||||
s = decode_string(s, locale.getpreferredencoding())
|
||||
elif isinstance(s, unicode):
|
||||
s = s.encode("utf8", "ignore")
|
||||
return s
|
||||
|
||||
class TorrentInfo(object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user