<commit_before>#!/usr/bin/env python
import os
import sys
import autoProcessMovie
import tmdb
import guessit
from imdb_mp4 import imdb_mp4
from readSettings import ReadSettings
from mkvtomp4 import MkvtoMp4
from extensions import valid_input_extensions

print "nzbToCouchPotato MP4 edition"

def FILEtoIMDB(file_name): #Added function by nctiggy. This executes if the nzb does not have the IMDB id appended to the name
    #This does capture all of the movies info not just the IMDB id
    #Future can eliminate the calls to IMDB to use this data instead perhaps
    
    print "CouchPotatoServer did not append the IMDB id to the nzb, guessing instead"
    api_key = "45e408d2851e968e6e4d0353ce621c66" # You need to get this key from themoviedb.org

    # Guessing at the name of the movie using the filename
    movie_info = guessit.guess_movie_info(file_name)
    
    #configuring tmdb to use the supplied api key
    tmdb.configure(api_key)
    print "Guessed movie title as: %s" % (movie_info["title"])
    
    #Creating a collection of movies from tmdb for the guess movie title
    movies = tmdb.Movies(movie_info["title"])

    #parse through all movies found
    for movie in movies.iter_results():
        #Identify the first movie in the collection that matches exactly the movie title
        if movie["title"].lower() == movie_info["title"].lower():
            print "Matched movie title as: %s %s" % (movie["title"], movie["release_date"])
            movie = tmdb.Movie(movie["id"])
            break
    #return the imdb id of the movie identified
    return movie.get_imdb_id()[2:]

def NZBtoIMDB(nzbName):
    nzbName = str(nzbName)
    a = nzbName.find('.cp(tt') + 6
    b = nzbName[a:].find(')') + a
    imdbid = nzbName[a:b]
    return imdbid

settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")
imdb_id = NZBtoIMDB(sys.argv[2])

if len(sys.argv) > 3:
    path = str(sys.argv[1])
    for r, d, f in os.walk(path):
        for files in f:
            if os.path.splitext(files)[1][1:] in valid_input_extensions:
                file = os.path.join(r, files)
                if imdbid = "":
                    try:
                        imdb_id = FILEtoIMDB(os.path.basename(file))
                    except AttributeError:
                        print "Unable to accurately identify movie file %s" % (file)
                print "IMDB ID is: %s" % (imdb_id)
                print "Converting the following file: %s" % (os.path.basename(file))
                convert = MkvtoMp4(file, FFMPEG_PATH=settings.ffmpeg, FFPROBE_PATH=settings.ffprobe, delete=settings.delete, output_extension=settings.output_extension, relocate_moov=settings.relocate_moov, iOS=settings.iOS, awl=settings.awl, swl=settings.swl, adl=settings.adl, sdl=settings.sdl)
                try:
                    imdbmp4 = imdb_mp4(imdb_id)
                    imdbmp4.setHD(convert.width, convert.height)
                    imdbmp4.writeTags(convert.output)
                except AttributeError:
                    print "Unable to tag file, Couch Potato probably screwed up passing the IMDB ID"

# SABnzbd
if len(sys.argv) == 8:
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file<commit_msg>Adding additional logging to assist troubleshooting<commit_after>#!/usr/bin/env python
import os
import sys
import autoProcessMovie
import tmdb
import guessit
from imdb_mp4 import imdb_mp4
from readSettings import ReadSettings
from mkvtomp4 import MkvtoMp4
from extensions import valid_input_extensions

print "nzbToCouchPotato MP4 edition"

def FILEtoIMDB(file_name): #Added function by nctiggy. This executes if the nzb does not have the IMDB id appended to the name
    #This does capture all of the movies info not just the IMDB id
    #Future can eliminate the calls to IMDB to use this data instead perhaps
    
    print "CouchPotatoServer did not append the IMDB id to the nzb, guessing instead"
    api_key = "45e408d2851e968e6e4d0353ce621c66" # You need to get this key from themoviedb.org

    # Guessing at the name of the movie using the filename
    movie_info = guessit.guess_movie_info(file_name)
    
    #configuring tmdb to use the supplied api key
    tmdb.configure(api_key)
    print "Guessed movie title as: %s" % (movie_info["title"])
    
    #Creating a collection of movies from tmdb for the guess movie title
    movies = tmdb.Movies(movie_info["title"])

    #parse through all movies found
    for movie in movies.iter_results():
        #Identify the first movie in the collection that matches exactly the movie title
        if movie["title"].lower() == movie_info["title"].lower():
            print "Matched movie title as: %s %s" % (movie["title"], movie["release_date"])
            movie = tmdb.Movie(movie["id"])
            break
    #return the imdb id of the movie identified
    return movie.get_imdb_id()[2:]

def NZBtoIMDB(nzbName):
    nzbName = str(nzbName)
    a = nzbName.find('.cp(tt') + 6
    b = nzbName[a:].find(')') + a
    imdbid = nzbName[a:b]
    return imdbid

settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")
imdb_id = NZBtoIMDB(sys.argv[2])

if len(sys.argv) > 3:
    path = str(sys.argv[1])
    for r, d, f in os.walk(path):
        for files in f:
            if os.path.splitext(files)[1][1:] in valid_input_extensions:
                file = os.path.join(r, files)
                if imdbid = "":
                    try:
                        print "Going to guess the following files info: %s" % (os.path.basename(file))
                        imdb_id = FILEtoIMDB(os.path.basename(file))
                    except AttributeError:
                        print "Unable to accurately identify movie file %s" % (file)
                print "IMDB ID is: %s" % (imdb_id)
                print "Converting the following file: %s" % (os.path.basename(file))
                convert = MkvtoMp4(file, FFMPEG_PATH=settings.ffmpeg, FFPROBE_PATH=settings.ffprobe, delete=settings.delete, output_extension=settings.output_extension, relocate_moov=settings.relocate_moov, iOS=settings.iOS, awl=settings.awl, swl=settings.swl, adl=settings.adl, sdl=settings.sdl)
                try:
                    imdbmp4 = imdb_mp4(imdb_id)
                    imdbmp4.setHD(convert.width, convert.height)
                    imdbmp4.writeTags(convert.output)
                except AttributeError:
                    print "Unable to tag file, Couch Potato probably screwed up passing the IMDB ID"

# SABnzbd
if len(sys.argv) == 8:
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
{'fraction_non_alphanumeric': 0.08984550772461376, 'fraction_numerical': 0.01319934003299835, 'mean_word_length': 2.777903682719547, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '317924', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2077, 'n_words': 650}