Python filtering strings -


i´m trying make python script rename subtitles file (.srt) filename of video file corresponding episode, when open in vlc subtitles loaded.

so far i´ve succeeded in getting file names videos , subs strings on 2 separate lists. need somehow pair video string of episode 1 subtitle corresponding same episode.

i´ve tried in lots of differents ways always,most regular patterns, none has worked. here´s example of code :

import glob   videopaths = glob.glob(r"c:\users\tobia_000\desktop\bbt\video\*.mp4") subspaths = glob.glob(r"c:\users\tobia_000\desktop\bbt\subs\*.srt")  #with glob sort filenames of video , subs in separate variables  ep1 = [] ep2 = [] ep3 = [] #etc.. 

this how videopaths , subspaths variables files have. dont have them yet.

videopath = ["the.big.bang.theory.s05e24.hdtv.x264-lol.mp4", "the.big.bang.theory.s05e19.hdtv.x264lol.mp4", "the.big.bang.theory.s05e21.hdtv.x264-lol.mp4"]  subspath = ["the big bang theory - 5x19 - weekend vortex.720p hdtv.lol.en.srt", "the big bang theory - 5x21 - hawking excitation.hdtv.lol.en.srt", "the big bang theory - 5x24 - countdown reflection.hdtv.lol.en.srt"] 

you can use zip make pairs, if sorted lists videopaths , subspaths correct in correspond each other. ie first episode video , subtitles both first element of each list.

episodes = list(zip(videopaths, subspaths)) 

edit: , since glob returns result in arbitrary order, sort before that.

episodes = list(zip(sorted(videopaths), sorted(subspaths))) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -