Jump to content

Recommended Posts

Posted

I am in the process of converting my 13k+ media collection over from using xml files to the standard nfo files.  I am a stickler for the library art, etc. so I have resisted for many years in changing but finally decided to take the plunge.  I have written some python code to do most of the heavy lifting.  I started with TV shows and now have moved on to the movies.

 

I have a question about movie names that I am hoping for some advice on:

 

All of my movies are in folders.  The name of the movie media files is the Title of the movie, followed by the year in parenthesis.  However, I used the "sort title" for the folder names for the movies.  I am now thinking that I should correct that at this point.  Sounds like it might be a problem if I ever started using multiple versions of movies (the wiki says it has to match the folder name).

 

For example,  I currently have

 

/Movies/Watch, The (2012)/The Watch (2012).mkv

 

Should I rename that to:

 

/Movies/The Watch (2012)/The Watch (2012).mkv

 

Any thoughts on this?

 

Thanks.

Posted

It's not a bad idea if it's something you can easily do, yes.

Posted

I was afraid you were going to say it like that Luke...  

 

I was hoping you would either say "not a big deal" or "absolutely you should because of xyz" so that I was forced one way or the other!   :)   Now you left it up to me to decide.   :rolleyes:

Posted

When I did it I used

/Movies/Watch, The (2012)/Watch, The (2012).mkv

I don't have any issues

Posted

This has been debated before I am sure but are there not certain words that should be excluded from sorting like "The" or "A"? I also use the naming convention with a comma followed by "The" and have had no problem.

  • 2 weeks later...
ulrick65
Posted

Well, I made the plunge and renamed everything...so it's done and I moved everything to the new nfo style and deleted all xml traces.  It was quite a chore, but it helped me learn Python and I had a good time getting the scripts to work properly.

 

I admit, it is now strange to have everything in folders in "The..." but the reality is, once I am done setting a movie I rarely ever go back to the folder anyway.

 

Thanks.

Posted

Thanks for the feedback !

Posted

@ulrick65: Any chance you'll share your code - or the logic behind  ;) ?  

I'm too still using the xml files, but can hear the clock tick'ing.

WIll most likely use perl - but it would be a great help to see how you have translated.

ulrick65
Posted

@ulrick65: Any chance you'll share your code - or the logic behind  ;) ?  

I'm too still using the xml files, but can hear the clock tick'ing.

WIll most likely use perl - but it would be a great help to see how you have translated.

 

I would be glad to...but remember I am a self taught programmer (VBA) that jumped into Python for this project....so no guarantees on the functionality and certainly no pride in the coding style!!

 

Wouldn't mind feedback though from anyone as to what to do differently, etc.  I am learning and do this in my spare time...so every bit of advice helps.  I am sure my code is way longer then it needs to be, probably very inefficient and violates lots of standards...but in the end, it got the job done!

 

Not sure if it is OK to post it directly here...but I did anyway.

 

@@Luke can delete it if not not appropriate.

 

 

The first block below is for TV and the second one is for Movies.  This was written for Python 2.7 and had I known then what I have since learned, I would have done it in 3.6....man Unicode in 2.7 is a nightmare.  You will see that I used it all over the place trying to figure out what the heck was going on.  Many media items have Unicode characters...so it was all buggered up at first.  Python 3.6 handles it much better... but I didn't know that when I started.

 

I use metabrowser for my metadata...so basically what I did was ran these scripts first to convert over all the artwork to the new format.  They I used metabrowser to create all the .nfo files.  The way I went about it is like this:

 

I have many different libraries, so I did this for each one separatly as it was smaller chunks that way.

I setup metabrowser so it would not automatically scan and edit anymore...so everything was manual.

I made sure that ALL the items in my library were UNLOCKED (this is important...you will run into trouble later if you don't do this).

I ran these below scripts and got all the artwork converted over but left the xml files in place.

In metabrowser I enabled the XBMC Frodo Plugin for Locals and made it the primary and made the MediaBrowser local the "fallback".

I then configured XBMC Frodo plugin naming conventions (actually I think I just checked them and they were good as is)

I went to Savers and enabled XMBC Frod Plugin (make sure to use the Frodo version) and disabled the MediaBrowser saver.

I then scanned the library.  It recognized everything (well most everything, there were a few errors based on naming conventions but pretty minor).

Once that was done, you have to force save them all (I just used process all and had it rename files) so that it creates the .nfo files and renames the media files accordingly.

 

Optional:

I went one step further while I was in there and set it up to reprocess the entire library and update any missing metadata (some of my stuff is many years old, so it did find a lot of new things).

I also converted over the naming convention format that I mention here in this thread...not sure I would recommend that really, but its not the end of the world.

 

Saved everything and told Emby to rescan...and Bob's your uncle!

 

Now, I have a rather large collection, so some of this took a while...but in the end it worked out and all is running fine.  Had to rebuild KODI Local Database on each KODI install, but that was pretty minor and worked fine (also took a while though).

 

I am currently putting the finishing touches on a Python program that scans all my media for foreign languages (audio and subtitle) and remuxes anything that it finds.  Just about have that working perfectly too...  Really loving Python so far!

 

Let me know if I can help...moving off xml was not quite as bad as I thought...between the scripts and metabrowser it was somewhat painless (although time consuming).

import fnmatch
import os
import shutil
import sys

starting_folder_path = "//192.168.1.242/Media/TV - Ended Archive"
rogue_series_files_log = "D:/Working/rogue_series_files.log"
rogue_season_files_log = "D:/Working/rogue_season_files.log"
rogue_metadata_files_log = "D:/Working/rogue_metadata_files.log"
rogue_series_files_delete = False
rogue_season_files_delete = False
rogue_metadata_files_delete = False


def clean_up_errors(c_list, c_path, c_delete):

    if len(c_list) > 0:
        with open(c_path, 'w') as error_writer:
            for error_file in c_list:
                if c_delete:
                    error_writer.write(
                        (error_file + " - DELETED" + "\n").encode("utf-8")
                    )
                    os.remove(error_file)
                else:
                    error_writer.write(
                        (error_file + " - Not Deleted" + "\n").encode("utf-8")
                    )


def yes_or_no(question):
    while "the answer is invalid":
        reply = str(raw_input(question+' (y/n): ')).lower().strip()
        if reply[:1] == 'y':
            return True
        if reply[:1] == 'n':
            return False


def process_series_folder(path, files):
    if not os.path.isdir(os.path.join(path, "extrafanart")):
        os.mkdir(os.path.join(path, "extrafanart"))
    for f in files:
        full_path = os.path.abspath(os.path.join(path, f))
        if f.startswith("backdrop"):
            if os.path.splitext(f)[0] == "backdrop":
                if not os.path.isfile(full_path.replace(
                        "backdrop", "season-all-fanart")
                ):
                    try:
                        shutil.copy(full_path, full_path.replace(
                            "backdrop", "season-all-fanart")
                                    )
                    except IOError:
                        rogue_series_files.append(full_path + " - IO Error")
                        pass
                else:
                    rogue_series_files.append(
                        full_path + " - Error Copying File")
                    rogue_series_files.append(full_path.replace(
                        "backdrop", "season-all-fanart") + " - Already Exists")
                if not os.path.isfile(full_path.replace(
                        "backdrop", "fanart")
                ):
                    os.rename(full_path, full_path.replace(
                        "backdrop", "fanart")
                              )
                else:
                    rogue_series_files.append(
                        full_path + " - Error Copying File")
                    rogue_series_files.append(full_path.replace(
                        "backdrop", "fanart") + " - Already Exists")

            else:
                if not os.path.isfile(os.path.join(
                        path, "extrafanart", f.replace("backdrop", "fanart"))):
                    os.rename(full_path, os.path.join(
                        path, "extrafanart", f.replace("backdrop", "fanart")))

                else:
                    rogue_series_files.append(
                        full_path + " - Error Renaming File")
                    rogue_series_files.append(full_path.replace(
                        "backdrop", "fanart") + " - Already Exists")

        if f.startswith("folder."):
            if not os.path.isfile(full_path.replace(
                    "folder", "season-all-poster")
            ):
                try:
                    shutil.copy(full_path, full_path.replace(
                        "folder", "season-all-poster")
                                )
                except IOError:
                    rogue_series_files.append(full_path + " - IO Error")
                    pass

            else:
                rogue_series_files.append(
                    full_path + " - Error Copying File")
                rogue_series_files.append(full_path.replace(
                    "folder", "season-all-poster") + " - Already Exists")

            if not os.path.isfile(full_path.replace("folder", "poster")):
                os.rename(full_path, full_path.replace("folder", "poster"))
            else:
                rogue_series_files.append(
                    full_path + " - Error Renaming File")
                rogue_series_files.append(full_path.replace(
                    "folder", "poster") + " - Already Exists")

        if f.startswith("thumb."):
            if not os.path.isfile(full_path.replace("thumb", "landscape")):
                os.rename(full_path, full_path.replace("thumb", "landscape"))
            else:
                rogue_series_files.append(
                    full_path + " - Error Renaming File")
                rogue_series_files.append(full_path.replace(
                    "thumb", "landscape") + " - Already Exists")
        if f.startswith("banner."):
            if not os.path.isfile(full_path.replace(
                    "banner", "season-all-banner")
            ):
                try:
                    shutil.copy(full_path, full_path.replace(
                        "banner", "season-all-banner")
                                )
                except IOError:
                    rogue_series_files.append(full_path + " - IO Error")
                    pass

            else:
                rogue_series_files.append(
                    full_path + " - Error Renaming File")
                rogue_series_files.append(full_path.replace(
                    "banner", "season-all-banner") + " - Already Exists")


def process_season_folder(path, files):
    for f in files:
        full_path = os.path.abspath(os.path.join(path, f))
        series_folder = os.path.abspath(os.path.join(
            full_path, os.pardir, "..")
        )
        if os.path.basename(path).replace(" ", "").lower() == "season00":
            season_name = "season-specials"
        else:
            season_name = os.path.basename(path).replace(" ", "").lower()

        if f.startswith("folder."):
            season_poster = os.path.join(
                series_folder, season_name.lower() + f.replace(
                    "folder", "-poster")
            )
            if not os.path.isfile(season_poster):
                try:
                    shutil.move(full_path, season_poster)
                except IOError:
                    rogue_season_files.append(full_path + " - IOError")
                    pass
            else:
                rogue_season_files.append(full_path + " - Error Renaming File")
                rogue_season_files.append(season_poster + " - Already Exists")

        if f.startswith("thumb."):
            season_landscape = os.path.join(
                series_folder, season_name.lower() + f.replace(
                    "thumb", "-landscape")
            )
            if not os.path.isfile(season_landscape):
                try:
                    shutil.move(full_path, season_landscape)
                except IOError:
                    rogue_season_files.append(full_path + " - IOError")
                    pass
            else:
                rogue_season_files.append(full_path + " - Error Renaming File")
                rogue_season_files.append(
                    season_landscape + " - Already Exists"
                )

        if f.startswith("banner."):
            season_banner = os.path.join(
                series_folder, season_name.lower() + f.replace(
                    "banner", "-banner"))
            if not os.path.isfile(season_banner):
                try:
                    shutil.move(full_path, season_banner)
                except IOError:
                    rogue_season_files.append(full_path + " - IOError")
                    pass
            else:
                rogue_season_files.append(full_path + " - Error Renaming File")
                rogue_season_files.append(
                    season_banner + " - Already Exists"
                )


def process_metadata_folder(path, files):
    for f in files:
        if os.path.splitext(f)[1].lower() == ".jpg":
            full_path = os.path.abspath(os.path.join(path, f))
            season_folder = os.path.abspath(os.path.join(
                full_path, os.pardir, "..")
            )
            episode_thumb = os.path.splitext(f)[0] + "-thumb" + \
                os.path.splitext(f)[1]
            episode_thumb = os.path.join(season_folder, episode_thumb)
            if not os.path.isfile(episode_thumb):
                try:
                    shutil.move(full_path, episode_thumb)
                except IOError:
                    rogue_metadata_files.append(full_path + " - IOError")
                    pass
            else:
                rogue_metadata_files.append(
                    full_path + " - Error Renaming File"
                )
                rogue_metadata_files.append(
                    episode_thumb + " - Already Exists"
                )


if rogue_series_files_delete or rogue_season_files_delete \
        or rogue_metadata_files_delete:
    print ""
    ok_to_delete = yes_or_no("Going to delete some files if found, OK?")
    if not ok_to_delete:
        sys.exit("Exiting at user request")

rogue_series_files = []
rogue_season_files = []
rogue_metadata_files = []
for path, folders, files in os.walk(unicode(starting_folder_path)):
    if os.path.isfile(os.path.join(path, "series.xml")):
        print os.path.basename(path)
        process_series_folder(path, files)
    if fnmatch.fnmatch(os.path.basename(path).lower(), "season*"):
        process_season_folder(path, files)

    if fnmatch.fnmatch(os.path.basename(path).lower(), "metadata"):
        process_metadata_folder(path, files)

clean_up_errors(rogue_season_files, rogue_season_files_log,
                rogue_season_files_delete)

clean_up_errors(rogue_series_files, rogue_series_files_log,
                rogue_series_files_delete)

clean_up_errors(rogue_metadata_files, rogue_metadata_files_log,
                rogue_metadata_files_delete)

import os
import sys
import fnmatch
from colorama import init

starting_folder_path = "//192.168.1.242/Media/Movies 02"
error_trailer_move_log = "D:/Working/error_trailer_move.log"
error_movie_art_log = "D:/Working/error_movie_art.log"
rogue_files_log = "D:/Working/rogue_files.log"
running_on_windows = False
# Setting this to True will cause the program to remove any files of the old
# type if a file of the new type already exists.  For example:  If it tries
# to rename folder.jpg to SomeMovie-poster.jpg and SomeMovie-poster.jpg already
# exists in that location, it will keep that file and REMOVE the folder..jpg
remove_existing_files = True
# Setting this to True will take a little longer, but will give the user a
# total count of movies before processing, so they know what to expect.
count_movies_to_process = False
# Set this to the maximum number of movies to process. This is used to stop
# processing if you only want to test it on a few movies.  Setting this to zero
# will disable it and process all movies.
movies_to_process = 0

# Initialize colorama if we are running on windows terminal
if running_on_windows:
    init()

# Ansi colors for printing color messages
BLACK = "\033[0;30m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
YELLOW = "\033[0;33m"
BLUE = "\033[0;34m"
MAGENTA = "\033[0;35m"
CYAN = "\033[0;36m"
WHITE = "\033[0;37m"


def clean_up_errors(c_list, c_path):

    if len(c_list) > 0:
        with open(c_path, 'w') as error_writer:
            for error_file in c_list:
                error_writer.write(
                    (error_file + "\n").encode("utf-8")
                )


def yes_or_no(question):
    while "the answer is invalid":
        reply = str(raw_input(question+' (y/n): ')).lower().strip()
        if reply[:1] == 'y':
            return True
        if reply[:1] == 'n':
            return False


def sorted_walk(top, top_down=True, onerror=None):
    """ Return a sorted list from os.walk

    Normal os.walk does not provide a sorted list. The key=... is used to
    ignore upper case when sorting, because normally upper case is sorted
    ahead of lower case in Python.
    """
    from os.path import join, isdir, islink, abspath

    names = os.listdir(top)
    names.sort(key=lambda s: s.lower())
    dirs = []
    non_dirs = []

    for name in names:
        if isdir(os.path.join(top, name)):
            dirs.append(name)
        else:
            non_dirs.append(name)

    if top_down:
        yield top, dirs, non_dirs
    for name in dirs:
        s_path = abspath(join(top, name))
        if not islink(s_path):
            for x in sorted_walk(s_path, top_down, onerror):
                yield x
    if not top_down:
        yield top, dirs, non_dirs


def process_movie_folder(m_path, m_files):
    for f in m_files:
        if f.startswith("backdrop"):
            if not f.startswith("backdrop."):
                move_fanart(m_path, f)
                continue
            else:
                rename_file(m_path, f, "backdrop", "-fanart")
                continue
        if f.startswith("banner."):
            rename_file(m_path, f, "banner", "-banner")
            continue
        if f.startswith("clearart."):
            rename_file(m_path, f, "clearart", "-clearart")
            continue
        if f.startswith("disc."):
            rename_file(m_path, f, "disc", "-disc")
            continue
        if f.startswith("folder."):
            rename_file(m_path, f, "folder", "-poster")
            continue
        if f.startswith("landscape."):
            rename_file(m_path, f, "landscape", "-landscape")
            continue
        if f.startswith("logo."):
            rename_file(m_path, f, "logo", "-logo")
            continue

        old_file = os.path.abspath(os.path.join(m_path, f))
        if not f.startswith(os.path.basename(m_path)):
            if f.lower() == "back.jpg" or f.lower() == "thumbs.db":
                try:
                    os.remove(old_file)
                    rogue_files.append(old_file + " - File Deleted")
                except (IOError, OSError) as error:
                    rogue_files.append(old_file + " - Error Removing")
                    rogue_files.append(
                        old_file + " - " + str(error.errno)
                        + ": " + error.strerror
                    )
            elif not f.startswith("movie.xml"):
                rogue_files.append(old_file)


def process_collection_folder(c_path, c_files):
    for f in c_files:
        old_file = os.path.abspath(os.path.join(c_path, f))

        if f.startswith("backdrop"):
            if not f.startswith("backdrop."):
                move_fanart(c_path, f)
                continue
            else:
                new_file = os.path.join(
                    c_path, f.replace("backdrop", "fanart")
                )
                if not os.path.isfile(new_file):
                    try:
                        os.rename(old_file, new_file)
                    except (IOError, OSError) as error:
                        error_movie_art_files.append(
                            old_file + " - Error Renaming"
                        )
                        error_movie_art_files.append(
                            new_file + " - " + str(error.errno) + ": "
                            + error.strerror)
                else:
                    error_movie_art_files.append(
                        old_file + " - Error Renaming"
                    )
                    error_movie_art_files.append(
                        new_file + " - Already Exists"
                    )
                    if remove_existing_files:
                        try:
                            os.remove(old_file)
                            error_movie_art_files.append(
                                old_file + " - Removed"
                            )
                        except (IOError, OSError) as error:
                            error_movie_art_files.append(
                                old_file + " - Error Removing File"
                            )
                            error_movie_art_files.append(
                                old_file + " - " + str(error.errno) + ": "
                                + error.strerror
                            )

                continue

        if f.startswith("folder."):
            new_file = os.path.join(c_path, f.replace("folder", "poster"))
            if not os.path.isfile(new_file):
                try:
                    os.rename(old_file, new_file)
                except (IOError, OSError) as error:
                    error_movie_art_files.append(
                        old_file + " - Error Renaming"
                    )
                    error_movie_art_files.append(
                        new_file + " - " + str(error.errno) + ": "
                        + error.strerror)
            else:
                error_movie_art_files.append(
                    old_file + " - Error Renaming"
                )
                error_movie_art_files.append(
                    new_file + " - Already Exists"
                )
                if remove_existing_files:
                    try:
                        os.remove(old_file)
                        error_movie_art_files.append(
                            old_file + " - Removed"
                        )
                    except (IOError, OSError) as error:
                        error_movie_art_files.append(
                            old_file + " - Error Removing File"
                        )
                        error_movie_art_files.append(
                            old_file + " - " + str(error.errno) + ": "
                            + error.strerror
                        )

            continue

        if os.path.splitext(f)[0] not in collection_allowed_files:
            if f.lower() == "back.jpg" or f.lower() == "thumbs.db":
                try:
                    os.remove(old_file)
                    rogue_files.append(old_file + " - File Deleted")
                except (IOError, OSError) as error:
                    rogue_files.append(old_file + " - Error Removing")
                    rogue_files.append(
                        old_file + " - " + str(error.errno)
                        + ": " + error.strerror
                    )
            else:
                rogue_files.append(old_file)


def process_trailer_folder(t_path, t_files):
    if not t_files:
        try:
            os.rmdir(t_path)
        except (IOError, OSError) as error:
            error_trailer_move_files.append(
                t_path + " - Error Removing Folder"
            )
            error_trailer_move_files.append(
                t_path + " - " + str(error.errno) + ": "
                + error.strerror
            )
    for trailer in t_files:
        old_trailer = os.path.abspath(os.path.join(t_path, trailer))
        new_trailer = os.path.basename(
            os.path.dirname(t_path)
        ) + "-trailer" + os.path.splitext(trailer)[1]
        new_trailer = os.path.abspath(
            os.path.join(os.path.dirname(t_path), new_trailer)
        )
        if not os.path.isfile(new_trailer):
            try:
                os.rename(old_trailer, new_trailer)
            except (IOError, OSError) as error:
                error_trailer_move_files.append(
                    old_trailer + " - Error Moving File"
                )
                error_trailer_move_files.append(
                    new_trailer + " - " + str(error.errno) + ": "
                    + error.strerror
                )

        else:
            error_trailer_move_files.append(
                old_trailer + " - Error Moving File"
            )
            error_trailer_move_files.append(
                new_trailer + " - The File Already Exists"
            )
            if remove_existing_files:
                try:
                    os.remove(old_trailer)
                    error_trailer_move_files.append(old_trailer + " - Removed")
                except (IOError, OSError) as error:
                    error_trailer_move_files.append(
                        old_trailer + " - Error Removing File"
                    )
                    error_trailer_move_files.append(
                        old_trailer + " - " + str(error.errno) + ": "
                        + error.strerror
                    )
                try:
                    os.rmdir(t_path)
                except (IOError, OSError) as error:
                    error_trailer_move_files.append(
                        t_path + " - Error Removing Folder"
                    )
                    error_trailer_move_files.append(
                        t_path + " - " + str(error.errno) + ": "
                        + error.strerror
                    )


def rename_file(r_path, r_file, old_name, new_name):
    old_file = os.path.abspath(os.path.join(r_path, r_file))
    movie_name = os.path.basename(r_path)
    new_file = os.path.join(
        r_path, r_file.replace(old_name, movie_name + new_name)
    )

    if not os.path.isfile(new_file):
        try:
            os.rename(old_file, new_file)
        except (IOError, OSError) as error:
            error_movie_art_files.append(old_file + " - Error Renaming")
            error_movie_art_files.append(
                new_file + " - " + str(error.errno) + ": "
                + error.strerror)
    else:
        error_movie_art_files.append(old_file + " - Error Renaming")
        error_movie_art_files.append(new_file + " - Already Exists")
        if remove_existing_files:
            try:
                os.remove(old_file)
                error_movie_art_files.append(old_file + " - Removed")
            except (IOError, OSError) as error:
                error_movie_art_files.append(
                    old_file + " - Error Removing File"
                )
                error_movie_art_files.append(
                    old_file + " - " + str(error.errno) + ": "
                    + error.strerror
                )


def move_fanart(f_path, f_file):
    old_file = os.path.abspath(os.path.join(f_path, f_file))
    new_file = os.path.join(
        f_path, "extrafanart", f_file.replace("backdrop", "fanart")
    )

    if not os.path.isdir(os.path.join(f_path, "extrafanart")):
        try:
            os.mkdir(os.path.join(f_path, "extrafanart"))
        except (IOError, OSError) as error:
            error_movie_art_files.append(
                f_path + " - Error Creating extrafanart Folder"
            )
            error_movie_art_files.append(
                f_path + " - " + str(error.errno) + ": "
                + error.strerror
            )

    if not os.path.isfile(new_file):
        try:
            os.rename(old_file, new_file)
        except (IOError, OSError) as error:
            error_movie_art_files.append(old_file + " - Error Renaming")
            error_movie_art_files.append(
                new_file + " - " + str(error.errno) + ": "
                + error.strerror)
    else:
        error_movie_art_files.append(old_file + " - Error Renaming")
        error_movie_art_files.append(new_file + " - Already Exists")

        if remove_existing_files:
            try:
                os.remove(old_file)
                error_movie_art_files.append(old_file + " - Removed")
            except (IOError, OSError) as error:
                error_movie_art_files.append(
                    old_file + " - Error Removing File"
                )
                error_movie_art_files.append(
                    old_file + " - " + str(error.errno) + ": "
                    + error.strerror
                )


print RED
print "This will rename fanart files, move the trailer and"
print "delete the Trailers folder (if empty after the move)"
ok_to_delete = yes_or_no("OK to Proceed? ")
if not ok_to_delete:
    sys.exit("Exiting at user request")
print WHITE

if remove_existing_files:
    print RED
    print "Remove Existing Files is set to TRUE!"
    print "This will remove fanart files of the old naming convention if a"
    print "file already exists of the new naming convention!"
    ok_to_delete = yes_or_no("OK to Proceed? ")
    if not ok_to_delete:
        sys.exit("Exiting at user request")
    print WHITE

collection_allowed_files = ["collection", "banner", "clearart", "fanart",
                            "landscape", "logo", "poster"
                            ]
error_trailer_move_files = []
error_movie_art_files = []
rogue_files = []
movie_folders = []

print "Analyzing...please wait..."
print ""
if count_movies_to_process:
    movie_count = 0
    movie_report = 50
    for m_path, m_folders, m_files in sorted_walk(unicode(starting_folder_path)):
        for file_name in fnmatch.filter(m_files, "movie.xml"):
            movie_folders.append(os.path.abspath(m_path))
            movie_count = movie_count + 1
            if movie_count == movie_report:
                print "Movies Found So Far: ", movie_count
                movie_report = movie_count + 50

    print ""
    print "Total Movies To Process: ", len(movie_folders)
    print ""
movie_count = 0
movie_report = 25
for path, folders, files in sorted_walk(unicode(starting_folder_path)):
    if os.path.isfile(os.path.join(path, "movie.xml")):
        if movie_count == movie_report:
            print "Movies Processed So Far: ", movie_count
            movie_report = movie_report + 25
        process_movie_folder(path, files)
        movie_count = movie_count + 1
        if movies_to_process != 0:
            if movie_count >= movies_to_process:
                break

    if os.path.basename(path).lower() == "trailers":
        process_trailer_folder(path, files)

    if os.path.isfile(os.path.join(path, "collection.xml")):
        process_collection_folder(path, files)

clean_up_errors(error_trailer_move_files, error_trailer_move_log)
clean_up_errors(error_movie_art_files, error_movie_art_log)
clean_up_errors(rogue_files, rogue_files_log)

print ""
print "Movies Processed: ", movie_count
print "Art File Errors: ", len(error_movie_art_files)
print "Trailer File Errors: ", len(error_trailer_move_files)
print "Rogue Files Found: ", len(rogue_files)
print ""
print "Processing Completed"

Posted

@ulrick65:​ Thanks a lot - both for the code and the great work description. 

The code looks to me very nicely structured and easily read.

For scripting like this I think it's a good decision to favor "get it done".

 

I'll dust off my python knowledge and consider if I'll adapt the code or convert into perl.

Think Python is a great language with a lot of useful libraries - but have always been a bit sceptical over a language using whitespace for the block syntax. At least when I'm the one at the keyboard :)

Unicode is a constant pain, yes - not least when using both Linux and Windows and different programming languages.

moviefan
Posted

FYI, as I recently learned, you can simply turn on NFO writing in Emby, disable downloaders, and manually refresh a Library to force Emby to create the NFOs on your behalf without any scripting.

ulrick65
Posted

FYI, as I recently learned, you can simply turn on NFO writing in Emby, disable downloaders, and manually refresh a Library to force Emby to create the NFOs on your behalf without any scripting.

 

I would be interested to know exactly how that works.  I would guess that it would scrape the metadata rather than convert what is already there (in the xml format and the artwork with the old mediabrowser style naming conventions).  Do you have a reference or can you give details as to how this works?

 

Thanks.

moviefan
Posted

I would be interested to know exactly how that works.  I would guess that it would scrape the metadata rather than convert what is already there (in the xml format and the artwork with the old mediabrowser style naming conventions).  Do you have a reference or can you give details as to how this works?

 

If you have local metadata and the downloaders are turned off, the only information that Emby has is what is in the local metadata.  If you do a refresh in this state it will write that information to NFO files.

 

As far as the artwork, the only change is folder to poster right?  Emby did most of these but not all.  It was easy for me to sort this out after the fact even with over 4000 movies.

ulrick65
Posted

The artwork is much more substantial a change than that.  All the backdrops have to be saved into the extrafanart folder and all of the other artworks needs to be renamed to the movie title followed by a dash and the type of artwork.  The trailer gets moved from the trailer folder to the main folder and renamed appropriately.

Posted

They don't have to be because we will still recognize the older conventions. You can also just leave your artwork as it is, and from Emby's standpoint it will work fine.

ulrick65
Posted

They don't have to be because we will still recognize the older conventions. You can also just leave your artwork as it is, and from Emby's standpoint it will work fine.

 

Understood.  The whole point though is to convert it all over to the new format.  Not only that, but the library would then have some old format and everything from here forward in the new format...which isn't really what I was after.  Either way...whatever works for the user.  For me, I prefer the consistency so I converted everything and works like a champ.

 

Thanks.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...