New API method to retrieve only filename

This commit is contained in:
Croneter 2018-03-27 08:01:24 +02:00
parent bfd4415fa1
commit d7891d6ec2
2 changed files with 18 additions and 14 deletions

View file

@ -112,6 +112,22 @@ class API(object):
"""
return self.item[self.mediastream][self.part]
def file_name(self, force_first_media=False):
"""
Returns only the filename, e.g. 'movie.mkv' as unicode or None if not
found
"""
ans = self.file_path(force_first_media=force_first_media)
if ans is None:
return
if "\\" in ans:
# Local path
filename = ans.rsplit("\\", 1)[1]
else:
# Network share
filename = ans.rsplit("/", 1)[1]
return filename
def file_path(self, force_first_media=False):
"""
Returns the direct path to this item, e.g. '\\NAS\movies\movie.mkv'

View file

@ -288,13 +288,7 @@ class Movies(Items):
scraper='metadata.local')
if do_indirect:
# Set plugin path and media flags using real filename
filename = api.file_path(force_first_media=True)
if "\\" in filename:
# Local path
filename = filename.rsplit("\\", 1)[1]
else:
# Network share
filename = filename.rsplit("/", 1)[1]
filename = api.file_name(force_first_media=True)
path = 'plugin://%s.movies/' % v.ADDON_ID
filename = ('%s?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (path, itemid, v.PLEX_TYPE_MOVIE, filename))
@ -857,13 +851,7 @@ class TVShows(Items):
else:
# Set plugin path - do NOT use "intermediate" paths for the show
# as with direct paths!
filename = api.file_path(force_first_media=True)
if "\\" in filename:
# Local path
filename = filename.rsplit("\\", 1)[1]
else:
# Network share
filename = filename.rsplit("/", 1)[1]
filename = api.file_name(force_first_media=True)
path = 'plugin://%s.tvshows/' % v.ADDON_ID
filename = ('%s?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (path, itemid, v.PLEX_TYPE_EPISODE, filename))