Esempio n. 1
0
def show_movies_by_genre(genre_id):
    global maxpage
    page = 1
    movie_results = tmdb.get_movies_by_genre(genre_id, page)
    maxpage = movie_results["total_pages"]
    movie_ids = movie_results["results"]
    if maxpage > page:
        movie_ids.append(tmdb.get_movies_by_genre(genre_id, page + 1)["results"][0])
    show_movies(movie_ids, "genre", 1)
Esempio n. 2
0
    def onClick(self,control):
        xbmc.log('you clicked '+ str(control))
        global movie_id
        global movie
        global cast_member
        global cast_member_id
        global genre_id
        global current_genre
        global keyword_id
        global current_keyword
        global list_id
        global list_name
        global in_list
        global list_count
        if control in(200,201,202,203,204,205,206,207,208,209):
            if self.mode=='similar':
                movie_id=self.similar[control-200]['id']
                startup()  
            elif self.mode=='cast':
                from resources.lib import person
                person.person_id=self.cast[control-200]['id']
                person.startup()
               
            elif self.mode=='keywords':
               movie_id=self.keywords[control-200]['id']
               startup()  
            elif self.mode=='genre':  
                movie_id=self.genres[control-200]['id']
                startup()
            elif self.mode=='cast_movies':
                movie_id=self.cast_movies[control-200]['id']
                startup()

        if control in (50,51,52,4000):
            dg = dialogWindow('dialog_select.xml',addon_path,'default')
            dg.curr_movie=self.current_movie
            if control==50:dg.mode='trailer'
            if control==51:dg.mode='keyword'
            if control==52:dg.mode='genre'
            if control==4000: #List
                dg.mode='list'
                if self.session_id=='':
                    session_id=utils.get_login()
                    if session_id!='':self.session_id=session_id
            if self.session_id!='' or control in(50,51,52):
                dg.doModal()
            if control==4000:
                if list_id!='':
                    if in_list=='true':
                        res=tmdb.remove_from_list(list_id,self.current_movie['id'],addon.getSetting('session_id'))
                        if res:
                            list_count=list_count-1
                            dialog = xbmcgui.Dialog()
                            dialog.notification('themoviedb.org Browser', 'Successfully Removed ' + self.current_movie['title'] + ' from '+ list_name, xbmcgui.NOTIFICATION_INFO, 5000)
                            if list_count<=0:self.getControl(4010).setImage('film-icon-disable.png')
                        else:
                            dialog = xbmcgui.Dialog()
                            dialog.notification('themoviedb.org Browser', 'Failed to Remove ' + self.current_movie['title'] + ' from ' + list_name, xbmcgui.NOTIFICATION_ERROR, 5000)
                    else:
                        res=tmdb.add_to_list(list_id,self.current_movie['id'],addon.getSetting('session_id'))
                        if res:
                            dialog = xbmcgui.Dialog()
                            dialog.notification('themoviedb.org Browser', 'Successfully Added ' + self.current_movie['title'] + ' to '+ list_name, xbmcgui.NOTIFICATION_INFO, 5000)
                            self.getControl(4010).setImage('film-icon.png')
                        else:
                            dialog = xbmcgui.Dialog()
                            dialog.notification('themoviedb.org Browser', 'Failed to Add ' + self.current_movie['title'] + ' to ' + list_name, xbmcgui.NOTIFICATION_ERROR, 5000)
            if control==51:
                if keyword_id!='':
                    self.mode='keywords'
                    results=tmdb.getMoviesByKeyword(keyword_id,1)
                    self.keywords=results['results']
                    self.total_results=results['total_results']
                    self.show_keywords(self.keywords)
            elif control==52:
                if genre_id!='':
                    self.mode='genre'
                    results=tmdb.get_movies_by_genre(genre_id,1)
                    self.genres=results['results']
                    self.total_results=results['total_results']
                    self.show_genre(self.genres)
                                  
        if control == 105 or control == 106:
            if control==105:
                if self.poster_index==0:
                    self.poster_index=len(self.posters)-1
                else:
                    self.poster_index=self.poster_index-1
            if control==106:
                if self.poster_index==len(self.posters)-1:
                    self.poster_index=0
                else:
                    self.poster_index=self.poster_index+1
            self.getControl(102).setImage('')
            self.getControl(107).setLabel(str(self.poster_index+1) + ' of ' + str(len(self.posters)))
            self.getControl(101).setLabel('Loading')
            self.getControl(102).setImage('http://image.tmdb.org/t/p/original' +self.posters[self.poster_index])
            self.getControl(901).setImage('http://image.tmdb.org/t/p/original' +self.posters[self.poster_index])



        if control == 122:
            self.getControl(126).setLabel('')
            self.mode='similar'
            str_similar=tmdb.get_similar_movies(self.current_movie['id'],1)
            self.similar=str_similar['results']
            self.total_results=str_similar['total_results']
            self.show_similar(self.similar)

        if control == 124:
            self.getControl(126).setLabel('')
            self.mode = 'cast'
            self.show_cast(self.cast)
                
        if control ==127:
            if self.getControl(127).getLabel()=='Play':
                xbmc.Player().play(self.file)
                xbmc.executebuiltin('Dialog.Close(all,true)')
            else:
                xbmc.executebuiltin("XBMC.RunPlugin('plugin://plugin.video.couchpotato_manager/movies/add?title='" + self.current_movie['title']+ "')'")
        if control == 405 or control == 406:
            if control==405:
                if self.background_index==0:
                    self.background_index=len(self.backgrounds)-1
                else:
                    self.background_index=self.background_index-1
            if control==406 :
                if self.background_index==len(self.backgrounds)-1:
                    self.background_index=0
                else:
                    self.background_index=self.background_index+1

            self.getControl(402).setImage('')
            self.getControl(900).setImage('')
            self.getControl(407).setLabel(str(self.background_index+1) + ' of ' + str(len(self.backgrounds)))
            self.getControl(401).setLabel('Loading')
            self.getControl(402).setImage('http://image.tmdb.org/t/p/original' +self.backgrounds[self.background_index])
            self.getControl(900).setImage('http://image.tmdb.org/t/p/original' +self.backgrounds[self.background_index])


        if control==104:
            iw = imageWindow('image.xml', addon_path,'default')
            iw.images=self.posters
            iw.image_index=self.poster_index
            iw.doModal()
            del iw

        if control==404:
            iw = imageWindow('image.xml', addon_path,'default')
            iw.images=self.backgrounds
            iw.image_index=self.background_index
            iw.doModal()
            del iw
        
        if control==132:
            rw =  ratingWindow('rating_dialog.xml',addon_path,'default')
            rw.curr_movie=self.current_movie
            rw.doModal()
            del rw
            xbmc.sleep(1000)
            states=tmdb.get_movie_account_states(self.current_movie['id'],self.session_id)
            if states['rated']:
                star=round(self.current_movie['vote_average'],2)
                self.getControl(131).setLabel(str(star)+'/10 (' + str(self.current_movie['vote_count']) + ' votes, you voted '+ str(states['rated']['value']) +')')

        if control==129: #Webpage
            url=self.current_movie['homepage']
            url=urllib.quote_plus(url)
            xbmc.Player().play('plugin://plugin.program.chrome.launcher/?url=' + url + '&mode=showSite&stopPlayback=no')

        if control==4001: #Favorite
            if self.session_id=='':
                session_id=utils.get_login()
                if session_id!='':self.session_id=session_id
            if self.session_id!='':
                res=tmdb.update_favorite_movie(self.current_movie['id'],addon.getSetting('session_id'))
                if res['success']:
                    if res['update']:
                        dialog = xbmcgui.Dialog()
                        dialog.notification('themoviedb.org Browser', 'Successfully Added ' + self.current_movie['title'] + ' to Favorites', xbmcgui.NOTIFICATION_INFO, 5000)
                        self.getControl(4011).setImage('favorite-enable.png')
                    else:
                        dialog = xbmcgui.Dialog()
                        dialog.notification('themoviedb.org Browser', 'Successfully Removed ' + self.current_movie['title'] + ' from Favorites', xbmcgui.NOTIFICATION_INFO, 5000)
                        self.getControl(4011).setImage('favorite-disable.png')
                else:
                    dialog = xbmcgui.Dialog()
                    dialog.notification('themoviedb.org Browser','Failed to Update Favorite', xbmcgui.NOTIFICATION_ERROR, 5000)
        if control==5001: #Watchlist
            if self.session_id=='':
                session_id=utils.get_login()
                if session_id!='':self.session_id=session_id
            if self.session_id!='':
                res=tmdb.update_watchlist_movie(self.current_movie['id'],addon.getSetting('session_id'))
                if res['success']:
                    if res['update']:
                        dialog = xbmcgui.Dialog()
                        dialog.notification('themoviedb.org Browser', 'Successfully Added ' + self.current_movie['title'] + ' to Watchlist', xbmcgui.NOTIFICATION_INFO, 5000)
                        self.getControl(5011).setImage('popcorn-enable.png')
                    else:
                        dialog = xbmcgui.Dialog()
                        dialog.notification('themoviedb.org Browser', 'Successfully Removed ' + self.current_movie['title'] + ' from Watchlist', xbmcgui.NOTIFICATION_INFO, 5000)
                        self.getControl(5011).setImage('popcorn-disable.png')
                else:
                    dialog = xbmcgui.Dialog()
                    dialog.notification('themoviedb.org Browser','Failed to Update Watchlist', xbmcgui.NOTIFICATION_ERROR, 5000)
        if control==5020: #Show All
            from resources.lib import movies
            if self.mode=='genre':
                movies.genre_id=genre_id
                movies.genre_name=current_genre
                movies.page=1
                movies.source='genre'
                movies.show_movies_by_genre(genre_id)             
            if self.mode=='similar':
                movies.similar_name=self.current_movie['title']
                movies.similar_id=self.current_movie['id']
                movies.page=1
                movies.source='similar'
                movies.show_similar_movies(self.current_movie['id'])
            if self.mode=='cast_movies':
                movies.person_id=cast_member_id
                movies.person_name=cast_member
                movies.page=1
                movies.source='person'
                movies.show_movies_by_person(cast_member_id)
            if self.mode=='keywords':
                movies.keyword_id=keyword_id
                movies.keyword_name=current_keyword
                movies.page=1
                movies.source='keyword'
                movies.show_movies_by_keyword(keyword_id)
Esempio n. 3
0
    def onClick(self, control):
        global source
        global query
        global page
        global maxpage
        global genre_id
        global genre_name
        global year
        global person_id
        global person_name
        global keyword_id
        global list_id
        global list_name
        movieid = ""
        movieid = self.get_movieid_from_control(control)
        do_movies = False
        do_tv = False
        do_people = False

        popular = 32101
        top_rated = 32102
        upcoming = 32103
        now_playing = 32104
        favorites = 33105
        watchlist = 33106
        rated = 33107
        list_btn = 33108
        query_btn = 81
        previous = 32116
        next = 32117
        tv_shows = 32114
        people = 32115
        genre_btn = 82
        year_btn = 83
        person_btn = 84

        if movieid != "":
            from resources.lib import movie

            movie.movie_id = movieid
            movie_window = movie.movieWindow("script-movieDetailWindow.xml", addon_path, "default")
            movie_window.doModal()
            del movie_window
        if control == popular and source != "popular":
            source = "popular"
            page = 1
            do_movies = True
        if control == top_rated and source != "top_rated":
            source = "top_rated"
            do_movies = True
            page = 1
        if control == upcoming and source != "upcoming":
            source = "upcoming"
            do_movies = True
            page = 1
        if control == now_playing and source != "now_playing":
            source = "now_playing"
            do_movies = True
            page = 1
        if control == favorites and source != "favorites":
            do_movies = True
            source = "favorites"
            page = 1
        if control == watchlist and source != "watchlist":
            do_movies = True
            source = "watchlist"
            page = 1
        if control == rated and source != "rated":
            do_movies = True
            source = "rated"
            page = 1
        if control == query_btn:
            source = "query"
            do_movies = True
            page = 1
        if control == genre_btn:
            source = "genre"
            page = 1
            genre_id = ""
            do_movies = True
        if control == year_btn:
            source = "years"
            page = 1
            year = ""
            do_movies = True
        if control == person_btn:
            source = "person"
            page = 1
            person_id = ""
            person_name = ""
            do_movies = True
        if control == list_btn:
            source = "list"
            list_id = ""
            page = 1
            do_movies = True
        if control == next:
            if page < maxpage:
                page = page + 1
                do_movies = True
        if control == previous:
            if page > 1:
                page = page - 1
                do_movies = True
        if control == tv_shows:
            do_tv = True
        if control == people:
            do_people = True

        if do_movies:
            ans = True
            if source == "query":
                self.getControl(80).setVisible(True)
                if control == query_btn:
                    k = xbmc.Keyboard("", "Enter Movie Title to Search For")
                    k.doModal()
                    query = k.getText()
                if query != "":
                    movies = tmdb.search_movies(query, page)
                    maxpage = movies["total_pages"]
                    movies = movies["results"]
                    if maxpage > page:
                        movies.append(tmdb.search_movies(query, page + 1)["results"][0])
                    show_movies(movies, source, page)
            elif source == "favorites":
                if self.session_id == "":
                    session_id = utils.get_login()
                    if session_id != "":
                        self.session_id = session_id
                if self.session_id != "":
                    movies = tmdb.get_favorite_movies(self.session_id, page)
                    total_pages = movies["total_pages"]
                    maxpage = total_pages
                    movies = movies["results"]
                    if total_pages > page:
                        movies.append(tmdb.get_favorite_movies(self.session_id, page + 1)["results"][0])
                    show_movies(movies, source, page)
            elif source == "watchlist":
                if self.session_id == "":
                    session_id = utils.get_login()
                    if session_id != "":
                        self.session_id = session_id
                if self.session_id != "":
                    movies = tmdb.get_watchlist_movies(self.session_id, page)
                    total_pages = movies["total_pages"]
                    maxpage = total_pages
                    movies = movies["results"]
                    if total_pages > page:
                        movies.append(tmdb.get_watchlist_movies(self.session_id, page + 1)["results"][0])
                    show_movies(movies, source, page)
            elif source == "rated":
                if self.session_id == "":
                    session_id = utils.get_login()
                    if session_id != "":
                        self.session_id = session_id
                if self.session_id != "":
                    movies = tmdb.get_rated_movies(self.session_id, page)
                    total_pages = movies["total_pages"]
                    maxpage = total_pages
                    movies = movies["results"]
                    if total_pages > page:
                        movies.append(tmdb.get_rated_movies(self.session_id, page + 1)["results"][0])
                    show_movies(movies, source, page)
            elif source == "list":
                if self.session_id == "":
                    session_id = utils.get_login()
                    if session_id != "":
                        self.session_id = session_id
                if self.session_id != "" and list_id == "":
                    dg = dialogWindow("dialog_select.xml", addon_path, "Default")
                    dg.mode = "list"
                    dg.doModal()
                if list_name == "Add New":
                    k = xbmc.Keyboard("", "Enter List Name")
                    k.doModal()
                    name = k.getText()
                    if name != "" and (k.isConfirmed()):
                        k = xbmc.Keyboard("", "Enter List Description")
                        k.doModal()
                        description = k.getText()
                        if k.isConfirmed():
                            res = tmdb.add_list(name, description, addon.getSetting("session_id"))
                            if res:
                                dialog = xbmcgui.Dialog()
                                dialog.notification(
                                    "themoviedb.org Browser",
                                    "List " + name + " Successfully Added",
                                    xbmcgui.NOTIFICATION_INFO,
                                    5000,
                                )
                            else:
                                dialog = xbmcgui.Dialog()
                                dialog.notification(
                                    "themoviedb.org Browser", "Failed Add " + name, xbmcgui.NOTIFICATION_ERROR, 5000
                                )
                if list_id != "":
                    movies = tmdb.get_movie_list(list_id)
                    movies = movies["items"]
                    pages = len(movies) / 20
                    if len(movies) % 20 > 0:
                        pages = pages + 1
                    total_pages = pages
                    maxpage = total_pages
                    list_movies = []
                    if page > 1:
                        for i in range((page * 20) - 20, (page * 20) + 1):
                            if i < len(movies):
                                list_movies.append(movies[i])
                        movies = list_movies
                    show_movies(movies, source, page)
            elif source == "genre":
                if genre_id == "":
                    dg = dialogWindow("dialog_select.xml", addon_path, "Default")
                    dg.mode = "genre"
                    dg.doModal()
                if genre_id != "":
                    movies = tmdb.get_movies_by_genre(genre_id, page)
                    total_pages = movies["total_pages"]
                    movies = movies["results"]
                    maxpage = total_pages
                    if total_pages > page:
                        movies.append(tmdb.get_movies_by_genre(genre_id, page + 1)["results"][0])
                    show_movies(movies, source, page)
            elif source == "years":
                if year == "":
                    kb = xbmc.Keyboard("", "Enter Year")
                    kb.doModal()
                    year = kb.getText()
                movies = tmdb.get_movies_by_year(year, page)
                total_pages = movies["total_pages"]
                movies = movies["results"]
                maxpage = total_pages
                if total_pages > page:
                    movies.append(tmdb.get_movies_by_year(year, page + 1)["results"][0])
                show_movies(movies, source, page)
            elif source == "similar":
                movies = tmdb.get_similar_movies(similar_id, page)
                total_pages = movies["total_pages"]
                movies = movies["results"]
                maxpage = total_pages
                if total_pages > page:
                    movies.append(tmdb.get_similar_movies(similar_id, page + 1)["results"][0])
                show_movies(movies, source, page)
            elif source == "keyword":
                movies = tmdb.getMoviesByKeyword(keyword_id, page)
                total_pages = movies["total_pages"]
                movies = movies["results"]
                maxpage = total_pages
                if total_pages > page:
                    movies.append(tmdb.getMoviesByKeyword(keyword_id, page + 1)["results"][0])
                show_movies(movies, source, page)
            elif source == "person":
                if person_id == "":
                    kb = xbmc.Keyboard("", "Enter Persons Name")
                    kb.doModal()
                    person_name = kb.getText()
                    if person_name != "":
                        dg = dialogWindow("dialog_select.xml", addon_path, "Default")
                        dg.mode = "people"
                        dg.doModal()
                movies = tmdb.getMoviesByActor(person_id, page)
                pages = len(movies) / 20
                if len(movies) % 20 > 0:
                    pages = pages + 1
                total_pages = pages
                xbmc.log(str(len(movies)))
                maxpage = total_pages
                movies = sorted(movies, key=lambda k: k["release_date"], reverse=True)
                person_movies = []
                if page > 1:
                    for i in range((page * 20) - 20, (page * 20) + 1):
                        if i < len(movies):
                            person_movies.append(movies[i])
                    movies = person_movies
                show_movies(movies, source, page)
            elif source in ("Production", "Directing", "Writing"):
                person = tmdb.get_person(person_id)
                crew_movies = person["movie_credits"]["crew"]
                movies = []
                for movie in crew_movies:
                    if movie["department"] == source:
                        movies.append(movie)
                pages = len(movies) / 20
                if len(movies) % 20 > 0:
                    pages = pages + 1
                total_pages = pages
                maxpage = total_pages
                movies = sorted(movies, key=lambda k: k["release_date"], reverse=True)
                person_movies = []
                if page > 1:
                    for i in range((page * 20) - 20, (page * 20) + 1):
                        if i < len(movies):
                            person_movies.append(movies[i])
                    movies = person_movies
                show_movies(movies, source, page)
            else:
                query = ""
                xbmc.log(source)
                movies = tmdb.get_movies(source, page)
                total_pages = movies["total_pages"]
                maxpage = 10
                if source == "upcoming" or source == "now_playing":
                    maxpage = movies["total_pages"]
                movies = movies["results"]
                if total_pages > page:
                    movies.append(tmdb.get_movies(source, page + 1)["results"][0])
                show_movies(movies, source, page)
        elif do_tv:
            from resources.lib import tvshows

            tvshows.source = "popular"
            tvshows.startup()
        elif do_people:
            from resources.lib import people

            people.source = "popular"
            people.startup()