Skip to content

Commit

Permalink
Additional fixes and compatibility shims for playing AudioItems #873
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Aug 25, 2024
1 parent 3699499 commit 4377cc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions resources/lib/youtube_plugin/kodion/items/media_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def set_mediatype(self, mediatype):
self._mediatype = self._DEFAULT_MEDIATYPE

def get_mediatype(self):
return self._mediatype
return self._mediatype or self._DEFAULT_MEDIATYPE

def set_plot(self, plot):
try:
Expand Down Expand Up @@ -381,7 +381,7 @@ def playlist_item_id(self, value):


class AudioItem(MediaItem):
_ALLOWABLE_MEDIATYPES = {'song', 'album', 'artist'}
_ALLOWABLE_MEDIATYPES = {CONTENT.AUDIO_TYPE, 'song', 'album', 'artist'}
_DEFAULT_MEDIATYPE = CONTENT.AUDIO_TYPE

def __init__(self, name, uri, image='DefaultAudio.png', fanart=None):
Expand All @@ -396,7 +396,7 @@ def get_album_name(self):


class VideoItem(MediaItem):
_ALLOWABLE_MEDIATYPES = {'video',
_ALLOWABLE_MEDIATYPES = {CONTENT.VIDEO_TYPE,
'movie',
'tvshow', 'season', 'episode',
'musicvideo'}
Expand Down
25 changes: 18 additions & 7 deletions resources/lib/youtube_plugin/kodion/items/xbmc/xbmc_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,20 @@ def set_info(list_item, item, properties, set_play_count=True, resume=True):

resume_time = resume and item.get_start_time()
duration = item.get_duration()
if resume_time and duration:
info_tag.setResumePoint(resume_time, float(duration))
elif resume_time:
info_tag.setResumePoint(resume_time)
if info_type == 'video' and duration:
info_tag.addVideoStream(xbmc.VideoStreamDetail(duration=duration))
if info_type == 'video':
if resume_time and duration:
info_tag.setResumePoint(resume_time, float(duration))
elif resume_time:
info_tag.setResumePoint(resume_time)
if duration:
info_tag.addVideoStream(xbmc.VideoStreamDetail(duration=duration))
elif info_type == 'music':
# These properties are deprecated but there is no other way to set these
# details for a ListItem with a MusicInfoTag
if resume_time:
properties['ResumeTime'] = str(resume_time)
if duration:
properties['TotalTime'] = str(duration)

# duration: int
# As seconds
Expand All @@ -346,7 +354,10 @@ def set_info(list_item, item, properties, set_play_count=True, resume=True):
value = item.get_play_count()
if value is not None:
if set_play_count:
info_tag.setPlaycount(value)
if info_type == 'video':
info_tag.setPlaycount(value)
elif info_type == 'music':
info_tag.setPlayCount(value)
properties[PLAY_COUNT] = value

# count: int
Expand Down
6 changes: 4 additions & 2 deletions resources/lib/youtube_plugin/youtube/helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from math import log10

from ...kodion.constants import CONTENT, LICENSE_TOKEN, LICENSE_URL, PATHS
from ...kodion.items import DirectoryItem, menu_items
from ...kodion.items import AudioItem, DirectoryItem, menu_items
from ...kodion.utils import (
datetime_parser,
friendly_number,
Expand Down Expand Up @@ -431,7 +431,9 @@ def update_video_infos(provider, context, video_id_dict,

media_item = video_id_dict[video_id]
media_item.set_mediatype(
CONTENT.AUDIO_TYPE if audio_only else CONTENT.VIDEO_TYPE
CONTENT.AUDIO_TYPE
if audio_only or isinstance(media_item, AudioItem) else
CONTENT.VIDEO_TYPE
)

play_data = use_play_data and yt_item.get('play_data')
Expand Down

0 comments on commit 4377cc3

Please sign in to comment.