Git Product home page Git Product logo

Comments (5)

thorian93 avatar thorian93 commented on May 9, 2024

I want to emphasize that as an open source project I think it would be great to also support open knowledge platforms and make people aware of such solutions.
I myself ditched IMDB as soon as I learned that it is owned by Amazon. Not meaning to flame here, but for me that was a show stopper. Projecting that to other people this might be a concern for the success of this tool, be it a rather small one.

from hypnotix.

kodi-rc avatar kodi-rc commented on May 9, 2024

And the result of the tmdbsimple library can be provided in other languages, not only in english.

import tmdbsimple as tmdb
tmdb.API_KEY = 'myKey*******'
tmdb_lang = 'pt-BR' #my language

#channel.title = 'The Avengers'
channel.title = 'Os Vingadores'


search = tmdb.Search()
r_films = search.movie(query=channel.title, language=tmdb_lang)


if len(r_films['results']) > 1:
	lstname = []
	for i in range(len(r_films['results'])):
		lstname.append(r_films['results'][i]['title'])

	#display a list of all results, for users to choose the best option
	print(str(lstname))
	ret = ?? #integer : user choice
else:
	ret = 0

if ret > -1
	film_id = r_films['results'][ret]['id']
	r_movie_info = tmdb.Movies(film_id).info(language=tmdb_lang)
	overview = r_movie_info['overview']

	credits_movie = tmdb.Movies(film_id).credits(language=tmdb_lang)

	r_trailer = tmdb.Movies(film_id).videos(language=tmdb_lang)
	if len(r_trailer['results']) > 0:
		for tag in r_trailer['results']:
			name = tmdb_lang + ' - ' + tag['name']
			trailer_name.append(name)
			trailer_key.append(tag['key'])
	
	r_trailer_en = tmdb.Movies(texto).videos()
	if len(r_trailer_en['results']) > 0:
		for tag in r_trailer_en['results']:
			trailer_name.append(tag['name'])
			trailer_key.append(tag['key'])

else:
	print('Movie not registered in database!')

When there is no result for my language, I make another query without specifying a language to make the query in English:

if overview == '' or overview == 'null' or overview == '0':
	r_movie_info_en = tmdb.Movies(film_id).info()
	overview = r_movie_info_en['overview']

from hypnotix.

kodi-rc avatar kodi-rc commented on May 9, 2024

An additional option besides the automatic search, would also be to create a tag with the id of the movie / series on TMDB.
ex: tvg-tmdb = "299534"
https://www.themoviedb.org/movie/299534-avengers-endgame?language=pt-BR

#EXTINF:0 tvg-name="Vingadores: Ultimato - [2019] [1080p]" tvg-logo="https://****.jpg" tvg-tmdb="299534" group-title="VOD Dublado-Acao",Vingadores: Ultimato
https://*****


With the function below I can get url of the image, synopsis of the movie and link to the movie trailer:
I considered that the link of the trailers inserted in TMDB are on youtube. It can be changed in the code to see which host of the trailer, as TMDB informs the host in the videos method.

import os
os.environ["PYTHONIOENCODING"] = "utf-8"

import tmdbsimple as tmdb
myKey = '***' #add an option for the user to put their TMDB key
tmdb.API_KEY = myKey
TMDB_LANG = 'pt-BR' #User local language

URLYOUTUBE = 'https://www.youtube.com/watch?v='
URLTMDBPOSTER = 'https://image.tmdb.org/t/p/w'
URLNOPOSTER = 'https://nocover.png'

def movie_detail(tvg_tmdbid='', postersize='200'):
    '''
    tvg_tmdbid = Movie id on TMDB website
        type = string
        ex: Os Vingadores : https://www.themoviedb.org/movie/24428-the-avengers?language=pt-BR
        tvg_tmdbid = '24428'

    postersize = Poster image width
        type = string
        ex: 200 , 300, 500 ...
    '''
    if tvg_tmdbid != None and str(tvg_tmdbid).strip() != '':
        tmdb_movie = tmdb.Movies(tvg_tmdbid)
        tmdb_infos = tmdb_movie.info(language=TMDB_LANG)

        originaltitle = tmdb_infos['original_title']
        print(f'TMDB Movie ID: {tvg_tmdbid}\n'
            f'Original Title: {originaltitle}\n')

        poster = ''
        posterpath = tmdb_infos['poster_path']
        if posterpath != '' and posterpath != 'null' and posterpath != '0' and posterpath != None:
            poster = URLTMDBPOSTER + postersize + posterpath
        else:
            poster = URLNOPOSTER
        print(f'Poster: {poster}\n')

        overview = ''
        overview_mylang  = tmdb_infos['overview']
        overview_mylang = overview_mylang.strip()
        if overview_mylang != '' and overview_mylang != 'null' and overview_mylang != '0' and overview_mylang != None:
            overview = overview_mylang
        else:
            overview_en  = tmdb_movie.info()['overview']
            overview_en = overview_en.strip()
            if overview_en != '' and overview_en != 'null' and overview_en != '0':
                overview = f'Only in English - {overview_en}'
            else:
                overview = ''

        if overview != '':
            overview = overview
            print(f'Overview: {overview}\n')
        else:
            print('Overview not available on TMD\n')


        key_trailer = ''
        lang_trailer = TMDB_LANG.upper()
        trailers_mylang = tmdb_movie.videos(language=TMDB_LANG)['results']
        if len(trailers_mylang) > 0:
            key_trailer = trailers_mylang[0]['key']
            key_trailer = key_trailer.strip()
        else:
            trailers_en = tmdb_movie.videos()['results']
            if len(trailers_en) > 0:
                key_trailer = trailers_en[0]['key']
                key_trailer = key_trailer.strip()
                lang_trailer = 'EN'

        if key_trailer != '':
            print(f'Trailer: {lang_trailer} | {URLYOUTUBE}{key_trailer}\n')
        else:
            print('Trailer not available on TMD\n')

    else:
        print('TMDB Movie ID not informed\n')

    print('==========================\n')

#poster: ok, overview: pt-BR , trailer: pt-BR
movie_detail('24428')

#poster: ok, overview: pt-BR , trailer: English
movie_detail('89')

#poster: ok, overview: English , trailer: English
movie_detail('438890')

#poster: nothing, overview: English , trailer: nothing
movie_detail('740437')

### Search results for the 4 movies above

TMDB Movie ID: 24428
Original Title: The Avengers

Poster: https://image.tmdb.org/t/p/w200/u49fzmIJHkb1H4oGFTXtBGgaUS1.jpg

Overview: Loki, o irmão de Thor, ganha acesso ao poder ilimitado do cubo cósmico ao roubá-lo de dentro das instalações da S.H.I.E.L.D. Nick Fury, o diretor desta agência internacional que mantém a paz, logo reúne os únicos super-heróis que serão capazes de defender a Terra de ameaças sem precedentes. Homem de Ferro, Capitão América, Hulk, Thor, Viúva Negra e Gavião Arqueiro formam o time dos sonhos de Fury, mas eles precisam aprender a colocar os egos de lado e agir como um grupo em prol da humanidade.

Trailer: PT-BR | https://www.youtube.com/watch?v=6Y6zOSn8ff4

==========================

TMDB Movie ID: 89
Original Title: Indiana Jones and the Last Crusade

Poster: https://image.tmdb.org/t/p/w200/vTBem2ZGmLKVgaD3EtJUfMQ9AH1.jpg

Overview: O arqueólogo Indiana Jones (Harrisson Ford) tem acesso à um misterioso envelope que contém informações sobre a localização do lendário Santo Graal, o cálice que Jesus Cristo teria utilizado na Última Ceia. Quando seu pai, o professor Henry Jones (Sean Connery), é sequestrado pelos nazistas, o aventureiro irá embarcar numa missão perigosa para salvá-lo e impedir que a relíquia sagrada caia em mãos erradas.

Trailer: EN | https://www.youtube.com/watch?v=gNXQQbgK_cc

==========================

TMDB Movie ID: 438890
Original Title: 仮面ライダー 世界に駆ける

Poster: https://image.tmdb.org/t/p/w200/n0AQnPzsTAKUm4OhL314SbUuw3y.jpg

Overview: Only in English - In the film, the Crisis Empire devise a plan to defeat Kohtaro Minami by reverting him back to his old form of Kamen Rider Black and sending out several revived monsters after him. However, Kamen Rider Black is assisted by another RX, who used a time warp to help his past self. The two are joined by RX's alternate forms of Robo Rider and Bio Rider and the four Kamen Riders combine their powers to defeat the revived monsters.

Trailer: EN | https://www.youtube.com/watch?v=gc6qG-KHWJA

==========================

TMDB Movie ID: 740437
Original Title: A Porta

Poster: https://nocover.png

Overview: Only in English - A group of friends have to deal with the consequences of a game they played.

Trailer not available on TMD

==========================

from hypnotix.

kodi-rc avatar kodi-rc commented on May 9, 2024

### Here the function for the Series

import os
os.environ["PYTHONIOENCODING"] = "utf-8"

import tmdbsimple as tmdb
myKey = '***' #add an option for the user to put their TMDB key
tmdb.API_KEY = myKey
TMDB_LANG = 'pt-BR' #User local language

URLYOUTUBE = 'https://www.youtube.com/watch?v='
URLTMDBPOSTER = 'https://image.tmdb.org/t/p/w'
URLNOPOSTER = 'https://nocover.png'

def serie_detail(tvg_tmdbid='', postersize='200'):
    '''
    tvg_tmdbid = Series id on TMDB website
        type = string
        ex: Game of Thrones: https://www.themoviedb.org/tv/1399-game-of-thrones?language=pt-BR
        tvg_tmdbid = '1399'

    postersize = Poster image width
        type = string
        ex: 200 , 300, 500 ...
    '''

    if tvg_tmdbid != None and str(tvg_tmdbid).strip() != '':
        tmdb_serie = tmdb.TV(tvg_tmdbid)
        tmdb_infos = tmdb_serie.info(language=TMDB_LANG)

        originaltitle = tmdb_infos['original_name']
        print(f'TMDB Serie ID: {tvg_tmdbid}\n'
            f'Original Title: {originaltitle}\n')

        poster = ''
        posterpath = tmdb_infos['poster_path']
        if posterpath != '' and posterpath != 'null' and posterpath != '0' and posterpath != None:
            poster = URLTMDBPOSTER + postersize + posterpath
        else:
            poster = URLNOPOSTER
        print(f'Poster: {poster}\n')

        overview = ''
        overview_mylang  = tmdb_infos['overview']
        overview_mylang = overview_mylang.strip()
        if overview_mylang != '' and overview_mylang != 'null' and overview_mylang != '0' and overview_mylang != None:
            overview = overview_mylang
        else:
            overview_en  = tmdb_serie.info()['overview']
            overview_en = overview_en.strip()
            if overview_en != '' and overview_en != 'null' and overview_en != '0' and overview_en != None:
                overview = f'Only in English - {overview_en}'
            else:
                overview = ''

        if overview != '':
            overview = overview
            print(f'Overview: {overview}\n')
        else:
            print('Overview not available on TMD\n')


        key_trailer = ''
        lang_trailer = TMDB_LANG.upper()
        trailers_mylang = tmdb_serie.videos(language=TMDB_LANG)['results']
        if len(trailers_mylang) > 0:
            key_trailer = trailers_mylang[0]['key']
            key_trailer = key_trailer.strip()
        else:
            trailers_en = tmdb_serie.videos()['results']
            if len(trailers_en) > 0:
                key_trailer = trailers_en[0]['key']
                key_trailer = key_trailer.strip()
                lang_trailer = 'EN'

        if key_trailer != '':
            print(f'Trailer: {lang_trailer} | {URLYOUTUBE}{key_trailer}\n')
        else:
            print('Trailer not available on TMD\n')

    else:
        print('TMDB Serie ID not informed\n')

    print('==========================\n')


#poster: ok, overview: pt-BR , trailer: pt-BR
serie_detail('1399')

#poster: ok, overview: English , trailer: English
serie_detail('71717')

#poster: ok, overview: pt-BR , trailer: no trailer
serie_detail('36', '500')

#poster: nothing, overview: nothing , trailer: nothing
serie_detail('62608')

Search results for the 4 series above

TMDB Serie ID: 1399
Original Title: Game of Thrones

Poster: https://image.tmdb.org/t/p/w200/mQ9cyw1gfpK1M3a69cgXFHvWkih.jpg

Overview: Em uma terra onde os verões podem durar vários anos e o inverno toda uma vida, sete nobres famílias lutam pelo controle da mítica terra de Westeros, dividida depois de uma guerra. Num cenário que lembra a Europa medieval, reis, rainhas, cavaleiros e renegados usam todos os meios possíveis em um jogo político pela disputa do Trono de Ferro, o símbolo do poder absoluto.

Trailer: PT-BR | https://www.youtube.com/watch?v=Ah5LiqkKBTo

==========================

TMDB Serie ID: 71717
Original Title: 9JKL

Poster: https://image.tmdb.org/t/p/w200/6jFLTrrmTgZxLAqTza171eX2FZr.jpg

Overview: Only in English - A time in Mark Feuerstein's adult life when he lived in apartment 9K in the building he grew up in, sandwiched between his parents' apartment, 9J; and his brother, sister-in-law and their baby's apartment, 9L and his attempts to set boundaries with his intrusive but well-meaning family.

Trailer: EN | https://www.youtube.com/watch?v=tV43V1xTgDE

==========================

TMDB Serie ID: 36
Original Title: Medium

Poster: https://image.tmdb.org/t/p/w500/w27IIhZJ57hYo8HOCABUtuxFMrG.jpg

Overview: Allison, uma jovem mulher, luta para entender seus sonhos e visões de pessoas mortas desde a infância. Ela é dedicada aos três filhos, marido, curso de direito e ao estágio na promotoria. Seu desafio é convencer seu chefe, Devalos, e outros no departamento de que seus poderes psíquicos podem ajudar na solução de crimes, cujos mistérios só podem ser esclarecidos pelos que vivem além do túmulo.

Trailer not available on TMD

==========================

TMDB Serie ID: 62608
Original Title: A Segunda Vez

Poster: https://nocover.png

Overview not available on TMD

Trailer not available on TMD

==========================

from hypnotix.

kodi-rc avatar kodi-rc commented on May 9, 2024

The best strategy would be to add a tvg-tmdbid tag to the m3u file

if tvg-tmdbid has any value with only numeric characters
search for this id

otherwise {tvg-tmdbid = ''}, search for the name of the 'movie or series' to find the TMDB ID and then search the other values with that TMDB ID

if channel.tmdbid != '':
    serie_detail(channel.tmdbid)

else:
    myImgpath = ''
    overview = ''
    trailer_lang = ''
    trailer = ''

    #series
    #r_tv = search.tv(query=channel.title, language=tmdb_idioma)
    #movies
    r_tv = search.movie(query=channel.title, language=tmdb_idioma)

    if len(r_tv['results']) > 0:
        tmdbid = r_tv['results'][0]['id']
        serie_detail(channel.tmdbid)

Of course, this is just a demonstrative example, but it could change the functions {movie_detail and serie_detail} to instead of printing the value in the terminal, return these values with a list to be manipulated in the main program code.

Note: In this case, the search takes the first result from the TMDB list. This can cause problems, it can pass information from another film or series.
That is why normally in kodi addon when the search has more than one result I usually display a list with the options of series / film; from the first page of TMBD, for the user to choose the most suitable one.

from hypnotix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.