11# -*- coding: utf-8 -*-
2- from attrdict import AttrDict
2+ from concurrent .futures import ThreadPoolExecutor
3+
34import imdbpie
5+ from attrdict import AttrDict
46
57from .logging import log
68
@@ -85,6 +87,8 @@ def get_rating(self, imdb_id):
8587 def search (self , title ):
8688 log .debug ("Searching IMDb for '{}'" , title )
8789 results = self .imdb .search_for_title (title )
90+ if len (results ) == 1 :
91+ return self .get_info (results [0 ]['imdb_id' ])
8892
8993 print ("Results:" )
9094 for i , movie in enumerate (results ):
@@ -110,11 +114,19 @@ def search(self, title):
110114 return self .get_info (result ['imdb_id' ])
111115
112116 def get_info (self , imdb_id ):
113- movie = AttrDict (self .imdb .get_title (imdb_id ))
114- movie .credits = self .imdb .get_title_credits (imdb_id )['credits' ]
115- movie .stars = self .imdb .get_title_auxiliary (imdb_id )['principals' ]
116- movie .genres = self .imdb .get_title_genres (imdb_id )['genres' ]
117- title_versions = self .imdb .get_title_versions (imdb_id )
117+ log .debug ('getinfo' )
118+ with ThreadPoolExecutor () as executor :
119+ f_movie = executor .submit (self .imdb .get_title , imdb_id )
120+ f_credits = executor .submit (self .imdb .get_title_credits , imdb_id )
121+ f_aux = executor .submit (self .imdb .get_title_auxiliary , imdb_id )
122+ f_genres = executor .submit (self .imdb .get_title_genres , imdb_id )
123+ f_versions = executor .submit (self .imdb .get_title_versions , imdb_id )
124+
125+ movie = AttrDict (f_movie .result ())
126+ movie .credits = f_credits .result ()['credits' ]
127+ movie .stars = f_aux .result ()['principals' ]
128+ movie .genres = f_genres .result ()['genres' ]
129+ title_versions = f_versions .result ()
118130 movie .titles = {item ["region" ]: item ["title" ]
119131 for item in title_versions ['alternateTitles' ]
120132 if "region" in item and "title" in item }
0 commit comments