AnthonyBloomer / tmdbv3api

A lightweight Python library for The Movie Database (TMDb) API. The TMDb API is a resource for developers to integrate movie, TV show and cast data along with posters or movie fan art.
http://anthonybloomer.github.io/tmdbv3api/.
224 stars 51 forks source link

How to get only the first cover and title ? #99

Closed Impre-visible closed 3 years ago

Impre-visible commented 3 years ago

How can i get only the first title and cover : image


def home():
    print(type(movie))
    vu = "\\\\Freebox_Server\\disque dur\\Vidéos\\Vu"
    films = os.listdir(vu)
    print(films)

    for film in films:  
        file_title = film.title()
        original_file_title = file_title
        size = len(file_title)
        file_title = file_title[:size - 4]
        search = movie.search(file_title)
        for res in search:
            movie_title = (res.title)
            movie_cover_path = (res.poster_path)
            cover_full_path = (f"https://image.tmdb.org/t/p/original/{movie_cover_path}")
            print("Titre : "+movie_title)
            print("Cover :", cover_full_path)
        print('Nom du fichier sans ext : '+file_title)
        print(f'Path : \\\\Freebox_Server\\disque dur\\Vidéos\\Vu\\{original_file_title}')
        print("---------------------------------")

    return render_template('index.html', films=films, titre=movie_title, cover=cover_full_path)```
Maxcension commented 2 years ago

how did u manage to do that?

Impre-visible commented 2 years ago

I do that :


def get_movie(slug):
    for film_data in searched_films:
        if film_data["slug"] == slug:
            return film_data

path = "static/Vu"
film_file_list = os.listdir(path)
film_file_list.sort()

for searched_film in film_file_list:   
    if not isinstance(searched_film, str):
        continue
    file_title = searched_film.title()
    original_file_title = file_title
    size = len(file_title)
    file_title = file_title[:size - 4]

    try:
        search = movie.search(file_title)
    except TMDbException:
        continue

    if not search:
        continue

    res = search[0]
    movie_title = res.title
    movie_cover_path = res.poster_path
    cover_full_path = f"https://image.tmdb.org/t/p/original{movie_cover_path}"
    print(f"titre original : {original_file_title}")
    print(f"")
    print("titre modifié : "+file_title)
    print(f"")
    print(f"titre trouvé : {movie_title}")
    print(f"")
    print(f"lien poster : {cover_full_path}")
    print(f"")
    print(f"-------------------------")
    print(f"")

    film_data = {
    "title": movie_title,
    "cover": cover_full_path,
    "slug": original_file_title,
    }

    searched_films.append(film_data)
Maxcension commented 2 years ago

Thanks mate!