def __init__(self, params): self.TMDb = tmdbv3api.TMDb() self.TMDb.api_key = params["apikey"] self.TMDb.language = params["language"] response = tmdbv3api.Configuration().info() if hasattr(response, "status_message"): raise Failed("TMDb Error: {}".format(response.status_message)) self.apikey = params["apikey"] self.language = params["language"] self.Movie = tmdbv3api.Movie() self.TV = tmdbv3api.TV() self.Discover = tmdbv3api.Discover() self.Trending = tmdbv3api.Trending() self.Keyword = tmdbv3api.Keyword() self.List = tmdbv3api.List() self.Company = tmdbv3api.Company() self.Network = tmdbv3api.Network() self.Collection = tmdbv3api.Collection() self.Person = tmdbv3api.Person() self.image_url = "https://image.tmdb.org/t/p/original"
def __init__(self, config, params): self.config = config self.TMDb = tmdbv3api.TMDb(session=self.config.session) self.TMDb.api_key = params["apikey"] self.TMDb.language = params["language"] try: response = tmdbv3api.Configuration().info() if hasattr(response, "status_message"): raise Failed(f"TMDb Error: {response.status_message}") except TMDbException as e: raise Failed(f"TMDb Error: {e}") self.apikey = params["apikey"] self.language = params["language"] self.Movie = tmdbv3api.Movie() self.TV = tmdbv3api.TV() self.Discover = tmdbv3api.Discover() self.Trending = tmdbv3api.Trending() self.Keyword = tmdbv3api.Keyword() self.List = tmdbv3api.List() self.Company = tmdbv3api.Company() self.Network = tmdbv3api.Network() self.Collection = tmdbv3api.Collection() self.Person = tmdbv3api.Person() self.image_url = "https://image.tmdb.org/t/p/original"
from mycroft import MycroftSkill, intent_file_handler from mycroft.util.log import getLogger from mycroft.util.format import pronounce_number, nice_date, nice_number import tmdbv3api __author__ = "*****@*****.**" __version__ = "0.1.2" LOGGER = getLogger(__name__) TMDB = { "tmdb": tmdbv3api.TMDb(), # "collection": tmdbv3api.Collection(), # "company": tmdbv3api.Company(), # "configuration": tmdbv3api.Configuration(), "discover": tmdbv3api.Discover(), "genre": tmdbv3api.Genre(), "movie": tmdbv3api.Movie(), "movie": tmdbv3api.Movie(), # "person": tmdbv3api.Person(), # "season": tmdbv3api.Season(), "tv": tmdbv3api.TV() } class Tmdb(MycroftSkill): def __init__(self): super(Tmdb, self).__init__(name="Tmdb") self.movieID = None self.movieDetails = None self.tvID = None
def personalized(request): discover = tb.Discover() movie = tb.Movie() if request.method == 'POST': var1 = request.POST['user_movie1'] var2 = request.POST['user_movie2'] var3 = request.POST['user_movie3'] var4 = request.POST['user_movie4'] var5 = request.POST['user_movie5'] movie_list = [] search1 = movie.search(var1) search2 = movie.search(var1) search3 = movie.search(var1) search4 = movie.search(var1) search5 = movie.search(var1) var1 = search1[0].id var2 = search2[0].id var3 = search3[0].id var4 = search4[0].id var5 = search5[0].id movie_list.append(var1) if var2 not in movie_list: movie_list.append(var2) if var3 not in movie_list: movie_list.append(var3) if var4 not in movie_list: movie_list.append(var4) if var5 not in movie_list: movie_list.append(var5) genre_count = { 878: 0, 18: 0, 28: 0, 35: 0, 53: 0, 27: 0, 10749: 0, 14: 0, 46: 0, 12: 0, 9648: 0 } for i in movie_list: m = movie.details(i) genre_id = [] for k in m.genres: genre_id.append(k["id"]) for j in genre_id: if j in genre_count.keys(): genre_count[j] += 1 genre_count = dict( sorted(genre_count.items(), key=operator.itemgetter(1), reverse=True)) all_counts = list(genre_count.values()) top3_genres = [] for i in range(3): for genre, count in genre_count.items(): if count == all_counts[i]: top3_genres.append(genre) popular = discover.discover_movies({ 'with_genres': top3_genres, 'sort_by': 'popularity.desc' }) string = [] poster = [] rec = {} for i in range(5): rec[popular[i].title] = popular[i].poster_path # string.append(popular[i].title) # poster.append(popular[i].poster_path) # string.append(popular[4].title) # poster.append(popular[4].poster_path) context = { 'rec': rec, #'poster':poster } return render(request, 'personalized.html', context) else: return render(request, 'personalized.html', {})
def get_response(request): response = {'status': None} if request.method == 'POST': data = json.loads(request.body.decode('utf-8')) message = data['message'] stop_words = set(stopwords.words('english')) word_tokens = word_tokenize(message) filtered_sentence = [w for w in word_tokens if not w in stop_words] filtered_sentence = [] for w in word_tokens: if w not in stop_words: filtered_sentence.append(w) #filtered_sentence is the list of processed words in the query chat_response = "No keyword used/Invalid response." if 'popular' in filtered_sentence: movie = tb.Movie() popular = movie.popular() string = "" for i in range(4): string += popular[i].title + ", " string += popular[4].title # chat_response = 'Some popular movies right now are ' + string genre_to_id = { "ScienceFiction": 878, "Drama": 18, "Action": 28, "Comedy": 35, "Thriller": 53, "Horror": 27, "Romance": 10749, "Fantasy": 14, "History": 46, "Adventure": 12, "Mystery": 9648 } if 'genre' in filtered_sentence: discover = tb.Discover() i = filtered_sentence.index('genre') string = '' for i in range(i + 1, len(filtered_sentence)): string += filtered_sentence[i] string2 = '' if string in genre_to_id.keys(): a = genre_to_id[string] popular = discover.discover_movies({"with_genres": a}) for i in range(4): string2 += popular[i].title + ", " string2 += popular[4].title chat_response = "Some popular " + string + " movies right now are " + string2 else: chat_response = "The query should be in the form of: \"suggest me some movie of genre g\" and g should be from the following: Science Fiction, Drama, Action, Comedy, Thriller, Horror, Romance, Fantasy, History, Adventure, Mystery" if 'kids' in filtered_sentence: discover = tb.Discover() popular = discover.discover_movies({ 'certification_country': 'US', 'certification.lte': 'G', 'sort_by': 'popularity.desc' }) string = '' for i in range(4): string += popular[i].title + ", " string += popular[4].title chat_response = 'Some popular kids movies right now are ' + string if 'review' in filtered_sentence: movie = tb.Movie() k = filtered_sentence.index('review') if 'movie' not in filtered_sentence[k:]: chat_response = 'The query should be in the form of: \"give review of movie x\"' else: i = filtered_sentence.index('movie') string = '' for i in range(i + 1, len(filtered_sentence)): string += filtered_sentence[i] string = string[:len(string) - 1] search = movie.search(string) chat_response = movie.reviews(search[0].id) chat = chat_response[0].entries count = 0 chat_response = '' for i in chat["content"]: if count != 300: chat_response += i count += 1 else: chat_response += ".... " + "\n\n For more check out: " + chat[ "url"] break if 'cast' in filtered_sentence: movie = tb.Movie() k = filtered_sentence.index('cast') if 'movie' not in filtered_sentence[k:]: chat_response = 'The query should be in the form of: \"cast of movie x\"' else: i = filtered_sentence.index('movie') string = '' for i in range(i + 1, len(filtered_sentence)): string += filtered_sentence[i] string = string[:len(string) - 1] search = movie.search(string) chat_response = movie.credits(search[0].id) chat = chat_response.cast chat_response = "Starring: " for i in chat: chat_response += i["name"] + " as " + i[ "character"] + " || " if 'popularity' in filtered_sentence: movie = tb.Movie() k = filtered_sentence.index('popularity') if 'movie' not in filtered_sentence[k:]: chat_response = 'The query should be in the form of: \"popularity of movie x\"' else: i = filtered_sentence.index('movie') string = '' for i in range(i + 1, len(filtered_sentence)): string += filtered_sentence[i] string = string[:len(string) - 1] search = movie.search(string) chat_response = search[0].popularity if 'tell' in filtered_sentence: movie = tb.Movie() k = filtered_sentence.index('tell') if 'movie' not in filtered_sentence[k:]: chat_response = 'The query should be in the form of: \"tell about movie x\"' else: i = filtered_sentence.index('movie') string = '' for i in range(i + 1, len(filtered_sentence)): string += filtered_sentence[i] string = string[:len(string) - 1] search = movie.search(string) chat_response = search[0].overview response['message'] = { 'text': chat_response, 'user': False, 'chat_bot': True } response['status'] = 'ok' else: response['error'] = 'no post data found' return HttpResponse(json.dumps(response), content_type="application/json")
from adapt.intent import IntentBuilder from mycroft.skills.core import MycroftSkill from mycroft.util.log import getLogger import requests __author__ = 'eClarity' LOGGER = getLogger(__name__) tmdb = TM.TMDb() collection = TM.Collection() company = TM.Company() configuration = TM.Configuration() discover = TM.Discover() genre = TM.Genre() movie = TM.Movie() person = TM.Person() season = TM.Season() tv = TM.TV() ##This will eventually move to the mycroft configuration class TmdbSkill(MycroftSkill): def __init__(self): super(TmdbSkill, self).__init__(name="TmdbSkill") tmdb.api_key = self.settings.get("v3api") tmdb.language = "en_US"