Prune Ended TVShows – A Script To Move Ended TVShows

Prune Ended Shows
A Script To Move Ended TVShows

I have written a script in bash that will move all TVShows with the status "Ended" to a separate directory. I find this useful because I have over 700 TVShows in my library, and I have noticed that this amount of files increases scan time when performing library updates.

To use this script you will need to first export your library into separate files, this will create the necessary nfo files that this script needs. Please note that this script requires you to use TheTVDB as a scraper!

You will also need to create a secondary directory to store TVShows that are no longer airing. I chose to call this folder "TVShows (Old)".

Next, use the script to move all your ended TVShows to your secondary directory. Make sure that you modify the script to work with your paths! I also suggest using your own API key for TheTVDB! Note that you can also easily customize the path of the logfile.

Code:
#!/bin/bash

# System readable timestamp
Date=`date +%Y%m%d%H%M%S`

# Human readable timestamp
Time=`date +%Y/%m/%d\ %H:%M:%S`

# Path to log file
# If file does not exist, it will be created
MyLog=~/PruneEndedShows"${Date}".log

# Path to TVShows
MyTVShowPath=~/TVShows/

# Path to Ended TVShows
MyEndedTVShowPath=~/TVShows\ \(Old\)/

# TheTVDB.com API key
MyAPIKey=1D62F2F90030C444

#----------------------------

touch "${MyLog}"
echo "${Time} - Started Processing Directory: ${MyTVShowPath}" >> "${MyLog}"

# Get list of TVShows
MyTVShowRegex="$(echo "${MyTVShowPath}" | sed -e 's/\//\\\//g')"
MyTVShowList="$(ls --format=single-column -d ${MyTVShowPath}*/ | sed -e 's/'"${MyTVShowRegex}"'//g')"

echo "The Following TVShows will be processed:" >> "${MyLog}"
echo "${MyTVShowList}" >> "${MyLog}"

IFS=$'\n' read -rd '' -a MyTVShowArray <<< "$MyTVShowList"

for ThisTVShowPath in "${MyTVShowArray[@]}"; do

    # Create temp file
    touch "${MyTVShowPath}${ThisTVShowPath}tmp.nfo"

    # Get TVShow ID from tvshow.nfo
    echo "Processing ${ThisTVShowPath}" >> "${MyLog}"
    ThisTVShowID="$(grep -hi "\<id\>" "${MyTVShowPath}${ThisTVShowPath}tvshow.nfo" | sed -e 's/\(\s\)\{0,\}<\/\?id>//g')"

    #Make URL
    ThisTVShowURL="http://www.thetvdb.com/api/${MyAPIKey}/series/${ThisTVShowID}/"

    # Download TVShow URL to temp file
    echo "Downloading MetaData from ${ThisTVShowURL}" >> "${MyLog}"
    wget -q "${ThisTVShowURL}" -O "${MyTVShowPath}${ThisTVShowPath}tmp.nfo"

    # Parse Temp NFO for status
    ThisTVShowStatus="$(grep -hi "\<status\>" "${MyTVShowPath}${ThisTVShowPath}tmp.nfo" | sed -e 's/\(\s\)\{0,\}<\/\?Status>//g')"
    echo "Status of ${ThisTVShowPath}: ${ThisTVShowStatus}" >> "${MyLog}"

    if [ "${ThisTVShowStatus}" == "Ended" ]; then

        echo "Moving files..." >> "${MyLog}"
        mv -fv "${MyTVShowPath}${ThisTVShowPath}" "${MyEndedTVShowPath}" >> "${MyLog}"

    fi


done

# Clean up temp files
echo "Cleaning up temp files" >> "${MyLog}"
rm -fv "${MyEndedTVShowPath}"*/tmp.nf >> "${MyLog}"
rm -fv "${MyTVShowPath}"*/tmp.nfo >> "${MyLog}"

# Finished
echo "Processing Complete" >> "${MyLog}"

Finally, you will need to add the secondary directory (ie. "TVShows (Old)") back into Kodi. Make sure you add it as its own source, and also exclude the path from library updates

Now only TVShows scheduled to continue will be included in your library updates! Big Grin

Playback randomly stops

I'm experiencing this issue since quite some time (probably since I installed v17) where the playback would just stop randomly when playing videos. It can happen 2 - 3 times when watching a TV show, or sometimes not at all. Tonight was really bad, I wa...

Amlogic hardware support

Hello, I am working on firmware for mediaplayer based on Amlogic CPU. This firmware in fact is Linux with Kodi as GUI. I am using libamcodec to play video with hardware acceleration. And I have some problems on new Amlogic hardware - http://trac.kodi....

Super Favourites Create new Super Folder

Is it possible for Super Favourites to look slightly different - by having the Create new Super Folder in the context menu for a given Super Folder and not as the first item in the list within the folder? Then the blank line would not be needed and the...

Change remote.xml home default mapping

I may well be mis-understanding exactly how all the default key mapping works, but if I am understanding correctly would the team please consider removing the keymapping from remote.xml for the info button when on the home screen. As Krypton now suppo...

Rotating videos while playing

Hi, I want to rotate video files(not display) while playing but i haven't find any solutions yet with osmc/kodi. For example on windows with pot player i can easily rotate videos 90 180 270 degrees while playing. Is it really hard to do it with kodi o...

Removing Old/Unnecessary Movie Scrapes

i have all my movies scraped and set with the poster image that i want but the question i have is; can you remove incorrect movie posters(for the correct movie) that kodi stores after you've selected the poster you want?(example: i only use movie poste...

Play in order but with random start

I was just wondering if I was missing an setting, but this may be a feature request then. Is it possible to play shows in order but not start at S01E01? I have a channel that is set to play a show in order. It works great but every time I start PT...

Question About Submitting a Kodi AddOn

Hello guys Im new to Kodi development I have develeoped a Video AddOn for Kodi, and I want this AddOn to be in the list of VideoAddOn-s so users can find this one easily So my question is: Should i submit the zip file of my video addOn or the zip file...

Logitech G933 7.1 – Voice channel missing?

Hey there! I just received my new Logitech G933 wireless surround sound headphones and was eager to try them on and watch a dolby or DTS movie from my libary. I've set up the logitech software and kodi settings: Audio output dev to WASAPI Logitech G93...

View Video History

Purchased Matricom G-Box Q² android box about a month ago, running Kodi 16.1. I mainly use it to watch college football, last weekend by accident I came across a video add-on that had all the ESPN channels. I can't for the life of me remember it name now, and was hoping there is a log or history file that I can access showing channels/add-ons I last watched.
I did do a export of my video library, but not sure if that contains the data I need, and have no idea how to access or read it.

Share Music “Files” Node over UPNP

Is there any way to share the "Files" node of the music library over UPNP/DLNA (either already in Jarvis, or in development)? This seems to be a sadly neglected area - does no-one have more than a handful of albums :-(

Ubuntu freezing

I've just started using Ubuntu and installed Kodi following the command line instructions in the wiki. This installed Krypton rather than Jarvis, which I assume is intended (I also found that software centre is installing Krypton beta 3 too). Anyway, ...

Grouping Movies and TV Shows with same name

Hi all, It can happen for me to have multiple files for the same TV Episode or Movie. This is because I have some videos that have different quality. However, the library shows me two or three entries for those cases. I would like to be able to see o...