Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
Handle foreign characters by using unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijs Waalen committed Feb 25, 2012
1 parent 1a15a41 commit db2713d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions default.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys, os
import xbmc, xbmcgui, xbmcplugin
import unicodedata
import urllib

import datetime
Expand Down Expand Up @@ -46,13 +47,14 @@ def remove_duplicates(files):
return list(set(files))

def clean_name(text):
text = text.replace('%21', '!')
text = text.replace('%3a', ':')
text = text.replace('%5c', '\\')
text = text.replace('%2f', '/')
text = text.replace('%2c', ',')
text = text.replace('%5f', '_')
text = text.replace('%20', ' ')
#text = text.replace('%21', '!')
#text = text.replace('%3a', ':')
#text = text.replace('%5c', '\\')
#text = text.replace('%2f', '/')
#text = text.replace('%2c', ',')
#text = text.replace('%5f', '_')
#text = text.replace('%20', ' ')
text = unicode(text, 'utf8')

return text

Expand Down Expand Up @@ -119,7 +121,7 @@ def get_tv_files(show_errors):

try:
episodes = episode_result['result']['episodes']
files.extend([ e['file'] for e in episodes ])
files.extend([ unicode(e['file'], 'utf8') for e in episodes ])
except KeyError:
if show_errors:
xbmcgui.Dialog().ok("ERROR!", "Could not retrieve episodes for %s!" % show_name, "Contact the developer if there actually are episodes!")
Expand Down Expand Up @@ -156,7 +158,7 @@ def file_has_extensions(filename, extensions):

def get_files(path):
results = []
for root, sub_folders, files in os.walk(path):
for root, sub_folders, files in os.walk(unicode(path, 'utf8')):
for f in files:
if file_has_extensions(f, FILE_EXTENSIONS):
f = os.path.join(root, f)
Expand Down Expand Up @@ -221,11 +223,11 @@ def show_movie_submenu():
sub_trailers = []

for item in set_files['result']['files']:
sub_files.append(clean_name(item['file']))
sub_files.append(unicode(item['file'], 'utf8'))
try:
trailer = item['trailer']
if not trailer.startswith('http://'):
library_files.append(clean_name(trailer))
library_files.append(unicode(trailer, 'utf8'))
except KeyError:
pass

Expand All @@ -235,16 +237,16 @@ def show_movie_submenu():
f = f.replace('stack://', '')
parts = f.split(' , ')

parts = [ clean_name(f) for f in parts ]
parts = [ unicode(f, 'utf8') for f in parts ]

for b in parts:
library_files.append(b)
else:
library_files.append(clean_name(f))
library_files.append(unicode(f, 'utf8'))
try:
trailer = m['trailer']
if not trailer.startswith('http://'):
library_files.append(clean_name(trailer))
library_files.append(unicode(trailer, 'utf8'))
except KeyError:
pass

Expand Down

0 comments on commit db2713d

Please sign in to comment.