from Tools import Notifications, ASCIItranslit
filename = ASCIItranslit.legacyEncode(filename)
Thanks milo
it did the job partially
def startdownload(self,action='download'):
from tsdownload import startdownload
dlocation=config.plugins.tstube.downloadlocation.value ###download location
success,txt=checkdownloadPath(dlocation) ####check if download path is mounted and exists
if success==False:
self.session.open(MessageBox,txt,MessageBox.TYPE_ERROR)
return
print "movie name before conversion",self.name ##print the name of movie as it is
from Tools import ASCIItranslit
self.name = ASCIItranslit.legacyEncode(self.name)##convert movie name to valid file name
#####add extension to downloaded movie
extension='.mpg' ##if no extesnion add .mpg as extension
if self.url.endswith('.flv'):
extension='.flv'
elif self.url.endswith('.avi'):
extension='.avi'
elif self.url.endswith('.mp4'):
extension='.mp4'
elif self.url.endswith('.mp3'):
extension='.mp3'
title=self.name+extension
print "movie name converted to valid filename",title
if dlocation.endswith('/'):
target= dlocation+self.name
else:
target= dlocation+"/"+self.name
startdownload(self.session,action,self.url,target,title,plugin_path)
movie name before conversion !Women Art Revolution
movie name converted to valid filename !WOMEN_ART_REVOLUTION.flv
movie name before conversion "Du Opfer!" Wenn Gewalt Ein Leben Verändert
movie name converted to valid filename ''DU_OPFER!''_WENN_GEWALT_EIN_LEBEN_VERAENDERT.flv
movie name before conversion Abbott and Costello Meet the Killer, Boris Karloff (1949)
movie name converted to valid filename ABBOTT_AND_COSTELLO_MEET_THE_KILLER,_BORIS_KARLOFF_(1949).avi
movie name before conversion Nahno La Nazraa El Shouk Movie / Ùيلم Ù†ØÙ† لا نزرع الشوك
movie name converted to valid filename NAHNO_LA_NAZRAA_EL_SHOUK_MOVIE_________________________.mpg
as noticed
- capatilize all characters
-convert spaces to _
-replace unicode characters by _
may be good solution to movie containing unacceptable characters in filename but we should also pass only these movie name to the function not all movies
we care not to change movie name because this makes searching for subtitle is difficult
now the typical use for the function should be like this
if validfilename(movie_name)==False: ##the movie_name is invalid for filename
from Tools import ASCIItranslit
final_movie_name = ASCIItranslit.legacyEncode(movie_name)##convert movie name to valid file name
but we have to search for function like validfilename to check for validity of string to use as filename
Edited by mfaraj57, 6 March 2014 - 06:49.