def searchOMDB(title, year=None, doSearch=False, ver=None):
	try:
		c=0
		res = None
		if doSearch:
			if Prefs["use_debug"]:
				Log("OMDB Search: Title:%s Year:%s" % (title,year))
			while res == None and c < 3:
				try:
					if year == None:
						res = omdb.search(title, c=Prefs['ca_api_key'], ver=ver)
					else:
						res = omdb.search('%s %s' % (title, year), c=Prefs['ca_api_key'], ver=ver)
				except:
					c += 1
					time.sleep(1.0)
		else:
			if Prefs["use_debug"]:
				Log("OMDB Request: Title:%s Year:%s" % (title,year))
			while res == None and c < 3:
				try:
					if year == None:
						res = omdb.request(t=title, r='json', c=Prefs['ca_api_key'], ver=ver, timeout=10)
					else:
						res = omdb.request(t=title, y=int(year), c=Prefs['ca_api_key'], ver=ver, r='json', timeout=10)
				except:
					c += 1
					time.sleep(1.0)

		return res
	except Exception as e:
		Log("interface.py>searchOMDB() >> : >>> %s" % (e))
		return None
Beispiel #2
0
def show_results(name):
    """Print on stdout the results obtained from omdb"""
    movies = omdb.search(name)
    if not movies:
        sys.exit(f'Movie "{name}" not found')
    for movie in omdb.search(name):
        m = omdb.imdbid(movie['imdb_id'])
        rating_str = 'No rating info'
        rating = get_rotten_tomato_rating(m)
        if rating:
            rating_str = f'Rotten Tomatoes {rating}'
        print(f'{m["title"]}/{m["year"]} ➡ {rating_str}')
        print('-' * 80)
Beispiel #3
0
def add_wishlist():

    if not g.user.is_confirmed():
        return redirect(url_for('admin.unconfirmed'))

    form = TitleSearchForm()
    addform = AddEntryForm()
    addform.wishlist.data = 1
    movies = []

    if request.args.get('title'):

        form.title.data = request.args.get('title')
        res = omdb.search(request.args.get('title'))

        for item in res:
            movie = {}
            movie['title'] = item['title']
            movie['year'] = item['year']
            if item['poster'] != 'N/A':
                movie['image'] = item['poster']
            movie['imdb_id'] = item['imdb_id']
            movies.append(movie)

    return render_template("admin/add.html", form=form, title="Add to Wishlist", subtitle="Search", \
                           movies=movies, addform = addform)
Beispiel #4
0
def add_wishlist():

    if not g.user.is_confirmed():
        return redirect(url_for('admin.unconfirmed'))

    form = TitleSearchForm()
    addform = AddEntryForm()
    addform.wishlist.data = 1
    movies = []

    if request.args.get('title'):

        form.title.data = request.args.get('title')
        res = omdb.search(request.args.get('title'))

        for item in res:
            movie = {}
            movie['title'] = item['title']
            movie['year'] = item['year']
            if item['poster'] != 'N/A':
                movie['image'] = item['poster']
            movie['imdb_id'] = item['imdb_id']
            movies.append(movie)

    return render_template("admin/add.html", form=form, title="Add to Wishlist", subtitle="Search", \
                           movies=movies, addform = addform)
def get_actor_rating(movie):
    #Get imdb movie id
    options = omdb.search(movie)
    imdb_id = 0
    year = 0
    #simply find most recent movie with the tite
    for option in options:
        if int(option["year"]) > year:
            year = int(option["year"])
            imdb_id = option["imdb_id"]

    res = omdb.request(i=imdb_id)
    data = res.json()
    if data["Response"] == "False":
        print "Movie not found"
        exit()

    actors = [a.strip() for a in data["Actors"].split(',')]
    directors = [d.strip() for d in data["Director"].split(',')]

    actor_scores = []
    director_scores = []

    for i in xrange(len(actors)):
        actor_scores.append((actors[i], get_score(actors[i], 100)))

    for i in xrange(len(directors)):
        director_scores.append((directors[i], get_score(directors[i], 100)))

    return actor_scores, director_scores, data["Ratings"]
def test_search_stem():
    s = 'stem'
    results = omdb.search(s)

    assert len(results) >= 30

    media_journal = {}
    media_videogame = {}

    for media in results:
        if media['Title'] == 'The STEM Journals':
            media_journal = media
        elif media['Title'] == 'Activision: STEM - in the Videogame Industry':
            media_videogame = media

    assert media_journal
    assert media_videogame

    media_videogame_details = omdb.get_by_id(media_videogame['imdbID'])

    assert media_videogame_details['Released'] == '23 Nov 2010'
    assert media_videogame_details['Director'] == 'Mike Feurstein'

    media_journal_details = omdb.get_by_title(media_journal['Title'])
    assert 'Science, Technology, Engineering and Math' in \
        media_journal_details['Plot']
    assert media_journal_details['Runtime'] == '22 min'
Beispiel #7
0
def getName(video):
    output = None
    videoFileNoExt = video.split('.')[
        0]  #/srv/samba/E5TB/Process/homerundvr/The Flash/Season 2/Run S01E01
    videoFileName = videoFileNoExt.split('/')[-1]
    split = videoFileName.split('-')
    if len(split) == 3:
        newname = str(split[0]) + "." + str(split[1]) + "." + str(
            split[2]) + ".mkv"
        output = str(dir.tvout) + str(newname)
    elif len(split) == 2:
        newname = str(split[0]) + "." + str(split[1]) + ".mkv"
        output = str(dir.tempout) + str(newname)
    elif len(split) == 1:
        search = omdb.search(videoFileName)
        newname = str(search[0].title) + " (" + str(search[0].year) + ").mkv"
        output = str(dir.movieout) + str(newname)
    elif len(split) > 3:
        newname = str(split[0]) + "." + str(split[1]) + ".mkv"
        output = str(dir.tempout) + str(newname)
    else:
        newname = videoFileName
        output = str(dir.manualout) + str(newname)
    temp = str(dir.tempout) + str(newname)
    setattr(dir, "temp", temp)
    return output
Beispiel #8
0
def imdb_search(movie_name):
    try:
        search = omdb.search(movie_name)
        first_match = search[0].title
        rating = omdb.get(title=first_match, tomatoes=True)
        return float(rating['imdb_rating'])
    except:
        return 0
Beispiel #9
0
def search(names):
    title = []
    invnames = []
    metascore = []
    for n in names:
        try:
            omdb.imdbid(omdb.search(n)[0].imdb_id).metascore
        except:
            invnames.append(n)
        else:
            title.append(omdb.search(n)[0].title)
            if not omdb.imdbid(omdb.search(n)[0].imdb_id).metascore:
                invnames.append(n)
            else:
                metascore.append(
                    omdb.imdbid(omdb.search(n)[0].imdb_id).metascore)
    return title, invnames, metascore
Beispiel #10
0
def find_omdb_movie(title, year):
    for movie in omdb.search(title):
        if movie.year[-1] == '-':
            movie.year = movie.year.replace('-', '')
        if movie.year == str(year):
            return omdb.imdbid(movie.imdb_id)
        print(movie.title)
    return np.nan
Beispiel #11
0
def getMovieData(movieList):
    movieData = {}
    i=0
    for item in movieList:
        i=i+1
        print i,":  "+item
        dataItem = omdb.search(str(item).rstrip())
        movieData.update({str(item).rstrip(): dataItem or ''})
    return movieData
def title_year_search(title,
                      year):  # лблБлб лЪлълцлўлџлАлўлблг лалљлЌлЉлўлЋлЮлўлЋ
    results = omdb.search(title, year=year)
    result_ids = []
    for i in results:
        result_ids.append(
            results[i]
            ['imdb_id'])  #лблБлб лЪлълцлўлџлАлўлблг лўлЮлћлЋлџлАлљлдлўл«
    return result_ids
Beispiel #13
0
def getMovieData(movieList):
    movieData = {}
    i=0
    for item in movieList:
        i=i+1
        print i,":  "+item
        dataItem = omdb.search(str(item).rstrip())
        movieData.update({str(item).rstrip(): dataItem or ''})
    return movieData
Beispiel #14
0
    def test_search_model_fields(self):
        expected_fields = [
            'title',
            'year',
            'type',
            'imdb_id'
        ]

        for item in omdb.search('True Grit'):
            self.assertEqual(set(item.keys()), set(expected_fields))
Beispiel #15
0
def write_movie_data(movies):
    """
    Write data about movies to single json file
    :param movies: list of movie titles
    :return: json file of movies data
    """
    all_movies = []
    lines = []
    for movie in movies:
        search = omdb.search(movie)
        if len(search) > 0:
            hit = search[0]
            # collect data for every movie
            if hit.type == 'movie':
                # list of all movies with links
                imdb_id = hit.imdb_id
                link = get_imdb_link(imdb_id)
                poster = hit.poster
                year = hit.year
                # list of all movies
                line = movie + "," + link + "\n"
                lines.append(line)
                # extract other movies data
                movie_data = {}
                movie_data['title'] = movie
                movie_data['id'] = link
                movie_data['poster'] = poster
                movie_data['imdb_id'] = imdb_id
                movie_data['year'] = year
                omdb_data = omdb.imdbid(imdb_id)
                movie_data['imdb_rating'] = get_attribute_value(omdb_data, 'imdb_rating')
                movie_data['genre'] = get_attribute_value(omdb_data, 'genre')
                movie_data['country'] = get_attribute_value(omdb_data, 'country')
                movie_data['released'] = get_attribute_value(omdb_data, 'released')
                movie_data['runtime'] = get_attribute_value(omdb_data, 'runtime')
                movie_data['language'] = get_attribute_value(omdb_data, 'language')
                movie_data['actors'] = get_attribute_value(omdb_data, 'actors')
                movie_data['plot'] = get_attribute_value(omdb_data, 'plot')
                all_movies.append(movie_data)
                print("Completed: " + movie)
            else:
                print("Skipped: " + movie)
        else:
            print("No results: " + movie)



    # write movies
    with open('movies.json', 'w') as fp:
        json.dump(all_movies, fp, indent=4)

    # write movies with links
    f = open('links.txt', 'w')
    f.writelines(lines)
    f.close()
Beispiel #16
0
def parse_omdb(data):
    omdb.set_default('apikey', 'b5e3df7f')
    results = omdb.search(data)

    ret = []

    for result in results:
        ret.append((result['title'], result['year'], result['imdb_id'],
                    result['poster']))

    return ret
Beispiel #17
0
def test_search_model_fields():
    expected_fields = [
        'title',
        'year',
        'type',
        'imdb_id',
        'poster'
    ]

    for result in omdb.search('True Grit'):
        assert set(result.keys()) == set(expected_fields)
def get_IMDB_id_from_title(title) :
    """
    title : string, titre de la série dont on recherche les infos
    renvoie l'id IMDB associée à cette série s'il existe, -1 sinon
    """
    info = omdb.search(title)
    series = []
    for dico in info :
        if dico['type'] == 'series' :
            series.append(dico)
    if len(series) == 0 : # si jamais la recherche ne renvoie pas de séries
        #print("Pas de séries pour ce titre")
        return -1
    return series[0]['imdb_id']
Beispiel #19
0
def interactive_mode():    
    results = []
    while  True:
        title = raw_input("> ")
        try:
            index = int(title)
            if index>=0 and index<len(results):
                details(results[index].title)
            else:
                print "?"
        except ValueError:
            results = omdb.search(title)
            for i,r in enumerate(results):
                rf = ASCIIProxy(r)
                print "%d: %20s   %4s" % (i, rf.title, rf.year)
def imdb_search(input_text):
    OMDB_API = os.environ.get("OMDB_API")
    message_list = []
    if len(input_text) == 0:
        text = "Command format: imdbs <title> [ ## <page> ]"
        message_list.append((text, []))
    else:
        options_list = input_text.split("##")
        # print options_list
        if len(options_list) > 1:
            om = omdb.search(options_list[0], page=options_list[1].strip())
        else:
            om = omdb.search(input_text)
        mn = min(len(om), 10)
        text = "Here's what I found: "
        attach = []
        d = dict()
        for i in range(mn):
            item = om[i]
            d["title"] = (d["title"] if "title" in d.keys() else
                          "") + item.title + " (" + item.year + ") \n"
        attach.append(d)
        message_list.append((text, attach))
    return message_list
Beispiel #21
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        title = self.request.GET.get('movie_title')
        context['slug'] = self.kwargs['slug']
        context['title'] = title

        omdb_result = omdb.search(title)

        for item in omdb_result:
            item['exists'] = MovieListItem.objects.filter(
                movie_list__user=self.request.user,
                imdb_id=item['imdb_id'],
                movie_list__slug=self.kwargs['slug']).exists()

        context['omdb'] = omdb_result

        return context
Beispiel #22
0
def find(mtitle, count):
    query = omdb.search(mtitle) 
    fincount = int(count)+2
    print('finalcount is ', fincount)
    data = dict()
    count = int(count)
    while True:
        try:
                res=query[count]
        except:
	        errormsg() 
        try:
                res = omdb.get(imdbid=str(res['imdb_id']), fullplot=False)
        except:
                errormsg()
        data.update({int(count):res['imdb_id']})
        count+= 1
        if(count > fincount):
            break
    return data
Beispiel #23
0
def get_imdb_info(query):
    """
    Gathers all imdb info on a movie/tv show
    """
    search = omdb.search(query)
    imdb_info = {}

    try:
        search = search[0].title
    except IndexError:
        print('An exception occured while searching for query')
    else:
        search_result = omdb.title(search)
        imdb_info = {
            'title': search_result.title,
            'cast': search_result.actors,
            'genre': search_result.genre,
            'plot': search_result.plot,
            'rating': search_result.imdb_rating,
            'poster': search_result.poster,
            'writer': search_result.writer,
        }

    return imdb_info
Beispiel #24
0
def test_empty_data():
    invalid = 'asdfghjkl'

    assert omdb.search(invalid) == []
    assert omdb.title(invalid) == {}
    assert omdb.imdbid(invalid) == {}
Beispiel #25
0
def movie_search(search_text):
    #ia = IMDb()
    #s_result = ia.search_movie(search_text)
    s_result = omdb.search(search_text)

    return render_template("movies.html", movies=s_result)
Beispiel #26
0
import omdb

movie = omdb.search('test')

print movie

Beispiel #27
0
def test_search():
    s = 'True Grit'
    results = omdb.search(s)

    assert results[0]['title'] == s
Beispiel #28
0
'''
Install below Python Module before You run this code.
>>> pip install omdb --upgrade
'''

import omdb
print("\n *** Movie Search in omdb.com *** \n")
api_key = '85772176'
omdb.set_default('apikey', api_key)
movie_name = input('\n Enter Movie Name to Search: ')
raw_data = omdb.search(movie_name)

for data in raw_data:
    print(
        f" Title: {data['title']} || Year: {data['year']} ||  IMDB ID: {data['imdb_id']} || Type: {data['type']}"
    )
def test_search():
    s = 'True Grit'
    results = omdb.search(s)
    assert results[0]['Title'] == s
Beispiel #30
0
    def test_search(self):
        s = 'True Grit'
        data = omdb.search(s)

        self.assertEqual(data[0].title, s)
def test_empty_data():
    invalid = 'asdfghjkl'

    assert omdb.search(invalid) == []
    assert omdb.get_by_id(invalid) == {}
    assert omdb.get_by_title(invalid) == {}
Beispiel #32
0
def search_results(search_term):
    results = str(omdb.search(search_term))
    return flask.render_template('starter.html',
                                 form=SearchForm(),
                                 results=results)
def getMovies(query):

	movies = omdb.search(query)

	return movies
Beispiel #34
0
def test_search_model_fields():
    expected_fields = ['title', 'year', 'type', 'imdb_id', 'poster']

    for result in omdb.search('True Grit'):
        assert set(result.keys()) == set(expected_fields)
 def com_omdb_search(self, media_title):
     """
     Search
     """
     omdb.search(media_title)
Beispiel #36
0
    def test_search(self):
        s = 'True Grit'
        data = omdb.search(s)

        self.assertEqual(data[0].title, s)
Beispiel #37
0
    def test_empty_data(self):
        invalid = 'asdfghjkl'

        self.assertEqual(omdb.search(invalid), [])
        self.assertEqual(omdb.title(invalid), {})
        self.assertEqual(omdb.imdbid(invalid), {})
Beispiel #38
0
    def test_empty_data(self):
        invalid = 'asdfghjkl'

        self.assertEqual(omdb.search(invalid), [])
        self.assertEqual(omdb.title(invalid), {})
        self.assertEqual(omdb.imdbid(invalid), {})
Beispiel #39
0
    def test_search_model_fields(self):
        expected_fields = ['title', 'year', 'type', 'imdb_id', 'poster']

        for item in omdb.search('True Grit'):
            self.assertEqual(set(item.keys()), set(expected_fields))
Beispiel #40
0
# 09 Nov 2017 | OMDb API Integration
'''
http://www.omdbapi.com/
https://github.com/dgilland/omdb.py
'''

import omdb

omdb.set_default('apikey', '6cf170d0')

# must use OMDb API parameters
res = omdb.request(t='True Grit', year=1969, r='json', apikey='6cf170d0')
#res = omdb.request(t='True Grit', year=1969, r='json')

#res = omdb.request(y=2017, r='json', apikey='6cf170d0')
print(res.content)

#src = omdb.search_movie(2017)
src = omdb.search(year=2017)
print(src)
Beispiel #41
0
import omdb

omdb.set_default('apikey', "d172df2f")
with open('moviedata.txt', 'a+', encoding='utf-8') as file:
    result = omdb.search('Canada') + omdb.search('University') + omdb.search(
        'Moncton') + omdb.search('Halifax') + omdb.search(
            'Toronto') + omdb.search('Vancouver') + omdb.search(
                'Alberta') + omdb.search('Niagara')
    for i in result:
        datanews = "title : " + i['title'] + " year : " + i[
            'year'] + " imdb_id : " + i['imdb_id'] + " type : " + i[
                'type'] + " poster : " + i['poster'] + "\n"
        file.write(datanews)
    ('the final sacrifice', None),
    ('surf nazis must die', 'https://www.youtube.com/watch?v=Q8LV1S2q2GA'),
    ('breaking away', 'https://www.youtube.com/watch?v=J1jzs6dk4bs'),
    ('tron', 'https://www.youtube.com/watch?v=L9szn1QQfas'),
    ('ski patrol', 'https://www.youtube.com/watch?v=OTyp09bkZbk')
]

print 'Assembling movie data...'

for favorite in FAVORITES:
    print ' Fetching metadata for ' + favorite[0] + '...'

    title = favorite[0]
    trailer = favorite[1]

    imdb_movie = omdb.search(title)
    if imdb_movie['Poster'] == 'N/A':
        imdb_movie['Poster'] = None

    if imdb_movie is not None:
        movie = media.Movie(
            title=imdb_movie['Title'],
            trailer_youtube_url=trailer,
            poster_image_url=imdb_movie['Poster'],
            rating=imdb_movie['Rated'],
            release_date=imdb_movie['Released'],
            plot_summary=imdb_movie['Plot'],
            running_time=imdb_movie['Runtime'],
            popularity=imdb_movie['imdbRating'])
        MOVIES.append(movie)