summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addon.py110
-rw-r--r--addon.xml19
2 files changed, 90 insertions, 39 deletions
diff --git a/addon.py b/addon.py
index 5534eaf..4b01c59 100644
--- a/addon.py
+++ b/addon.py
@@ -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:
diff --git a/addon.xml b/addon.xml
index 5a0daf0..fad1355 100644
--- a/addon.xml
+++ b/addon.xml
@@ -1,20 +1,21 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.newgrounds" version="0.1.0" name="Newgrounds" provider-name="zerodaysfordays">
<requires>
- <import addon="xbmc.python" version="3.0.0"/>
+ <import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.beautifulsoup4" version="4.12.2"/>
<import addon="script.module.requests" version="2.31.0"/>
</requires>
- <extension point="xbmc.python.script" library="addon.py">
- <provides>video</provides>
+ <extension point="xbmc.python.pluginsource" library="addon.py">
+ <provides>video</provides>
</extension>
+ <extension point="xbmc.python.library" library="bs4"></extension>
<extension point="xbmc.addon.metadata">
- <summary lang="en_US">Add-on for watching videos from Newgrounds</summary>
- <description lang="en_US">Add-on that displays Newgrounds movies. Newgrounds is a company and entertainment website founded by Tom Fulp in 1995.</description>
- <license>GPLv3</license>
+ <summary lang="en_US">Add-on for watching videos from Newgrounds</summary>
+ <description lang="en_US">Add-on that displays Newgrounds movies. Newgrounds is a company and entertainment website founded by Tom Fulp in 1995.</description>
+ <license>GPLv3-only</license>
<platform>all</platform>
- <source>https://git.sr.ht/~jakob/newgrounds-addon/</source>
- <email>zerodaysfordays@sdf.org</email>
+ <source>https://git.sr.ht/~jakob/newgrounds-addon/</source>
+ <email>zerodaysfordays@sdf.org</email>
<assets>
<icon>resources/icon.png</icon>
<fanart>resources/fanart.jpg</fanart>