Skip to content

Commit

Permalink
v3.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lekma committed Oct 14, 2024
1 parent c1c7d67 commit a48bc36
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 158 deletions.
16 changes: 7 additions & 9 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.invidious"
name="Invidious"
version="3.2.3"
version="3.2.5"
provider-name="lekma">

<requires>
<import addon="xbmc.python" version="3.0.1" />
<import addon="xbmc.addon" version="20.2.0" />
<import addon="script.module.nuttig" version="1.2.0" />
<import addon="script.module.iapc" version="2.2.0" />
<import addon="script.module.nuttig" version="1.2.5" />
<import addon="script.module.iapc" version="2.2.5" />
<import addon="script.module.requests" version="2.31.0" />
<import addon="script.module.inputstreamhelper" version="0.6.1" />
<import addon="service.yt-dlp" version="1.2.0" optional="true" />
<import addon="script.module.inputstreamhelper" version="0.7.0" />
<import addon="service.yt-dlp" version="1.2.5" optional="true" />
<import addon="plugin.video.youtube" version="7.0.9.2" optional="true" />
<import addon="service.sponsorblock" version="1.2.0" optional="true" />
<import addon="service.sponsorblock" version="1.2.5" optional="true" />
</requires>

<extension point="xbmc.python.pluginsource" library="lib/plugin.py">
Expand All @@ -22,9 +22,7 @@

<extension point="xbmc.service" library="lib/service.py" />

<extension point="xbmc.python.script" library="lib/scripts.py">
<provides>executable</provides>
</extension>
<extension point="xbmc.python.script" library="lib/scripts.py" />

<extension point="xbmc.addon.metadata">
<reuselanguageinvoker>true</reuselanguageinvoker>
Expand Down
36 changes: 24 additions & 12 deletions lib/invidious/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from invidious.items import (
FeedChannels, Folders, Playlists, Queries, Results, Video, Videos
)
from invidious.persistence import IVNavigationHistory


# instance ---------------------------------------------------------------------
Expand All @@ -36,6 +37,7 @@ class IVClient(object):
def __init__(self, logger):
self.logger = logger.getLogger(f"{logger.component}.client")
self.__client__ = Client()
self.__history__ = IVNavigationHistory()

# video --------------------------------------------------------------------

Expand All @@ -57,29 +59,35 @@ def tabs(self, **kwargs):

@instance
def tab(self, key, **kwargs):
if (videos := self.__client__.instance.tab(key, **kwargs)):
items, next, category = self.__client__.instance.tab(key, **kwargs)
if items is not None:
previous = self.__history__.continuation(
key, kwargs.get("continuation")
)
return Videos(
videos["items"],
continuation=videos["continuation"],
category=videos["channel"]
items, next=next, category=category, previous=previous
)

@instance
def playlists(self, **kwargs):
if (playlists := self.__client__.instance.playlists(**kwargs)):
items, next, category = self.__client__.instance.playlists(**kwargs)
if items is not None:
previous = self.__history__.continuation(
"playlists", kwargs.get("continuation")
)
return Playlists(
playlists["items"],
continuation=playlists["continuation"],
category=playlists["channel"]
items, next=next, category=category, previous=previous
)

# playlist -----------------------------------------------------------------

@instance
def playlist(self, **kwargs):
if(playlist := self.__client__.instance.playlist(**kwargs)):
items, next, category = self.__client__.instance.playlist(**kwargs)
if items is not None:
previous = self.__history__.index("playlist", kwargs["index"])
return Videos(
playlist["items"], limit=200, category=playlist["title"]
items, next=next, category=category, previous=previous
)

# home ---------------------------------------------------------------------
Expand All @@ -91,7 +99,9 @@ def home(self):

@instance
def feed(self, limit=29, **kwargs):
return Videos(self.__client__.feed.feed(limit, **kwargs), limit=limit)
items, next = self.__client__.feed.feed(limit, **kwargs)
previous = self.__history__.page("feed", kwargs["page"])
return Videos(items, next=next, previous=previous)

@instance
def channels(self):
Expand Down Expand Up @@ -123,6 +133,8 @@ def history(self):

@instance
def search(self, query):
items, next = self.__client__.search.search(query)
previous = self.__history__.page("search", query["page"])
return Results(
self.__client__.search.search(query), limit=20, category=query["q"]
items, next=next, previous=previous, category=query["q"]
)
42 changes: 7 additions & 35 deletions lib/invidious/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ def __init__(self, item, expires=1800):


# ------------------------------------------------------------------------------
# IVPlaylistVideos
# IVPlaylists

class IVPlaylistVideos(IVPlaylist):
class IVPlaylists(list):

def __init__(self, item):
super(IVPlaylistVideos, self).__init__(item)
self["items"] = IVVideos(item["videos"])
def __init__(self, playlists):
super(IVPlaylists, self).__init__(
IVPlaylist(playlist) for playlist in playlists if playlist
)


# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -250,7 +251,7 @@ def __init__(self, item, expires=1800):
subscribers=subscribers,
subscribersText=subscribersText,
tabs=[
dict(tab, action=action)
dict(tab, action=action, properties={"SpecialSort": "top"})
for action, tab in self.__tabs__.items()
if action in item.get("tabs", [])
]
Expand All @@ -261,35 +262,6 @@ def __repr__(self):
return f"IVChannel({self['channel']})"


# ------------------------------------------------------------------------------
# IVChannelVideos

class IVChannelVideos(dict):

def __init__(self, channel, items):
super(IVChannelVideos, self).__init__(
channel=channel,
continuation=items.get("continuation"),
items=IVVideos(items["videos"])
)


# ------------------------------------------------------------------------------
# IVChannelPlaylists

class IVChannelPlaylists(dict):

def __init__(self, channel, items):
super(IVChannelPlaylists, self).__init__(
channel=channel,
continuation=items.get("continuation"),
items=[
IVPlaylist(playlist)
for playlist in items["playlists"] if playlist
]
)


# ------------------------------------------------------------------------------
# IVResults

Expand Down
25 changes: 14 additions & 11 deletions lib/invidious/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ def update(self, videos):
self.__last__ = time()

def page(self, limit, page):
return self.__videos__[(limit * (page - 1)):(limit * page)]
videos, next = (
self.__videos__[:(fence := (limit * page))],
self.__videos__[fence:]
)
return (
videos[(limit * (page - 1)):],
{"page": (page + 1)} if next else None
)

# feed ---------------------------------------------------------------------

@public
def feed(self, limit, page=1):
t = time()
try:
if (
((page := int(page)) == 1) and
((keys := self.invalid()) is not None)
):
self.update(self.__instance__.__feeds__(keys))
return self.page(limit, page)
finally:
self.logger.info(f"feed() took: {time() - t} seconds")
if (
((page := int(page)) == 1) and
((keys := self.invalid()) is not None)
):
self.update(self.__instance__.__feeds__(keys))
return self.page(limit, page)

# channels -----------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions lib/invidious/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"action": "trending",
"title": 30310,
"art": "DefaultAddonMusic.png",
"properties": {"SpecialSort": "top"},
"kwargs": {
"type": "music",
"category": localizedString(30310)
Expand All @@ -36,6 +37,7 @@
"action": "trending",
"title": 30320,
"art": "DefaultAddonGame.png",
"properties": {"SpecialSort": "top"},
"kwargs": {
"type": "gaming",
"category": localizedString(30320)
Expand All @@ -45,6 +47,7 @@
"action": "trending",
"title": 30330,
"art": "DefaultMovies.png",
"properties": {"SpecialSort": "top"},
"kwargs": {
"type": "movies",
"category": localizedString(30330)
Expand All @@ -68,6 +71,7 @@ def __init__(self, action, folder):
action=folder.get("action", action),
setting=folder.get("setting"),
art=dict.fromkeys(("poster", "icon"), folder.get("art")),
properties=folder.get("properties"),
kwargs=folder.get("kwargs", {})
)

Expand Down
46 changes: 36 additions & 10 deletions lib/invidious/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
)

from invidious.extract import (
IVChannel, IVChannelVideos, IVChannelPlaylists,
IVPlaylist, IVPlaylistVideos,
IVResults, IVVideo, IVVideos
IVChannel, IVPlaylist, IVPlaylists, IVResults, IVVideo, IVVideos
)
from invidious.regional import locales, regions
from invidious.session import IVSession
Expand Down Expand Up @@ -245,31 +243,59 @@ def tabs(self, **kwargs):
self.logger.error(f"Invalid channelId: {channelId}", notify=True)

def __tab__(self, channelId, key, **kwargs):
#if (("continuation" in kwargs) and (not kwargs["continuation"])):
# del kwargs["continuation"]
if (continuation := kwargs.pop("continuation", None)):
kwargs["continuation"] = continuation
return (
self.__channel__(channelId)["channel"],
self.__get__(key, channelId, **kwargs)
self.__get__(key, channelId, **kwargs),
self.__channel__(channelId)["channel"]
)

@public
def tab(self, key, **kwargs):
if (channelId := kwargs.pop("channelId", None)):
return IVChannelVideos(*self.__tab__(channelId, key, **kwargs))
items, channel = self.__tab__(channelId, key, **kwargs)
return (
IVVideos(items["videos"]),
(
{"continuation": continuation}
if (continuation := items.get("continuation")) else None
),
channel
)
self.logger.error(f"Invalid channelId: {channelId}", notify=True)

@public
def playlists(self, **kwargs):
if (channelId := kwargs.pop("channelId", None)):
return IVChannelPlaylists(
*self.__tab__(channelId, "playlists", **kwargs)
items, channel = self.__tab__(channelId, "playlists", **kwargs)
return (
IVPlaylists(items["playlists"]),
(
{"continuation": continuation}
if (continuation := items.get("continuation")) else None
),
channel
)
self.logger.error(f"Invalid channelId: {channelId}", notify=True)

# playlist -----------------------------------------------------------------

@public
def playlist(self, **kwargs):
def playlist(self, limit=200, **kwargs):
if (playlistId := kwargs.pop("playlistId", None)):
return IVPlaylistVideos(self.__get_playlist__(playlistId, **kwargs))
items = (
(item := self.__get_playlist__(playlistId, **kwargs))["videos"]
)
return (
IVVideos(items),
(
{"index": (kwargs["index"] + count)}
if ((count := len(items)) >= limit) else None
),
item["title"]
)
self.logger.error(f"Invalid playlistId: {playlistId}", notify=True)

# feed ---------------------------------------------------------------------
Expand Down
13 changes: 9 additions & 4 deletions lib/invidious/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class Items(List):

__ctor__ = Item

def __init__(self, items, continuation=None, limit=0, **kwargs):
def __init__(self, items, previous=None, next=None, **kwargs):
super(Items, self).__init__(items, **kwargs)
self.more = continuation or ((len(self) >= limit) if limit else False)
self.previous = previous
self.next = next


class Contents(Items):
Expand All @@ -85,6 +86,10 @@ class Folder(Item):
def action(self):
return self.get("action", self.type)

@property
def properties(self):
return self.get("properties")

@property
def plot(self):
if (plot := self.get("plot")):
Expand All @@ -102,6 +107,7 @@ def getItem(self, url, **kwargs):
title,
buildUrl(url, action=self.action, **dict(self.kwargs, **kwargs)),
isFolder=True,
properties=self.properties,
infoLabels=self.labels(title, self.plot or title),
**self.art
)
Expand Down Expand Up @@ -147,8 +153,7 @@ def getItem(self, url):
action="search",
q=self.q,
type=self.type,
sort=self.sort,
page=self.page
sort=self.sort
),
isFolder=True,
infoLabels=self.labels(self.q, self.q),
Expand Down
Loading

0 comments on commit a48bc36

Please sign in to comment.