mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
use new DatabaseCon context object for play websocket play actions
This commit is contained in:
parent
d3ce04ab10
commit
b3214a9250
2 changed files with 53 additions and 51 deletions
|
@ -129,6 +129,7 @@ class DatabaseConn(object):
|
||||||
if self.db_file == "video":
|
if self.db_file == "video":
|
||||||
kodi_commit()
|
kodi_commit()
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
log.info("commit: %s", self.path)
|
||||||
|
|
||||||
log.info("close: %s", self.path)
|
log.info("close: %s", self.path)
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
|
@ -12,6 +12,8 @@ import playbackutils
|
||||||
import embydb_functions as embydb
|
import embydb_functions as embydb
|
||||||
import read_embyserver as embyserver
|
import read_embyserver as embyserver
|
||||||
from utils import window, kodiSQL, JSONRPC
|
from utils import window, kodiSQL, JSONRPC
|
||||||
|
from database import DatabaseConn
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
@ -29,77 +31,76 @@ class Playlist(object):
|
||||||
|
|
||||||
def play_all(self, item_ids, start_at):
|
def play_all(self, item_ids, start_at):
|
||||||
|
|
||||||
conn = kodiSQL('emby')
|
with DatabaseConn('emby') as conn:
|
||||||
cursor = conn.cursor()
|
with closing(conn.cursor()) as cursor:
|
||||||
emby_db = embydb.Embydb_Functions(cursor)
|
emby_db = embydb.Embydb_Functions(cursor)
|
||||||
|
|
||||||
player = xbmc.Player()
|
player = xbmc.Player()
|
||||||
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
||||||
playlist.clear()
|
playlist.clear()
|
||||||
|
|
||||||
log.info("---*** PLAY ALL ***---")
|
log.info("---*** PLAY ALL ***---")
|
||||||
log.info("Items: %s and start at: %s", item_ids, start_at)
|
log.info("Items: %s and start at: %s", item_ids, start_at)
|
||||||
|
|
||||||
started = False
|
started = False
|
||||||
window('emby_customplaylist', value="true")
|
window('emby_customplaylist', value="true")
|
||||||
|
|
||||||
if start_at:
|
if start_at:
|
||||||
# Seek to the starting position
|
# Seek to the starting position
|
||||||
window('emby_customplaylist.seektime', str(start_at))
|
window('emby_customplaylist.seektime', str(start_at))
|
||||||
|
|
||||||
for item_id in item_ids:
|
for item_id in item_ids:
|
||||||
|
|
||||||
log.info("Adding %s to playlist", item_id)
|
log.info("Adding %s to playlist", item_id)
|
||||||
item = emby_db.getItem_byId(item_id)
|
item = emby_db.getItem_byId(item_id)
|
||||||
try:
|
try:
|
||||||
db_id = item[0]
|
db_id = item[0]
|
||||||
media_type = item[4]
|
media_type = item[4]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Item is not found in our database, add item manually
|
# Item is not found in our database, add item manually
|
||||||
log.info("Item was not found in the database, manually adding item")
|
log.info("Item was not found in the database, manually adding item")
|
||||||
item = self.emby.getItem(item_id)
|
item = self.emby.getItem(item_id)
|
||||||
self.add_to_xbmc_playlist(playlist, item)
|
self.add_to_xbmc_playlist(playlist, item)
|
||||||
|
|
||||||
else: # Add to playlist
|
else: # Add to playlist
|
||||||
self.add_to_playlist(db_id, media_type)
|
self.add_to_playlist(db_id, media_type)
|
||||||
|
|
||||||
if not started:
|
if not started:
|
||||||
started = True
|
started = True
|
||||||
player.play(playlist)
|
player.play(playlist)
|
||||||
|
|
||||||
self.verify_playlist()
|
self.verify_playlist()
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
def modify_playlist(self, item_ids):
|
def modify_playlist(self, item_ids):
|
||||||
|
|
||||||
conn = kodiSQL('emby')
|
with DatabaseConn('emby') as conn:
|
||||||
cursor = conn.cursor()
|
with closing(conn.cursor()) as cursor:
|
||||||
emby_db = embydb.Embydb_Functions(cursor)
|
emby_db = embydb.Embydb_Functions(cursor)
|
||||||
|
|
||||||
log.info("---*** ADD TO PLAYLIST ***---")
|
log.info("---*** ADD TO PLAYLIST ***---")
|
||||||
log.info("Items: %s", item_ids)
|
log.info("Items: %s", item_ids)
|
||||||
|
|
||||||
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
||||||
|
|
||||||
for item_id in item_ids:
|
for item_id in item_ids:
|
||||||
|
|
||||||
log.info("Adding %s to playlist", item_id)
|
log.info("Adding %s to playlist", item_id)
|
||||||
item = emby_db.getItem_byId(item_id)
|
item = emby_db.getItem_byId(item_id)
|
||||||
try:
|
try:
|
||||||
db_id = item[0]
|
db_id = item[0]
|
||||||
media_type = item[4]
|
media_type = item[4]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Item is not found in our database, add item manually
|
# Item is not found in our database, add item manually
|
||||||
item = self.emby.getItem(item_id)
|
item = self.emby.getItem(item_id)
|
||||||
self.add_to_xbmc_playlist(playlist, item)
|
self.add_to_xbmc_playlist(playlist, item)
|
||||||
|
|
||||||
else: # Add to playlist
|
else: # Add to playlist
|
||||||
self.add_to_playlist(db_id, media_type)
|
self.add_to_playlist(db_id, media_type)
|
||||||
|
|
||||||
self.verify_playlist()
|
self.verify_playlist()
|
||||||
cursor.close()
|
|
||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in a new issue