Skip to content

Commit

Permalink
0.3.0 add settings
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
kuriho committed Jun 6, 2023
1 parent 1d90aa0 commit 764b890
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 39 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<addon id="plugin.video.tver" name="TVer" version="0.2.1" provider-name="kuriho">
<addon id="plugin.video.tver" name="TVer" version="0.3.0" provider-name="kuriho">

<requires>
<import addon="xbmc.python" version="3.0.1" />
Expand Down
29 changes: 29 additions & 0 deletions favourites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import xbmcgui

from mylist import MyList

def show_favourites():
series = MyList().select_favourites()
list = []

for serie in series:
li = xbmcgui.ListItem(serie[2])
list.append(li)

dialog = xbmcgui.Dialog()
selected_index = dialog.select("MyList", list)
if selected_index >= 0:
li = list[selected_index]
serie = series[selected_index]

thumb = 'https://statics.tver.jp/images/content/thumbnail/series/small/{}.jpg'.format(serie[0])
vid_info = li.getVideoInfoTag()
vid_info.setTitle(serie[2])
vid_info.setGenres([serie[1]])
vid_info.setMediaType('tvshow')

li.setArt({'thumb': thumb, 'icon': thumb, 'fanart': thumb})
li.setProperty('IsPlayable', 'false')

dialog = xbmcgui.Dialog()
dialog.info(li)
35 changes: 19 additions & 16 deletions mylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def create(self):
expires INTEGER,
vid_type TEXT,
title TEXT,
series TEXT,
series_title TEXT
series TEXT
);
'''
conn.execute(table)
Expand All @@ -32,7 +31,8 @@ def create(self):
table = '''
CREATE TABLE IF NOT EXISTS favourites (
id TEXT PRIMARY KEY NOT NULL,
category TEXT
category TEXT,
title TEXT
);
'''
conn.execute(table)
Expand All @@ -58,9 +58,9 @@ def build(self):
self.insert(episode['type'],episode['content'])


def add(self,category,series):
def add(self,category,series,title):
conn = sql.connect(self.file)
conn.execute(f'INSERT OR REPLACE INTO favourites (id,category) VALUES (?,?)', (series, category,),)
conn.execute(f'INSERT OR REPLACE INTO favourites (id,category,title) VALUES (?,?,?)', (series, category, title,),)
conn.commit()
conn.close()
#rebuild mylist
Expand All @@ -80,7 +80,8 @@ def select_favourites(self):

stmt = '''
SELECT id,
category
category,
title
FROM favourites
'''
cur.execute(stmt)
Expand All @@ -97,12 +98,13 @@ def select(self):
cur = conn.cursor()

stmt = '''
SELECT id,
vid_type,
title,
series,
series_title
FROM mylist
SELECT my.id,
my.vid_type,
my.title,
fav.id as series,
fav.title as series_title
FROM mylist as my
INNER JOIN favourites as fav on fav.id = my.series
'''
cur.execute(stmt)

Expand All @@ -117,10 +119,10 @@ def insert(self, type, content):
conn = sql.connect(self.file)

conn.execute('''
INSERT OR REPLACE INTO mylist (id,expires,vid_type,title,series,series_title)
VALUES (?,?,?,?,?,?)
INSERT OR REPLACE INTO mylist (id,expires,vid_type,title,series)
VALUES (?,?,?,?,?)
''',
(content['id'], content['endAt'], type, content['title'], content['seriesID'], content['seriesTitle'],),)
(content['id'], content['endAt'], type, content['title'], content['seriesID'], ),)

conn.commit()
conn.close()
Expand All @@ -141,7 +143,8 @@ def get(self):
'series': series_id,
'thumb': URL_VIDEO_PICTURE.format(video_type, video_id),
'video': URL_VIDEO_WEBSITE.format(video_type, video_id),
'genre': None })
'genre': None,
'series_title': series_title })

return episodes

Expand Down
24 changes: 18 additions & 6 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

from mylist import MyList
from watcher import Watcher
from utils import log, show_info, check_if_kodi_supports_manifest, extract_info, extract_manifest_url_from_info, get_url, refresh, get_adaptive_type_from_url, localize
from cache import Cache
from favourites import show_favourites
from utils import log, show_info, check_if_kodi_supports_manifest, extract_info, extract_manifest_url_from_info, get_url, refresh, get_adaptive_type_from_url, localize, clear_thumbnails

_HANDLE = int(sys.argv[1])

Expand All @@ -16,15 +18,20 @@ def list_videos(category):
xbmcplugin.setContent(_HANDLE, 'videos')

videos = []
context = (localize(30021),'mylist')
context = None

if category == 'mylist':
videos = MyList().get()
mylist = MyList()
mylist.build()
videos = mylist.get()
context = (localize(30020),'delist')

elif category == 'watching':
videos = tver.get_watching_episodes()

else:
videos = tver.get_episodes(category)
context = (localize(30021),'mylist')

for video in videos:
label = video['name']
Expand All @@ -40,8 +47,9 @@ def list_videos(category):
list_item.setArt({'thumb': video['thumb'], 'icon': video['thumb'], 'fanart': video['thumb']})
list_item.setProperty('IsPlayable', 'true')

context_menu_item = (context[0], 'RunPlugin({})'.format(get_url(action=context[1], series=video['series'], category=video['genre'])))
list_item.addContextMenuItems([context_menu_item])
if context:
context_menu_item = (context[0], 'RunPlugin({})'.format(get_url(action=context[1], series=video['series'], category=video['genre'], series_title=video['series_title'])))
list_item.addContextMenuItems([context_menu_item])

url = get_url(action='play', video=video['video'])
is_folder = False
Expand Down Expand Up @@ -120,10 +128,14 @@ def router(paramstring):
elif action == 'play':
play_video(params['video'])
elif action == 'mylist':
MyList().add(params['category'], params['series'])
MyList().add(params['category'], params['series'], params['series_title'])
elif action == 'delist':
MyList().remove(params['series'])
refresh()
elif action == 'thumbnails':
clear_thumbnails()
elif action == 'favourites':
show_favourites()
else:
raise ValueError('Invalid paramstring: {}!'.format(paramstring))
else:
Expand Down
4 changes: 0 additions & 4 deletions resources/language/resource.language.de_de/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ msgctxt "#30051"
msgid "Clear thumbnail cache"
msgstr "Vorschaubilder Cache leeren"

msgctxt "#30052"
msgid "Clear TVer cache"
msgstr "TVer Cache leeren"

msgctxt "#30071"
msgid "Remove"
msgstr "Entfernen"
Expand Down
4 changes: 0 additions & 4 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ msgctxt "#30051"
msgid "Clear thumbnail cache"
msgstr ""

msgctxt "#30052"
msgid "Clear TVer cache"
msgstr ""

msgctxt "#30071"
msgid "Remove"
msgstr ""
Expand Down
4 changes: 0 additions & 4 deletions resources/language/resource.language.ja_jp/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ msgctxt "#30051"
msgid "Clear thumbnail cache"
msgstr "サムネイルキャッシュをクリア"

msgctxt "#30052"
msgid "Clear TVer cache"
msgstr "ティーバーキャッシュをクリア"

msgctxt "#30071"
msgid "Remove"
msgstr "削除"
Expand Down
9 changes: 9 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<settings>
<category label="30000">
<setting label="30002" id="favourites" type="action" option="close" action="RunPlugin(plugin://$ID/?action=favourites)"/>
</category>

<category label="30050">
<setting label="30051" id="thumbnails" type="action" option="close" action="RunPlugin(plugin://$ID/?action=thumbnails)"/>
</category>
</settings>
7 changes: 5 additions & 2 deletions tver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
URL_LIST_EPISODES = URL_TAG_SEARCH_WS + '?platform_uid={}&platform_token={}'
URL_VIDEO_WEBSITE = 'https://tver.jp/{}s/{}'
URL_VIDEO_PICTURE = 'https://statics.tver.jp/images/content/thumbnail/{}/small/{}.jpg'
URL_VIDEO_CONTENT = 'https://statics.tver.jp/content/{}/{}.json'

CATEGORIES = [
("variety",localize(30005), get_custom_img_path("variety.jpg")),
Expand Down Expand Up @@ -60,12 +61,14 @@ def get_episodes(category):
if video_type == 'episode':
series_id = episode['content']['seriesID']
video_id = episode['content']['id']
label = ' '.join(filter(None, [strip_or_none(episode['content']['seriesTitle']), strip_or_none(episode['content']['title'])]))
series_title = strip_or_none(episode['content']['seriesTitle'])
label = ' '.join(filter(None, [series_title, strip_or_none(episode['content']['title'])]))
episodes.append({ 'name': label,
'series': series_id,
'thumb': URL_VIDEO_PICTURE.format(video_type, video_id),
'video': URL_VIDEO_WEBSITE.format(video_type, video_id),
'genre': category })
'genre': category,
'series_title': series_title })

return episodes

Expand Down
26 changes: 24 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import xbmcaddon
import xbmcgui

import sqlite3 as sql

from random import randint
from urllib.parse import urlencode

Expand Down Expand Up @@ -66,6 +68,7 @@ def strptime(date_string, format):

def extract_info(url):
from lib.yt_dlp import YoutubeDL
from lib.yt_dlp.extractor.tver import TVerIE

patch_strptime()

Expand All @@ -74,7 +77,7 @@ def extract_info(url):
}

ydl = YoutubeDL(ydl_opts)
ydl.add_default_info_extractors()
ydl.add_info_extractor(TVerIE())
info = ydl.extract_info(url, download=False)
return info

Expand Down Expand Up @@ -141,4 +144,23 @@ def refresh():
xbmc.executebuiltin("Container.Refresh")

def localize(string_id):
return xbmcaddon.Addon().getLocalizedString(string_id)
return xbmcaddon.Addon().getLocalizedString(string_id)

def clear_thumbnails():
from xbmcvfs import translatePath, delete
texturesDb = lookup_db("Textures")
thumbnailsPath = translatePath("special://thumbnails/")

conn = sql.connect(texturesDb)
try:
with conn:
textures = conn.execute("SELECT id, cachedurl FROM texture WHERE url LIKE '%%%s%%';" % "statics.tver.jp")
for texture in textures:
conn.execute("DELETE FROM sizes WHERE idtexture LIKE '%s';" % texture[0])
try:
delete( thumbnailsPath + texture[1])
except:
pass
conn.execute("DELETE FROM texture WHERE url LIKE '%%%s%%';" % "statics.tver.jp")
except:
pass

0 comments on commit 764b890

Please sign in to comment.