示例#1
0
        def get_info_from_search():
            search_data = tools.get_tmdb_search_data(tmdb_api_key,
                                                     self.movie_title)

            if search_data is None or search_data['total_results'] == 0:
                return False

            movie_data = None
            movie_backup_data = None

            if self.movie_release_year is None:
                movie_data = search_data['results'][0]
            else:

                for result in search_data['results'][:5]:
                    if movie_data is None:
                        if str(self.movie_release_year
                               ) == result['release_date'][:4]:
                            movie_data = result
                        elif result['release_date'][6:8] in ['09', '10', '11', '12'] \
                                and str(self.movie_release_year - 1) == result['release_date'][:4]:
                            movie_data = result
                        elif result['release_date'][6:8] in ['01', '02', '03', '04'] \
                                and str(self.movie_release_year + 1) == result['release_date'][:4]:
                            movie_data = result
                    elif movie_backup_data is None:
                        if str(self.movie_release_year -
                               1) == result['release_date'][:4]:
                            movie_backup_data = result

                        elif str(self.movie_release_year +
                                 1) == result['release_date'][:4]:
                            movie_backup_data = result

                if movie_data is None and movie_backup_data is not None:
                    print(
                        'None of the search results had a correct release year, picking the next best result'
                    )
                    movie_data = movie_backup_data

                if movie_data is None:
                    movie_data = search_data['results'][0]

            self.tmdb_id = movie_data['id']
            self.movie_title = tools.get_clean_string(movie_data['title'])
            self.movie_original_title = tools.get_clean_string(
                movie_data['original_title'])
            self.movie_title_keywords = tools.get_keyword_list(
                movie_data['title'])
            self.movie_original_title_keywords = tools.get_keyword_list(
                movie_data['original_title'])

            if len(movie_data['release_date'][:4]) == 4:
                self.movie_release_year = int(movie_data['release_date'][:4])
            else:
                self.movie_release_year = None
            return True
        def get_info_from_search():
            search_data = tools.get_tmdb_search_data(tmdb_api_key, self.movie_title)

            if search_data is None or search_data['total_results'] == 0:
                return False

            movie_data = None
            movie_backup_data = None

            if self.movie_release_year is None:
                movie_data = search_data['results'][0]
            else:

                for result in search_data['results'][:5]:
                    if movie_data is None:
                        if str(self.movie_release_year) == result['release_date'][:4]:
                            movie_data = result
                        elif result['release_date'][6:8] in ['09', '10', '11', '12'] \
                                and str(self.movie_release_year - 1) == result['release_date'][:4]:
                            movie_data = result
                        elif result['release_date'][6:8] in ['01', '02', '03', '04'] \
                                and str(self.movie_release_year + 1) == result['release_date'][:4]:
                            movie_data = result
                    elif movie_backup_data is None:
                        if str(self.movie_release_year - 1) == result['release_date'][:4]:
                            movie_backup_data = result

                        elif str(self.movie_release_year + 1) == result['release_date'][:4]:
                            movie_backup_data = result

                if movie_data is None and movie_backup_data is not None:
                    print('None of the search results had a correct release year, picking the next best result')
                    movie_data = movie_backup_data

                if movie_data is None:
                    movie_data = search_data['results'][0]

            self.tmdb_id = movie_data['id']
            self.movie_title = tools.get_clean_string(movie_data['title'])
            self.movie_original_title = tools.get_clean_string(movie_data['original_title'])
            self.movie_title_keywords = tools.get_keyword_list(movie_data['title'])
            self.movie_original_title_keywords = tools.get_keyword_list(movie_data['original_title'])

            if len(movie_data['release_date'][:4]) == 4:
                self.movie_release_year = int(movie_data['release_date'][:4])
            else:
                self.movie_release_year = None
            return True
示例#3
0
        def find_similar_results():

            def find_by_tmdb_id():
                similar_movies_data = list()
                movie_found = False

                for result in search_data['results']:

                    if self.tmdb_id == result['id']:
                        movie_found = True
                    else:
                        similar_movies_data.append(result)

                if movie_found:
                    return similar_movies_data
                else:
                    return None

            def find_by_release_year():
                similar_movies_data = list()
                movie_found = False
                backup_found = False

                for result in search_data['results']:

                    if not movie_found and str(self.movie_release_year) == result['release_date'][:4]:
                        movie_found = True
                        continue

                    elif not backup_found:

                        if result['release_date'][6:8] in ['09', '10', '11', '12'] \
                                and str(self.movie_release_year - 1) == result['release_date'][:4]:
                            backup_found = True

                        elif result['release_date'][6:8] in ['01', '02', '03'] \
                                and str(self.movie_release_year + 1 == result['release_date'][:4]):
                            backup_found = True

                    if len(similar_movies_data) < 5:
                        similar_movies_data.append(result)

                if movie_found or backup_found:
                    return similar_movies_data
                else:
                    return None

            search_data = tools.get_tmdb_search_data(tmdb_api_key, self.movie_title)

            if search_data is None or search_data['total_results'] == 0:
                return list()

            ret = find_by_tmdb_id()
            if ret is not None:
                return ret[:5]

            if self.movie_release_year is None:
                return search_data['results'][1:6]

            ret = find_by_release_year()
            if ret is not None:
                return ret[:5]

            return None
        if not os.path.isdir(os.path.join(library, folder)):
            continue
        handle_directory(os.path.join(library, folder))


c = configparser.ConfigParser()
c.read('default_config.cfg')

tmp_folder = os.path.join(os.path.dirname(sys.argv[0]), 'tmp')

configs = os.path.join(os.path.dirname(sys.argv[0]), 'extra_configs')
configs_content = os.listdir(configs)

records = os.path.join(os.path.dirname(sys.argv[0]), 'records')

result = tools.get_tmdb_search_data(c.get('SETTINGS', 'tmdb_api_key'),
                                    'star wars')
if result is None:
    print('Warning: No working TMDB api key was specified.')
    time.sleep(10)
    has_tmdb_key = False
else:
    has_tmdb_key = True

if args.directory:
    handle_directory(args.directory)
elif args.library:
    handle_library(args.library)
else:
    print('please specify a directory or a library to search extras for')

try:
        def find_similar_results():

            def find_by_tmdb_id():
                similar_movies_data = list()
                movie_found = False

                for result in search_data['results']:

                    if self.tmdb_id == result['id']:
                        movie_found = True
                    else:
                        similar_movies_data.append(result)

                if movie_found:
                    return similar_movies_data
                else:
                    return None

            def find_by_release_year():
                similar_movies_data = list()
                movie_found = False
                backup_found = False

                for result in search_data['results']:

                    if not movie_found and str(self.movie_release_year) == result['release_date'][:4]:
                        movie_found = True
                        continue

                    elif not backup_found:

                        if result['release_date'][6:8] in ['09', '10', '11', '12'] \
                                and str(self.movie_release_year - 1) == result['release_date'][:4]:
                            backup_found = True

                        elif result['release_date'][6:8] in ['01', '02', '03'] \
                                and str(self.movie_release_year + 1 == result['release_date'][:4]):
                            backup_found = True

                    if len(similar_movies_data) < 5:
                        similar_movies_data.append(result)

                if movie_found or backup_found:
                    return similar_movies_data
                else:
                    return None

            search_data = tools.get_tmdb_search_data(tmdb_api_key, self.movie_title)

            if search_data is None or search_data['total_results'] == 0:
                return list()

            ret = find_by_tmdb_id()
            if ret is not None:
                return ret[:5]

            if self.movie_release_year is None:
                return search_data['results'][1:6]

            ret = find_by_release_year()
            if ret is not None:
                return ret[:5]

            return None