diff options
Diffstat (limited to 'addon.py')
| -rw-r--r-- | addon.py | 110 |
1 files changed, 80 insertions, 30 deletions
@@ -47,44 +47,53 @@ def get_url(**kwargs): return '{}?{}'.format(URL, urlencode(kwargs)) -def get_genres(): +def list_genres(): """ - Get the list of video genres - - Here you can insert some code that retrieves - the list of video sections (in this case movie genres) from some site or API. - - :return: The list of video genres - :rtype: list + Create the list of movie genres in the Kodi interface. """ - return VIDEOS + xbmcplugin.setPluginCategory(HANDLE, 'Newgrounds') + xbmcplugin.setContent(HANDLE, 'movies') + genres = ["Featured", "Latest", "Popular"] -def get_videos(genre_index): - """ - Get the list of videofiles/streams. + for name in genres: + list_item = xbmcgui.ListItem(label=name) + # list_item.setArt({'icon': genre_info['icon'], 'fanart': genre_info['fanart']}) - Here you can insert some code that retrieves - the list of video streams in the given section from some site or API. + info_tag = list_item.getVideoInfoTag() + info_tag.setMediaType('video') + info_tag.setTitle(name) + info_tag.setGenres([name]) - :param genre_index: genre index - :type genre_index: int - :return: the list of videos in the category - :rtype: list - """ - return VIDEOS[genre_index] + url = get_url(action='listing', genre=name) + is_folder = True + xbmcplugin.addDirectoryItem(HANDLE, url, list_item, is_folder) + xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) + xbmcplugin.endOfDirectory(HANDLE) -def list_genres(): + +def list_categories(genre='Featured'): """ - Create the list of movie genres in the Kodi interface. + Create the list of movie categories in the Kodi interface. """ xbmcplugin.setPluginCategory(HANDLE, 'Newgrounds') xbmcplugin.setContent(HANDLE, 'movies') - genres = ["Featured"] # get_genres() + CATEGORIES = { + 'All': 0, + 'Action': 45, + 'Comedy - Original': 60, + 'Comedy - Parody': 61, + 'Drama': 47, + 'Experimental': 49, + 'Informative': 48, + 'Music Video': 50, + 'Other': 51, + 'Spam': 55, + } - for index, name in enumerate(genres): + for name in CATEGORIES.keys(): list_item = xbmcgui.ListItem(label=name) # list_item.setArt({'icon': genre_info['icon'], 'fanart': genre_info['fanart']}) @@ -93,14 +102,14 @@ def list_genres(): info_tag.setTitle(name) info_tag.setGenres([name]) - url = get_url(action='listing', genre_index=index) + url = get_url(action='listing', genre=genre, category=CATEGORIES[name]) is_folder = True xbmcplugin.addDirectoryItem(HANDLE, url, list_item, is_folder) xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(HANDLE) - + def get_video_url(url): """ TODO @@ -134,16 +143,45 @@ def get_addon_video_info(url): 'url': url } -def list_videos(genre_index): + +def get_video_urls(genre='Featured', interval='today', sort='date', category=0, offset=0): + URLS = { + 'Featured': 'https://www.newgrounds.com/movies/featured', + 'Latest': 'https://www.newgrounds.com/movies/browse', + 'Popular': 'https://www.newgrounds.com/movies/popular', + } + + assert(interval in ['today', 'yesterday', 'week', 'month', 'year', 'all']) + assert(sort in ['date']) + assert(isinstance(genre, int)) + + url = URLS[genre] + response = requests.get(url, params={ + 'interval': interval, + 'sort': sort, + 'genre': category, + 'isAjaxRequest': True, + 'offset': offset, + 'inner': 1 + }, headers={ + 'X-Requested-With': 'XMLHttpRequest', + }).json() + + soup = BeautifulSoup(response['content'], 'html.parser') + return [tag["href"] for tag in soup.find_all('a', "inline-card-portalsubmission")] + + +def list_videos(genre, category=0, offset=0): """ Create the list of playable videos in the Kodi interface. :param genre_index: the index of genre in the list of movie genres - :type genre_index: int + :type genre: str + :type offset: int """ html = requests.get("https://www.newgrounds.com/movies").text soup = BeautifulSoup(html, 'html.parser') - videos = [get_addon_video_info(tag["href"]) for tag in soup.find_all('a', "inline-card-portalsubmission")] + videos = [get_addon_video_info(url) for url in get_video_urls(category=category, interval='all', offset=offset)] xbmcplugin.setPluginCategory(HANDLE, "Featured") #, genre_info['genre']) xbmcplugin.setContent(HANDLE, 'movies') @@ -165,6 +203,16 @@ def list_videos(genre_index): url = get_url(action='play', video=video['url']) is_folder = False xbmcplugin.addDirectoryItem(HANDLE, url, list_item, is_folder) + + # Add a "continue" folder. + list_item = xbmcgui.ListItem(label="Next Page") + info_tag = list_item.getVideoInfoTag() + info_tag.setMediaType('video') + info_tag.setTitle("Next Page") + url = get_url(action='listing', genre=genre, category=category, offset=offset+20) + is_folder = True + xbmcplugin.addDirectoryItem(HANDLE, url, list_item, is_folder) + xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.endOfDirectory(HANDLE) @@ -187,8 +235,10 @@ def router(paramstring): params = dict(parse_qsl(paramstring)) if not params: list_genres() + elif params['action'] == 'listing' and 'category' in params: + list_videos(params['genre'], category=params['category'], offset=int(params.get('offset', 0))) elif params['action'] == 'listing': - list_videos(int(params['genre_index'])) + list_categories(params['genre']) elif params['action'] == 'play': play_video(params['video']) else: |