def test_unexisting_movie(self): if sys.version_info[:2] >= (2, 7): with self.assertRaises(LookupError): movie_info.get_movie_info("There's no way that movie exists", "1968") else: self.assertRaises( LookupError, lambda: movie_info.get_movie_info( "There's no way that movie exists", "1968"))
def test_unexisting_movie(self): if sys.version_info[:2] >= (2, 7): with self.assertRaises(LookupError): movie_info.get_movie_info( "There's no way that movie exists", "1968" ) else: self.assertRaises( LookupError, lambda: movie_info.get_movie_info( "There's no way that movie exists", "1968" ) )
def valid_Movie(self, vlcTitle, vlcYear, vlcDuration): try: # Get Movie info movie = movie_info.get_movie_info(vlcTitle, vlcYear) # Compare Movie runtime against VLC runtime regex = re.compile('^((?P<hour>[0-9]{1,2}).*?h)' + '?.*?(?P<min>[0-9]+).*?min?', re.IGNORECASE | re.MULTILINE) r = regex.search(movie['Runtime']) try: timeh = 0 if r.group('hour') is None else int(r.group('hour')) timem = 0 if r.group('min') is None else int(r.group('min')) time = timeh * 60 * 60 + timem * 60 except: self.log.debug("valid_Movie::unable to compute the duration", exc_info=sys.exc_info()) return False # Verify that the VLC duration is within 5 minutes of the # official duration if (vlcDuration >= time - 300) and (vlcDuration <= time + 300): self.cache["movie_info"] = deepcopy(movie) return True else: self.log.debug("valid_Movie::time range not respected " + "(%d +-300 != %d)" % (time, vlcDuration)) except: self.log.debug("valid_Movie::no valid title found", exc_info=sys.exc_info()) return False return False
def valid_Movie(self, vlcTitle, vlcYear, vlcDuration): try: # Get Movie info movie = movie_info.get_movie_info(vlcTitle, vlcYear) # Compare Movie runtime against VLC runtime regex = re.compile( '^((?P<hour>[0-9]{1,2}).*?h)' + '?.*?(?P<min>[0-9]+).*?min?', re.IGNORECASE | re.MULTILINE) r = regex.search(movie['Runtime']) try: timeh = 0 if r.group('hour') is None else int(r.group('hour')) timem = 0 if r.group('min') is None else int(r.group('min')) time = timeh * 60 * 60 + timem * 60 except: self.log.debug("valid_Movie::unable to compute the duration", exc_info=sys.exc_info()) return False # Verify that the VLC duration is within 5 minutes of the # official duration if (vlcDuration >= time - 300) and (vlcDuration <= time + 300): self.cache["movie_info"] = deepcopy(movie) return True else: self.log.debug("valid_Movie::time range not respected " + "(%d +-300 != %d)" % (time, vlcDuration)) except: self.log.debug("valid_Movie::no valid title found", exc_info=sys.exc_info()) return False return False
def get_info_from_omdb(): mn = request.form['movie'] type = request.form['type'] year = request.form['year'] data = movie_info.get_movie_info(mn, year) contents = {'type': type, 'movie': data} recommend_movie.init_feedback(mn, int(year)) resp = Response(type=response_type['movie_info'], status=1, message=mn, contents=contents).to_dict() return jsonify(resp)
def _movie_info_test(self, expected, searchTitle, searchYear=''): search = movie_info.get_movie_info(searchTitle, searchYear) search = self._cleanMovieDict(search) if 'Plot' in search: if 'Plot' in expected: ratio = fuzz.partial_ratio(expected['Plot'], search['Plot']) self.assertEqual(ratio > 90, True) del expected['Plot'] del search['Plot'] self.assertEqual(expected, search)
def get_Movie(self, vlc): try: now_playing = vlc.get_title("^(?!status change:)(?P<Title>.+?) ?(?:[[(]?(?P<Year>[0-9]{4})[])]?.*)? *\.[a-z]{2,4}") title = now_playing.group('Title') + ' ' + ifnull(now_playing.group('Year'), '') duration = int(vlc.get_length()) playtime = int(vlc.get_time()) percentage = playtime*100/duration if self.valid_Movie(title, duration): movie = movie_info.get_movie_info(vlcTitle) year = movie['Year'] return set_video(False, title, year, duration, percentage, -1, -1) return except: self.log.debug("No matching movie found for video playing") return
def valid_Movie(self, vlcTitle, vlcDuration): try: # Get Movie info movie = movie_info.get_movie_info(vlcTitle) # Compare Movie runtime against VLC runtime regex = re.compile('^((?P<hour>[0-9]{1,2}).*?h)?.*?(?P<min>[0-9]{1,2}).*?min?',re.IGNORECASE|re.MULTILINE) r = regex.search(movie['Runtime']) try: time = int(r.group('hour'))*60*60+int(r.group('min'))*60 except: return False if (vlcDuration == time - 300) or (vlcDuration == time + 300): return True except: self.log.debug("Valid_Movie -> no valid title found") return False return False
def get_Movie(self, vlc): try: now_playing = vlc.get_title( "^(?!status change:)(?P<Title>.+?) ?(?:[[(]?(?P<Year>[0-9]{4})[])]?.*)? *\.[a-z]{2,4}" ) title = now_playing.group('Title') + ' ' + ifnull( now_playing.group('Year'), '') duration = int(vlc.get_length()) playtime = int(vlc.get_time()) percentage = playtime * 100 / duration if self.valid_Movie(title, duration): movie = movie_info.get_movie_info(vlcTitle) year = movie['Year'] return set_video(False, title, year, duration, percentage, -1, -1) return except: self.log.debug("No matching movie found for video playing") return
def valid_Movie(self, vlcFilePath, vlcTitle, vlcYear, vlcDuration): try: # Get Movie info movie = movie_info.get_movie_info( vlcFilePath, vlcTitle, vlcYear, vlcDuration) # Compare Movie runtime against VLC runtime time = movie['Runtime'] # Verify that the VLC duration is within 5 minutes of the # official duration if (vlcDuration >= time - 300) and (vlcDuration <= time + 300): self.cache["movie_info"] = deepcopy(movie) return True else: self.log.debug("valid_Movie::time range not respected " + "(%d +-300 != %d)" % (time, vlcDuration)) except: self.log.debug("valid_Movie::no valid title found", exc_info=sys.exc_info()) return False return False
def valid_Movie(self, vlcTitle, vlcDuration): try: # Get Movie info movie = movie_info.get_movie_info(vlcTitle) # Compare Movie runtime against VLC runtime regex = re.compile( '^((?P<hour>[0-9]{1,2}).*?h)?.*?(?P<min>[0-9]{1,2}).*?min?', re.IGNORECASE | re.MULTILINE) r = regex.search(movie['Runtime']) try: time = int(r.group('hour')) * 60 * 60 + int( r.group('min')) * 60 except: return False if (vlcDuration == time - 300) or (vlcDuration == time + 300): return True except: self.log.debug("Valid_Movie -> no valid title found") return False return False
def _movie_info_test(self, expected, searchTitle, searchYear='', searchDuration=None): search = movie_info.get_movie_info( None, searchTitle, searchYear, searchDuration ) search = self._cleanMovieDict(search) if 'Plot' in search: if 'Plot' in expected: ratio = fuzz.partial_ratio(expected['Plot'], search['Plot']) self.assertEqual( ratio > 90, True, pprint.pformat(search, indent=4) ) del expected['Plot'] del search['Plot'] self.assertEqual(expected, search)
def send_message(): message = request.form['content'] project_id = os.getenv("DIALOGFLOW_PROJECT_ID") fulfillment_text, action = detect_intent_texts(project_id, "unique", message, 'en') type, contents, msg = '', None, '' # return recommend movie list if action == 'recommendation': state = recommend_movie.get_user_rs_state() # personalized recommendation if state == '1': recommend_movie.store_user_profile() search_results = recommend_movie.recommand_movies() contents = {'playlists': search_results} msg = 'You can tell me the number or touch the option to choose the recommended movie' type = 'movielist' # recommend according to the movie's hotness else: search_results = recommend_movie.recommond_hotest_movie() contents = {'playlists': search_results} msg = 'You can tell me the number or touch the option to choose the recommended movie' type = 'movielist' # reply fulfillment_text set in dialogflow elif action == 'input.unknown': msg = fulfillment_text type = 'text' contents = {} elif action[:5] == "movie": # ERROR: multiple movies if fulfillment_text == "0": msg = 'only one movie permitted' type = 'text' # give information for the movie else: if action == "movie.trailer": movie_name, type_of_info = fulfillment_text.split("#") video_info = video_service.youtube_search(movie_name)[0] type = 'video' msg = more_human.wrong_movie_response() contents = video_info else: movie_name, type_of_info = fulfillment_text.split("#") moive_data = movie_info.get_movie_info(movie_name) contents = { 'type': movie_info_type[type_of_info], 'movie': moive_data } msg = more_human.wrong_movie_response() type = 'movie_info' year = movie_info.get_movie_year(movie_name) recommend_movie.init_feedback(movie_name, int(year)) # based on the movie name user given in last step, generate search result list elif action == "notasexpected": movie_name, type_of_info = fulfillment_text.split('#') search_results = movie_info.find_results(movie_name, type_of_info) msg = 'You can tell me the number or touch the option to choose the movie you expected' contents = {'playlists': search_results} type = 'movielist' # select movie from search result list elif action == "select.movie": # ERROR: input multiple number if len(fulfillment_text) > 10: msg = fulfillment_text type = "text" # base on the number user choose, return the corresponding movie info else: number, type_of_info = fulfillment_text.split('#') number = int(number) contents = Selection(response_type["movie_info"], number, type_of_info).to_dict() msg = more_human.movie_selection_response() type = 'list_selection' # select movie from result recommendation list elif action == "select.rs": # ERROR: input multiple number if len(fulfillment_text) > 10: msg = fulfillment_text type = "text" # base on the number user choose, return the corresponding movie info else: number, type_of_info = fulfillment_text, 'overview' number = int(number) contents = Selection(response_type["movie_info"], number, type_of_info).to_dict() msg = more_human.movie_selection_response() type = 'list_selection' # small talk elif "smalltalk" in action: type = "text" msg = fulfillment_text + " you can ask me information about movies(details,actors,rating etc) and play music for you by asking the artists or their albums. i can also obtain the health data from your Apple Watch if you have one. Oh!dont't forget to connect your LIFX buble so you can control it from here" contents = fulfillment_text # defalut welcome elif action == "input.welcome": type = "text" msg = fulfillment_text + " you can ask me information about movies(details,actors,rating etc) and play music for you by asking the artists or their albums. i can also obtain the health data from your Apple Watch if you have one. Oh!dont't forget to connect your LIFX buble so you can control it from here" contents = fulfillment_text # health elif action == "health": health_type, start_date, end_date = fulfillment_text.split('#') if health_type == 'None': msg = 'could you say that again?' type = 'text' contents = {} else: msg = health_record.generate_res(health_type, start_date, end_date) type = 'health' health_type = health_type.split(',') contents = { 'start': start_date, 'end': end_date, 'type': health_info_type[health_type[0]] } # player function elif action[:6] == "player": contents = Music_Instruction( music_instruction[action_to_type[fulfillment_text]]).to_dict() type = "music_control" msg = more_human.music_instrction_response( music_instruction[action_to_type[fulfillment_text]]) # user's own playlists list elif action == 'music.playlist': contents = music_player.show_playlist() msg = more_human.music_playlist_response() type = "playlist" # top Ten elif action == "music.topten": # ERROR: multiple singers if fulfillment_text == '0': msg = 'one singer only.' type = "text" # return a certain singer's top-ten songs list else: contents = music_player.show_top_tracks(fulfillment_text) msg = more_human.music_topten_response(fulfillment_text) type = "track" # albums elif action == "music.album": # ERROR: multiple singers if fulfillment_text == '0': msg = 'one singer only.' type = "text" # return one singer's albums list else: contents = music_player.show_artist_albums(fulfillment_text) msg = more_human.music_album_response(fulfillment_text) type = "album" # selection in music part elif action == "select.music": # ERROR: multiple numbers if len(fulfillment_text) > 5: msg = fulfillment_text type = "text" # return the number user selected else: contents = Selection(response_type["playlist"], fulfillment_text).to_dict() type = 'list_selection' else: msg = fulfillment_text type = 'text' response_text = Response(type=response_type[type], message=msg, status=1, contents=contents).to_dict() # state == 1 ? return jsonify(response_text)
def _movie_info_test(self, expected, searchTitle, searchYear=''): search = movie_info.get_movie_info(searchTitle, searchYear) search = self._cleanMovieDict(search) self.assertEqual(expected, search)