2013-02-17, 20:56
2013-04-19, 15:21
(2013-02-17, 20:45)kinetik Wrote: Corrected all my initial naming mistakes, 3 left because they have a ? or : which are not allowed in file name, so I had to name those manually with the year and episode number.
The three that have those characters:
NOT FOUND Operation Rabbit
NOT FOUND What's Up Doc
NOT FOUND What's Opera, Doc
1: Copy past the TheTVDB data to a Google spreadsheet. I left just the Name and Number columns.
2: Export the data to a csv file.
3: Run this script.
Code:param ($Source, $EpisodeDataFile)
$EpisodeData = Import-Csv $EpisodeDataFile
$Files = Get-ChildItem $Source -recurse -include *.m4v
foreach ($File in $Files){
if ($File.Name -match "d(\d+)e(\d+) (.*).m4v"){
$NameMatches = $Matches
$Episode = $EpisodeData | Where-Object Name -eq $NameMatches[3]
if ($Episode){
#Write-Host "FOUND" $NameMatches[3]
#$Episode.Number
if ($Episode.Number -match "(\d+) x (\d+)"){
$NewFileName = "Looney Tunes s$($Matches[1])e$($Matches[2]) $($NameMatches[3]).m4v"
Write-Host "FOUND" $NewFileName
Rename-Item $File $NewFileName
}
}
else {
Write-Host "NOT FOUND" $NameMatches[3]
}
}
}
Trying to run your script, I get this error:
"Import-Csv : Cannot bind argument to parameter 'Path' because it is null."
Can you provide any help, or maybe some detailed instructions?
Thanks!
2013-05-19, 01:02
(2013-02-17, 20:45)kinetik Wrote: Corrected all my initial naming mistakes, 3 left because they have a ? or : which are not allowed in file name, so I had to name those manually with the year and episode number.
The three that have those characters:
NOT FOUND Operation Rabbit
NOT FOUND What's Up Doc
NOT FOUND What's Opera, Doc
1: Copy past the TheTVDB data to a Google spreadsheet. I left just the Name and Number columns.
2: Export the data to a csv file.
3: Run this script.
Code:param ($Source, $EpisodeDataFile)
$EpisodeData = Import-Csv $EpisodeDataFile
$Files = Get-ChildItem $Source -recurse -include *.m4v
foreach ($File in $Files){
if ($File.Name -match "d(\d+)e(\d+) (.*).m4v"){
$NameMatches = $Matches
$Episode = $EpisodeData | Where-Object Name -eq $NameMatches[3]
if ($Episode){
#Write-Host "FOUND" $NameMatches[3]
#$Episode.Number
if ($Episode.Number -match "(\d+) x (\d+)"){
$NewFileName = "Looney Tunes s$($Matches[1])e$($Matches[2]) $($NameMatches[3]).m4v"
Write-Host "FOUND" $NewFileName
Rename-Item $File $NewFileName
}
}
else {
Write-Host "NOT FOUND" $NameMatches[3]
}
}
}
How/Where do you run this script?
2013-05-22, 06:27
Would you believe it has been over a year since I posted in this thread, and yet until today my Looney Tunes directory remained unchanged? I recently have been teaching myself how to program in Python (hoping to contribute to XBMC in the form of addons, sreensavers, etc) and thought this would be a perfect place to try my new skills. This is nothing fancy, but it should get the job done assuming your files are of a similar naming scheme to mine.
This script will rename your files from BlahBlah – YadaYada Baseball Bugs Blah.avi to the TVDB standard of Looney Tunes S1946E02 Baseball Bugs.avi. The script can also move the files from your existing directory (for example C:\Looney Tunes\rename\) to your normal directory (for example C:\Looney Tunes\) and automatically create season folders if they do not exist yet (C:\Looney Tunes\Season 1946\).
What you need:
What you need to do:
As said before, this worked quite well for renaming the bulk of my episodes. Good luck and hope it helps someone else!
Please backup your files before using this script! I have had no problems, but better safe than sorry!
This script will rename your files from BlahBlah – YadaYada Baseball Bugs Blah.avi to the TVDB standard of Looney Tunes S1946E02 Baseball Bugs.avi. The script can also move the files from your existing directory (for example C:\Looney Tunes\rename\) to your normal directory (for example C:\Looney Tunes\) and automatically create season folders if they do not exist yet (C:\Looney Tunes\Season 1946\).
What you need:
- Python 2.7.5 from this URL: http://www.python.org/download/
- Python script from below in this thread (Save to a text file and rename the file extension from .txt to .py)
- Create a CSV by copying the episode list from the TVDB into Excel or Google Docs and save as CSV. No modifications are needed. Please see the example here for how your CSV file should look like.
- Filenames must contain the complete episode titles that match the TVDB CSV you created. This means that if your episode titles are separated by underscores (Baseball_Bugs.avi) then you are out of luck for now. The titles are not case sensitive, and the script will ignore unsafe filename characters when searching (?*<>|/\":). Of course if the episode title is misspelled then the script will not rename the file. Files that do not match the CSV will not be harmed. I had to manually rename about 15 files or so, but that’s not bad out of nearly 400!
What you need to do:
- Make a copy of your original Looney Tunes folder. Always good to start by making a backup! I renamed my folder from ‘Looney Tunes’ to ‘lt’ to make it easier to type.
- Move all the episodes into one folder (the script does not scan multiple or recursive folders) for easier renaming.
- Double click on the python file you downloaded from this thread.
- You will be prompted for the series name. In this case: Looney Tunes
- Enter the path to the CSV you downloaded from this thread. For example: C:\download\lt.csv
- Enter the path to your COPY of the episodes (to be safe). For example: C:\lt\disc1\*
- If you want to move the files while renaming (useful for the 300+ episodes in the Looney Tunes Golden Collection!) type "y" or "yes"
- If you chose to rename your files, enter the path to your normal show directory For example C:\Looney Tunes\
- Done!
As said before, this worked quite well for renaming the bulk of my episodes. Good luck and hope it helps someone else!
Please backup your files before using this script! I have had no problems, but better safe than sorry!
Code:
# Episode Name - File Renamer
# Renames files without accurate episode order using the Episode Name only
# Coded by: Tim.
# Import modules
import os
import glob
import csv
# Assign inital values
repeat = "true"
edit = "true"
#Define custom functions
def invalid_char(s):
"""
Strip the invalid filename characters from the string selected.
Feel free to add/remove additional .replace(X,X) as needed if you
want to remove other characters even if they are valid.
For example: , or [ or !
"""
return s.replace("?","").replace(":","").replace("*","").replace("<","").replace(">","").replace("|","").replace("/","").replace("\\","").replace('"',"")
def season(l):
"""
Takes the first cell of the CSV copied from the TVDB website
and strips out only the season.
"""
if l == "Special":
season = "00"
else:
season = l.split(" ")[0].zfill(2)
return season
def episode(l):
"""
Takes the first cell of the CSV copied from the TVDB website
and strips out only the episode. Pads a 0 before single digits.
"""
if l == "Special":
episode = "00"
else:
episode = l.split(" ")[-1].zfill(2)
return episode
# Overall loop, allows user to re-run the entire script
while repeat == "true":
# Checks if the user defined variables need to be edited
if edit == "true":
# Prompt user to define static variables
series_name = raw_input("Please enter your series name: ")
#series_name = "Charlie Brown"
print "\n"
data = raw_input("Path to CSV: ")
#data = "C:\lt\cb.csv"
print "\n"
dir1 = raw_input("Path to episodes (format C:\*): ")
#dir1 = "M:\TV Shows\CB\all\*"
print "\n"
move = raw_input("Would you like to move renamed files? (Yes/No): ").lower()
if move in ("y", "ye", "yes"):
print "\n"
print "Enter path to root folder where files should be moved"
move_path = raw_input("and season folders will be created (format C:\Show\): ")
edit = "false"
file_list = glob.glob(dir1)
print ("\n\n")
# Loop through file_list and look for matches in the CSV to the filename after the prefix assigned
for file in file_list:
fname = file
ext = fname[-4:]
with open(data, 'r') as file:
reader = csv.reader(file)
season_episode_name = ["S" + season(line[0]) + "E" + episode(line[0]) + " " + invalid_char(line[1]) for line in reader if invalid_char(line[1].lower()) in fname.lower() and line[1].lower() != ""]
season_dir = (''.join(season_episode_name)).split("E")[0][1:]
if season_episode_name:
season_episode_name = ''.join(season_episode_name)
fname2 = dir1[:-1] + series_name + " " + season_episode_name + ext
# If user chose to move files to another directory, then fname2 has the path replaced
if move in ("y", "ye", "yes"):
fname2 = move_path + "Season " + season_dir + "\\" + fname2[len(dir1[:-1]):]
# Generates the season directory if does not already exist
if not os.path.exists(move_path + "Season " + season_dir):
os.makedirs(move_path + "Season " + season_dir)
# Rename file and move if user requested
print fname + "\n >>> " + fname2 + "\n"
os.rename(fname, fname2)
else:
print fname + "\n >>> " "Unable to locate match, please rename manually.\n"
# Check if user wants to repeat, edit or exit
repeat = raw_input ("\n\nType R to run again, Type E to edit the parameters, or Q to quit: ")
if repeat.lower() in ("r", "retry"):
repeat = "true"
print "\nRunning again with the same parameters.."
elif repeat.lower() in ("e", "edit"):
edit = "true"
repeat = "true"
print "\nEditing paramaters before running again.."
elif repeat.lower() in ("q", "quit"):
repeat = "false"
print "\nQuitting..."
else:
repeat = "false"
print "\nInvalid command."
# When repeat no longer is "true" the script exiits with the below message
else:
raw_input("\n\nPress enter to exit...")
2013-05-24, 00:10
I'm about to dive into trying to do this, BUT since it seems as if you are handy at scripting, would it be possible for you to write a script that would essentially map the downloaded file names to the CSV and create a custom .nfo file for scraping, thus removing the need to modify any files/run a script?
Just thinking out side the box.
Just thinking out side the box.
2013-05-24, 00:46
Imported, if I understand what you are asking for, you want to create custom nfo files that point to the correct episodes in the TVDB but without renaming the files themselves? I would not suggest that, as for having the best compatibility with XBMC it would be better to have the proper naming structure for future-proofed scraping. The script I created will do just that, assuming you have the full title (case sensitive!) of each episode in your filename.
In order to do what you suggest, you would still need a script to run through the files, create new files (.nfo), and determine the correct URL for each episode. As said, it is best to focus on fixing the filenames of your content. That way you'll always be able to scrape it, even if you switch software/platforms. That's my opinion anyway.
If you do decide to give my script a shot let me know how it works out!
EDIT: Looks like you posted to disregard as I was posting :-). Oh well, good info regardless!
In order to do what you suggest, you would still need a script to run through the files, create new files (.nfo), and determine the correct URL for each episode. As said, it is best to focus on fixing the filenames of your content. That way you'll always be able to scrape it, even if you switch software/platforms. That's my opinion anyway.
If you do decide to give my script a shot let me know how it works out!
EDIT: Looks like you posted to disregard as I was posting :-). Oh well, good info regardless!
2013-05-24, 01:38
I can't say that this will work for the looney tunes episodes, but it does work for Jeopardy! episodes. Their naming convention is all out of whack, and I fiddled with different options until I found one that would work. I am not at home, so this is from memory but I think it went like this.
Jeopardy.3.25.2010.mkv
That is a hypothetical date, but I am pretty sure of that format. If I find it to be different when I get home I will correct it. Based on the format I saw on the TVDB for the looney tunes shorts, I suspect it will work the same. And I feel your pain on the manual renaming. If you folks aren't familiar with a tool named "Batch Renamer" again from memory, go check it out. It is very handy for helping in the task you are facing. While it can't automate it completely, it can assist.
Hope this helps.
Jeopardy.3.25.2010.mkv
That is a hypothetical date, but I am pretty sure of that format. If I find it to be different when I get home I will correct it. Based on the format I saw on the TVDB for the looney tunes shorts, I suspect it will work the same. And I feel your pain on the manual renaming. If you folks aren't familiar with a tool named "Batch Renamer" again from memory, go check it out. It is very handy for helping in the task you are facing. While it can't automate it completely, it can assist.
Hope this helps.
2013-05-24, 07:11
(2013-05-24, 00:46)Tim. Wrote: Imported, if I understand what you are asking for, you want to create custom nfo files that point to the correct episodes in the TVDB but without renaming the files themselves? I would not suggest that, as for having the best compatibility with XBMC it would be better to have the proper naming structure for future-proofed scraping. The script I created will do just that, assuming you have the full title (case sensitive!) of each episode in your filename.
In order to do what you suggest, you would still need a script to run through the files, create new files (.nfo), and determine the correct URL for each episode. As said, it is best to focus on fixing the filenames of your content. That way you'll always be able to scrape it, even if you switch software/platforms. That's my opinion anyway.
If you do decide to give my script a shot let me know how it works out!
EDIT: Looks like you posted to disregard as I was posting :-). Oh well, good info regardless!
Tim, i did try your script....... it took me a little bit of figuring out since it was my first time using Python, but i did eventually get it to run! I did however have to manually rename about 100 episodes, but out of the 404 that i had, i was thankful for the script...
Truth be told even though i was renaming them i didn't manually add the season and episode numbers, i just made the names match and then ran your script against it.. Once everything was done i ran them through "The Renamer" and it all worked flawlessly.
I've had this collection for about two years and not my family can enjoy it thanks to your script, so THANK YOU TIM.
(2013-05-24, 01:38)Diggs Wrote: I can't say that this will work for the looney tunes episodes, but it does work for Jeopardy! episodes. Their naming convention is all out of whack, and I fiddled with different options until I found one that would work. I am not at home, so this is from memory but I think it went like this.
Jeopardy.3.25.2010.mkv
That is a hypothetical date, but I am pretty sure of that format. If I find it to be different when I get home I will correct it. Based on the format I saw on the TVDB for the looney tunes shorts, I suspect it will work the same. And I feel your pain on the manual renaming. If you folks aren't familiar with a tool named "Batch Renamer" again from memory, go check it out. It is very handy for helping in the task you are facing. While it can't automate it completely, it can assist.
Hope this helps.
Diggs, i use a tool called "Bulk Rename Utility". I actually used this to remove any characters prior to the name (01 - ) so that i could just use the value of 0 in Tim's script.
Tim, your script has A LOT of potential.. if you're ever open to a feature request list here are a few:
- Automatically get the csv data from theTVDB based on show name or ID (kind of like the manual scraping in The Renamer works)
- Make it not be case sensitive (this was a majority of my issues (of not Of and The not the), along with differences in where a dash ( - ) was placed
- disregard characters in the CSV that are not able to be used in file names, like question marks)
- Add the ability/option to scan through sub folders
- And above all else, add the option at the end of:
Press " R " to RESCAN using the previously defined parameters, " E " to EDIT Parameters prior to rerunning, or " Q " to QUIT.
I think R & E above are self explanatory requests
Also your CSV file did not include Season 0 (Specials), but there were only a hand full of those.
This is the ONLY thing i found thus far that has allowed me to do any type of matching/renaming/scraping based on episode names.
I have a few other series i might try this with, although it will also be a few min process to make the CSV for those series. I agree that it is the proper way to to do it (as far as programming goes), but creating the CSV is now a little more involved.
A few notes to anyone else trying to use this script:
- Install Python BEFORE anything else. I had made my .py file in notepade and then assoiated notepad with ,py files on my subsequent opening of it. I couldnt figgure out how to "run the script" In short, if your douple click your .py file and it doesnt run in python, (in windows) right click on it, select "Open With" and then find the python.exe file.
- AFTER YOU MAKE A BACKUP, copy all of the episodes into a single folder as this script (as it stands) does not search recursively.
- If you think you already have a CSV file of the episodes, STOP and download the one Tim provided. It is different than any other provided in this thread and the key to this all working properly.
- If you are running this against The Looney Tunes Golden Collection that you might have downloaded, then shame on you go buy it , but know that there are quite a few files that you will never get named from any tool that uses theTVDB because they do not list exclusive DVD features/episodes in their DB. My hack solution was to prefix all of those with S00E00 so that they show up in the specials folder under the series in XBMC.
Also there are at least 5 episodes that are not Looney Tunes. According to theTVDB these are episodes of "The Captain and the Kids" series. The files included in the golden collection that belong to this other series are:- S01E03 Poultry Pirates
- S01E05 A Day at the Beach
- S01E12 The Captains Christmas
- S01E14 Seal Skinners
- S01E15 Mamas New Hat
- S01E03 Poultry Pirates
2013-05-24, 19:25
Imported, I'm glad to hear the script was helpful for you! I went ahead and made some modifications to it. It is no longer case-sensitive when comparing your episode name to the name in the CSV file. It retains your original file's format, however. If your episode was "D02E11 - Boobs in the Woods.avi" it would retain the lower-case "in" and "the," even though they are capitalized in the CSV. Also, as you requested, you now have retry, edit and quit options at the end of each run. I have modified the original post here with the new code.
Maybe create a few text files with episode names as the file names and test it out? Please let me know what you think!
Maybe create a few text files with episode names as the file names and test it out? Please let me know what you think!
2013-05-27, 21:22
Updated script once again. This time added move support. For example:
C:\Looney Tunes\rename\Looney Tunes d01e01 - Baseball Bugs.avi can be renamed and moved to C:\Looney Tunes\Season 1946\Looney Tunes S1946E02 Baseball Bugs.avi
If the "Season 19xx" directory does not exist, the script create one. Useful, as the collection includes 30+ season folders.
Get the latest version in the original post.
C:\Looney Tunes\rename\Looney Tunes d01e01 - Baseball Bugs.avi can be renamed and moved to C:\Looney Tunes\Season 1946\Looney Tunes S1946E02 Baseball Bugs.avi
If the "Season 19xx" directory does not exist, the script create one. Useful, as the collection includes 30+ season folders.
Get the latest version in the original post.
2013-06-02, 06:57
Major updates to my little script over the past day or so make it far more useful!
- No longer requires a specially modified CSV. Previously you had to copy the episode list from the TVDB and then modify it for this script to work. Now simply copying the episode list and saving as a CSV will work directly. Should make the script more easy to use, and more useful.
- Now the filename can contain anything before and after the episode title. For example: Blah-Episode Title_YadaYada.avi No longer requires a standard number of characters before the episode title. Previously if one episode was titled Blah-Episode.avi and the next BlahBlah-Episode.avi you would have to run the script twice and manually define the length of characters before the episode title (in this example 5 and then 9).
- Ignores unsafe filename characters (?*<>|/\":) when comparing episode titles against the CSV. This means episodes like What’s Up, Doc? Will be found and renamed without the "?" This managed to rename quite a few more files that the older version missed.
2013-06-04, 00:15
Tim.,
Thanks for all your effort! You rock!
I'm looking forward to my kiddos getting to know these great 'toons!
Thanks for all your effort! You rock!
I'm looking forward to my kiddos getting to know these great 'toons!
2013-06-04, 05:56
jaydash,
Thanks for the encouragment! Let me know if my script works out for you.
I've made a few minor updates today:
I tested my script on my "Charlie Brown" collection and it renamed all my files except for 2 with typos! At this point the script should work effectively on any series, not just Looney Tunes.
Grab the latest version in the original post!
Thanks for the encouragment! Let me know if my script works out for you.
I've made a few minor updates today:
- Added protection to avoid strange behavior when there are blank titles in the CSV. (A row in the CSV with an Season/Episode number, but no title in the second column.).
- If the CSV you generate includes inline specials (Season 00 episodes that show up in a normal season), they are only labeled as "Special". The script now takes these episodes when found and names them correctly. The CSV does not include the episode number, however, so all the inline specials will show up as Show_Name S00E00 Episode_Name.avi and will be moved to the directory "Season 00" when you use the move files option. You will have to go and manually change the episode number from 00 to the correct number. Alternatively, you could modify the CSV and replace "Special" entries with the correct format ("0 x 1" for Season 0 Episode 1).
I tested my script on my "Charlie Brown" collection and it renamed all my files except for 2 with typos! At this point the script should work effectively on any series, not just Looney Tunes.
Grab the latest version in the original post!
2013-06-12, 06:04
Ok Tim, I am about to test this out on my Beavis & Butthead Season 0 content..... I will let you know how it goes. I many not get back to you tonight.