Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #76 #79

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 61 additions & 40 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def showErrorNotification(message):
xbmcgui.NOTIFICATION_ERROR, 5000)


def get_user_input():
GautamMKGarg marked this conversation as resolved.
Show resolved Hide resolved
kb = xbmc.Keyboard('', 'Please enter the URL')
GautamMKGarg marked this conversation as resolved.
Show resolved Hide resolved
kb.doModal() # Onscreen keyboard appears
if not kb.isConfirmed():
return ''

# User input
return kb.getText()


# Get the plugin url in plugin:// notation.
__url__ = sys.argv[0]
# Get the plugin handle as an integer number.
Expand All @@ -60,6 +70,10 @@ def showErrorNotification(message):
def getParams():
result = {}
GautamMKGarg marked this conversation as resolved.
Show resolved Hide resolved
paramstring = sys.argv[2]

if paramstring == '':
GautamMKGarg marked this conversation as resolved.
Show resolved Hide resolved
paramstring = "?" + get_user_input()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know this but for what reason is the ? needed? May maybe something like the following would be more direct

if not paramstring:
  result['url'] = paramstring[1:]
else:
  result['url'] = get_local_user_input()
  

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that in future we might need to give option to user to select video quality, or pass any other customer parameters. That's why I did not pass URL directly in url variable. Kindly suggest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would even then suggest to explicitly return the result dict already correctly assigned to the keys instead of parsing it from a string.

Forcing a quality via the resolver will not really be possible anymore. Basically all streams are now fragmented with a manifest. Many still provide one legacy all in one stream where there is not much to choose from. For Kodi you can set the desired quality of a fragmented stream within the adaptive input stream addon. We partially supported manifest since the last PR we were testing so much.


additionalParamsIndex = paramstring.find(' ')
if additionalParamsIndex == -1:
result['url'] = paramstring[1:]
Expand All @@ -72,6 +86,50 @@ def getParams():
return result


def play(url, ydl_opts):
if xbmcplugin.getSetting(int(sys.argv[1]),"usemanifest"):
ydl_opts['format'] = 'bestvideo*+bestaudio/best'
ydl = YoutubeDL(ydl_opts)
ydl.add_default_info_extractors()

with ydl:
showInfoNotification("Resolving stream(s) for " + url)
result = ydl.extract_info(url, download=False)

if 'entries' in result:
# more than one video
pl = xbmc.PlayList(1)
pl.clear()

# determine which index in the queue to start playing from
indexToStartAt = playlistIndex(url, result)
if indexToStartAt == None:
indexToStartAt = 0

unresolvedEntries = list(result['entries'])
startingEntry = unresolvedEntries.pop(indexToStartAt)

# populate the queue with unresolved entries so that the starting entry can be inserted
for video in unresolvedEntries:
list_item = createListItemFromFlatPlaylistItem(video)
pl.add(list_item.getPath(), list_item)

# make sure the starting ListItem has a resolved url, to avoid recursion and crashes
startingVideoUrl = startingEntry['url']
startingItem = createListItemFromVideo(ydl.extract_info(startingVideoUrl, download=False))
pl.add(startingItem.getPath(), startingItem, indexToStartAt)

#xbmc.Player().play(pl) # this probably works again
# ...but start playback the same way the Youtube plugin does it:
xbmc.executebuiltin('Playlist.PlayOffset(%s,%d)' % ('video', indexToStartAt))

showInfoNotification("Playing playlist " + result['title'])
else:
# Just a video, pass the item to the Kodi player.
showInfoNotification("Playing title " + result['title'])
xbmcplugin.setResolvedUrl(__handle__, True, listitem=createListItemFromVideo(result))


def extract_manifest_url(result):
# sometimes there is an url directly
# but for some extractors this is only one quality and sometimes not even a real manifest
Expand Down Expand Up @@ -252,44 +310,7 @@ def playlistIndex(url, playlist):
params = getParams()
url = str(params['url'])
GautamMKGarg marked this conversation as resolved.
Show resolved Hide resolved
ydl_opts.update(params['ydlOpts'])
if xbmcplugin.getSetting(int(sys.argv[1]),"usemanifest"):
ydl_opts['format'] = 'bestvideo*+bestaudio/best'
ydl = YoutubeDL(ydl_opts)
ydl.add_default_info_extractors()

with ydl:
showInfoNotification("Resolving stream(s) for " + url)
result = ydl.extract_info(url, download=False)

if 'entries' in result:
# more than one video
pl = xbmc.PlayList(1)
pl.clear()

# determine which index in the queue to start playing from
indexToStartAt = playlistIndex(url, result)
if indexToStartAt == None:
indexToStartAt = 0

unresolvedEntries = list(result['entries'])
startingEntry = unresolvedEntries.pop(indexToStartAt)

# populate the queue with unresolved entries so that the starting entry can be inserted
for video in unresolvedEntries:
list_item = createListItemFromFlatPlaylistItem(video)
pl.add(list_item.getPath(), list_item)

# make sure the starting ListItem has a resolved url, to avoid recursion and crashes
startingVideoUrl = startingEntry['url']
startingItem = createListItemFromVideo(ydl.extract_info(startingVideoUrl, download=False))
pl.add(startingItem.getPath(), startingItem, indexToStartAt)

#xbmc.Player().play(pl) # this probably works again
# ...but start playback the same way the Youtube plugin does it:
xbmc.executebuiltin('Playlist.PlayOffset(%s,%d)' % ('video', indexToStartAt))

showInfoNotification("Playing playlist " + result['title'])
if url == '':
showInfoNotification("Kindly provide the valid URL.")
else:
# Just a video, pass the item to the Kodi player.
showInfoNotification("Playing title " + result['title'])
xbmcplugin.setResolvedUrl(__handle__, True, listitem=createListItemFromVideo(result))
play(url, ydl_opts)