If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

App renames your tvshow and copies it to custom folder

fhbfhb Posts: 362Members, Plex Pass Plex Pass
edited September 2012 in General (Third-Party Development)
RenameandMove

testx.jpg

Please give me your valuable feedback.

What it does

This tool renames every tv show episode which is dropped on it to Show Name.S##E##.episode title.ext (standard) or Show.name.S##E##.episode.title.ext and moves it to a specified folder creating the plex-typical subdirectorys if necessary (userpath/Showname/Season #). The episodetitle is from thetvdb.com

Conditions

The file must have one of the following naming patterns:

****.Show Name.S##E##.*****.anyfileextension


Show.Name.S##E##.******.anyfileextension


Show Name - S##E## - ******.anyfileextension


**** can be anything.

Customization

  • Use Automator
  • Edit the userpath in the first applescript snippet
  • If you want the words to be separated by dots rather than spaces use the setting variables at the beginning of the last applescript snippet:
  • set episodentitelwordsdividedbydots to true
    set shownamewordsdividedbydots to true
    

  • If you want to change the language replace en.xml, for a list click here




Edits

edit: new version correcting a small bug leading to an unnecessary blank right before the title. Problems should be fixed.
edit2: if the subfolders showname and showname/Season X do not exist, RenameandCopy will now create them.
edit3: shownames with more than one word and separated with a dot instead of a blank (worked before) are handled correctly now
edit4: titles containing words completely consisting of numbers should be added properly
edit5: If you want to copy episodes to your local hard drive called "Macintosh HD" it will work now (If you gave your drive another name you must rename it in the last code snippet.). The userpath appeared two times instead of once and there is now only one place where you have to edit the given path to the correct one.
edit6: 2. RenameandCopy capitalizes sXXeYY => SXXEYY and every first letter of every word in the showname
edit7: The first letter of a word is always capitalized, "and" & "a" are not, (messed with "Two and a Half Men", if you want to request additional changes please request them,if you don't need capitalization download copy number 1, it's not supported anymore so future edits won't have an effect on this version.
edit8 (2.03.2011) 0.9.1:
  • The App is called RenameandMove as it now uses the move function.
  • The App can now cope with every file extension (avi, mkv ...).
  • The messages are in English
  • If the file is already in the correct directory only the title will be added.
  • RenameandMove now supports dividing the words of the showname or of the episodetitel by dots. Please tell me if this is also needed for the Shownamefolder and the Season folders (How.I.Met.Your.Mother/Season.1/How.I.Met.Your.Mother.S01E01.Titel.exists.avi). You have to activate the two variables in the last applescript snippet:
  • set episodentitelwordsdividedbydots to true
    set shownamewordsdividedbydots to true
    

  • Versioning is introduced

edit9: 0.9.2 supports
Show Name - S##E## - ******.anyfileextension
«1

Comments

  • sansnipplesansnipple Posts: 1,151Members
    not sure why you'd need to add the episode title to the file name at all though, plex scrapes the title and lots more from tvdb as long as you have S##E##.
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    edited May 2010
    thats right, but some people do prefer them to be part of the filename as well. You could easily delete that function from the script if you want to.
    gn8 :)
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    Updated the file, should run without problems now.
  • JayBirdJayBird Posts: 360Members ✭✭
    edited May 2010
    EDIT
    Mac Mini 2.0Ghz | 17" i5 MacBook Pro | iPhone 4 | iPad 16GB Wi-Fi | Apple TV 2
  • PlexLarsPlexLars Posts: 310Members ✭✭
    fhb wrote on 09 May 2010 - 03:37 AM:

    thats right, but some people do prefer them to be part of the filename as well. You could easily delete that function from the script if you want to.
    gn8 :)

    I´m one of those :)
    I´m not experianced with Automator and therefore struggling a bit. I´m trying to change the destination path:

    set pfad to "/Users/larsj/Movies/RenameandCopy" & Gilmore Girls & "/Season 7" & season & "/"

    Whats wrong?
    Mac Mini // Drobo-FS // Panasonic // Harman Kardon // Dali
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    edited July 2010
    Glad I'm not the only one :)
    The script gets the showname, episode and season from the given file.

    If your files are named this way: Gilmore Girls.SXXEYY.nowcomewhatmay.avi it should work fine with this line of code:
    set pfad to "/Users/larsj/Movies/" & showname & "/Season " & season & "/"
    
    , if you want to save your file(s) in
    "/Users/larsj/Movies/Gilmore Girls/Season XX/Gilmore Girls.SXX.EYY.titlefromthetvdb.org.avi"
    

    showname and season are variables.

    Problems occur if the folders do not exist. You should manually create /Users/larsj/Movies/Gilmore Girls/Season XX

    You can debug the script by adding "Add given finder objects" (rough translation from german) at the beginning and select the file you want to test. You can now look at the results if you run the script from within Automator. Before saving it you should remove the added function.

    I updated the script to create the needed folders if not existant,
    just change userpath to "/Users/larsj/Movies/TVShows/"


    check my first post for the new upload
  • visagevisage Posts: 2Members
    I'm having a hard time with my input files where showname has more than one single word. They are all separated with a period, like "Deadliest.Catch.S06E12.HDTV.XviD-GNARLY". If I rename it to "Deadliest Catch.S06E12.HDTV.XviD-GNARLY" it will work...

    I'm kinda new to scripting and can't find a workaround for the script to work on these files.
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    edited July 2010
    Thats right, changed the script to accept files like yours as well. Please vote in the poll :)
    #replace:
    set the showname to the first text item of filename
    set the seasonandepisode to the second text item of filename
    

    #by:
    set filenamelist to every text item of the filename
    set showname to ""
    repeat with currentTextitem in filenamelist
    	
    	if (currentTextitem contains "S0" or currentTextitem contains "S1") then
    		set the seasonandepisode to currentTextitem	
    		exit repeat
    	else
    		set the showname to showname & " " & currentTextitem
    	end if
    end repeat
    

    the filename is separated into "Deadliest" & "Catch" & "S06E12" & "HDTV" & "XviD-GNARLY"
    with repeat I start a loop, with currentTextitem changing from "Deadliest" to "Catch" to .. and so on
    if the currenTextitem does not contain "S0" or "S1" (I guess there are no shows with more than 19 seasons) the script adds the item to the showname. This repeats until "S0" or "S1" is part of the item, now "S06E12" is saved to seasonandepisode and the loop can be exited.

    Problems occured if the episode's title contained words only consisting of numbers (e.g.: The Crash 312). Safari (and automator) display .xml files without any tags and replace them with blanks. e.g.:
      "2358351 212131 12 Empty Throne 2010-06-29 Josh remains behind to handle affairs on the Cornelia Marie as Captain Phil is medevaced to Anchorage. Captain Andy starts training Mike as relief captain, to the jealousy of the other deckhands. Word of Phil's stroke begins to reach the other captains, sending shockwaves through the fleet. 1277946232 0 episodes/78957/2358351.jpg 78957 2010-06-30 18:03:52 2 7 6 en"
    

    therefore I had to separate the title from the date via typ validation, changed the script today and hope it works properly now:

    set ersteselement to "2358351 212131 12 Empty Throne 23 2010-06-29 Josh remains behind to handle affairs on the Cornelia Marie as Captain Phil is medevaced to Anchorage. Captain Andy starts training Mike as relief captain, to the jealousy of the other deckhands. Word of Phil's stroke begins to reach the other captains, sending shockwaves through the fleet. 1277946232 0 episodes/78957/2358351.jpg 78957 2010-06-30 18:03:52 2 7 6 en"
    #set episodentitel to the fourth text item of ersteselement ...unnecessary.. will be deleted on the next upload
    set num to 4
    set episodentitel to ""
    repeat while (not (is_this_an_integer(word num of ersteselement) and is_this_an_integer(word (num + 1) of ersteselement) and is_this_an_integer(word (num + 2) of ersteselement) and not is_this_an_integer(word (num + 3) of ersteselement)))
    	if num = 4 then
    		set episodentitel to episodentitel & (word num of ersteselement)
    	else
    		set episodentitel to episodentitel & " " & (word num of ersteselement)
    	end if
    	set num to num + 1
    	
    end repeat
    return episodentitel
    
    on is_this_an_integer(thevariable)
    	try
    		thevariable as integer
    		return true
    	on error
    		return false
    	end try
    end is_this_an_integer
    
  • brettonlewisbrettonlewis Posts: 27Members, Plex Pass Plex Pass
    This sounds great. What would I need to customize to get these results:

    userpath / Showname / SXXEXX - showtitle.avi


    I have a huge library of TV shows without season folders. I tried editing a few lines but it only would output errors after.

    If anyone can help I would appreciate it. Thanks!
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    edited August 2010
    Just edit the very last code snippet:

    tell application "Finder" to set name of file ersteselement to seriesandepisode & "." & episodentitel & ".avi"
    

    just replace "." by " - "

    Are you sure that you want all the episodes in your main Show folder and not separated into seasons (Showname/Season 1/SXXEYY - showtitle.avi)?

    The userpath is changed in the first code snippet
    on run {input, parameters}
    	#this is a little tool, which renames the file, which you dropped on the app, from showname.S##E##.*****.avi to showname.S##E##.episodetitle.avi and moves it to a custom folder/showname/Season X/. The title is taken from thetvdb.com. 
    	#In order to use it you must change /Volumes/Drive1/Serien into your custom folder.... If you want to change the language of the titles you must replace en.xml by the an equivalent (look here). Use Automator.app for those modifications or a texteditor to change renameandmove.app/Contents/document.wflow.
    	#If you're done just drop a file on it 
    	#If you're wondering about the reason to make such an app: Coming from windows i miss the cut and paste and like the titles to be added automatically.
    	global showname
    	#edit this variable!
    	set userpath to "/Volumes/Drive1/Serien/"
    	#edit this variable! Important: last slash (/) !
    
  • brettonlewisbrettonlewis Posts: 27Members, Plex Pass Plex Pass
    edited August 2010
    Just a heads up that the last code snippet still has your drive paths in it:
    rename-copy-bug.jpg

    Is there any way to force the results to be capitalized? If the source file is named like this entourage.s07e05.asdasd.sdada.avi it will create a show folder named "entourage" rather than "Entourage" and the file output will be named s07e05.Bottoms Up... rather than the proper S07E05.. etc.

    Thanks for this amazing script, btw!
  • Don GiovanniDon Giovanni Posts: 4Members
    Couldn't get this to work for me, it pulls the correct name from the database it just can't add the episode name to the file name for some reason.

    "Run AppleScript Failed - 1 error
    Finder got and error: Can't set file "Volumes:Movies:The Big Bang Theory:Season 2:The Big Bang Theory.S02E02.avi" to "The Big Bang Theory.S02E02.The Codpiece Topology.avi". (-10006)

    So what I end up with is the original file "The.Big.Bang.Theory.S02E02.incorrectname.avi" (in /Volumes/Recordings) gets renamed to "The Big Bang Theory.S02E02.avi" and it also gets copied to /Volumes/Movies/The Big Bang Theory/Season 2/The Big Bang Theory.S02E02.avi

    Any idea why it can't add in the episode title?
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    edited September 2010
    xhalation wrote on 09 August 2010 - 03:15 AM:

    Just a heads up that the last code snippet still has your drive paths in it:
    rename-copy-bug.jpg

    Is there any way to force the results to be capitalized? If the source file is named like this entourage.s07e05.asdasd.sdada.avi it will create a show folder named "entourage" rather than "Entourage" and the file output will be named s07e05.Bottoms Up... rather than the proper S07E05.. etc.

    Thanks for this amazing script, btw!

    Thanks, your right, I edited the script and the userpath should occur only once now. It should work now, download the second app, I kept the last version up this time, just for sure.
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    edited September 2010
    Don Giovanni wrote on 12 September 2010 - 10:20 AM:

    Couldn't get this to work for me, it pulls the correct name from the database it just can't add the episode name to the file name for some reason.

    "Run AppleScript Failed - 1 error
    Finder got and error: Can't set file "Volumes:Movies:The Big Bang Theory:Season 2:The Big Bang Theory.S02E02.avi" to "The Big Bang Theory.S02E02.The Codpiece Topology.avi". (-10006)

    So what I end up with is the original file "The.Big.Bang.Theory.S02E02.incorrectname.avi" (in /Volumes/Recordings) gets renamed to "The Big Bang Theory.S02E02.avi" and it also gets copied to /Volumes/Movies/The Big Bang Theory/Season 2/The Big Bang Theory.S02E02.avi

    Any idea why it can't add in the episode title?

    Yeah its the wrong path, it should be Macintosh HD:Movies.., I edited the script, just download the new one.
  • Don GiovanniDon Giovanni Posts: 4Members
    Your update setting the userpath only once worked out nicely. Thank you for sharing your work!

    I have two questions for modifying the script for my personal use if you don't mind answering.

    Rather than copy the file I would like it to just move the file to a new folder. I assumed I could just replace the word "copy" with "move" this line in the second Apple script
    try
       copy file newpath to folder a
    


    Looks like I was wrong because the result is still a copy of the file rather than it being moved (you will have to excuse my ignorance in scripting).

    Another question I have is the final file name is "Showname.S##E##.Tile of Episode Here.avi" how would I modify this so the spaces in the file name get converted to periods? The result I am looking for would be "Showname.S##E##.Tile.of.Episode.Here.avi"

    I tried just adding the automator action "Replace Text in Finder Item Names" and doing a Find " " and Replace "." but after running realised that edits the file in its original path, not the file in its final destination.

    Thanks
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    I'll look into it, do you want the spaces to be replaced in the showname as well?
  • Don GiovanniDon Giovanni Posts: 4Members
    edited September 2010
    Yes please. As a personal rule I use periods instead of spaces in all file and folder names. Just makes it easier later on if I ever need to access stuff in terminal in OSX/Ubuntu. And I am **** retentive about all my files being uniform ;)

    Right now I just use a second app file I created in Automator to remove the spaces, but it would be nice to have it done all in one shot.
  • fhbfhb Posts: 362Members, Plex Pass Plex Pass
    mhm I tried it but it's too messy as the dot is used as a separator between showname,SxxEyy and episodetitle. Perhaps I'll try to write a small application with xcode. Automator is quite unuseful and restricted.
    You should add the functions from your second app to the end of mine, should do the trick.
  • Don GiovanniDon Giovanni Posts: 4Members
    edited September 2010
    fhb wrote on 13 September 2010 - 04:41 PM:

    mhm I tried it but it's too messy as the dot is used as a separator between showname,SxxEyy and episodetitle. Perhaps I'll try to write a small application with xcode. Automator is quite unuseful and restricted.
    You should add the functions from your second app to the end of mine, should do the trick.

    No big deal. Having to drop the files on two different app files isn't exactly hard.

    I had previously added functions to the end of your app, but for some reason these functions don't get applied.

    It's something with the way automator works because I have run into a similar issue before where two different functions wouldn't work when part of the same app/workflow but would when I separated them. I suspect it has something to do with automator only looking at the original file input. So if the file was first at OriginalPath\TV Showname.S01E01.Incorrect name here.avi
    The function I add at the end expects to modify only that original file in that original path, but we are no longer working with that path. Hope this makes sense...

    Maybe there is another kind of function I need to add before it to tell it to update with the new path??

    Thanks still.
  • brettonlewisbrettonlewis Posts: 27Members, Plex Pass Plex Pass
    Works perfectly now!

    It was allowing me to output the filename without the showname tacked on originally but now I can't seem to get it to do it again. It's outputting "Mad Men.SXXEYY showtitle.avi" and I was hoping to get "SXXEYY showtitle.avi".

    Is this still possible?

    Thanks again for this awesome script!
«1
Sign In or Register to comment.