-
-
Save ssalvatella/796079c90907dc91c6d9e0cd496e6566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Paquetes para la interfaz de Kodi | |
import xbmcaddon | |
import xbmcplugin | |
import xbmcgui | |
import pyxbmct | |
# Paquetes para Youtube | |
from apiclient.discovery import build | |
from apiclient.errors import HttpError | |
from oauth2client.tools import argparser | |
# Paquuete de Youtube DL | |
import YDStreamExtractor | |
import YDStreamUtils | |
# | |
# Busqueda en Youtube | |
# | |
# | |
DEVELOPER_KEY = "AIzaSyD2hO5vx5Sokce8QIH1PNIlUbgc36T_s5I" | |
YOUTUBE_API_SERVICE_NAME = "youtube" | |
YOUTUBE_API_VERSION = "v3" | |
addon_handle = int(sys.argv[1]) | |
def youtube_search(palabras_clave): | |
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, | |
developerKey=DEVELOPER_KEY) | |
# Call the search.list method to retrieve results matching the specified | |
# query term. | |
search_response = youtube.search().list( | |
q=palabras_clave, | |
part="id,snippet", | |
maxResults=25 | |
).execute() | |
videos = [] | |
channels = [] | |
playlists = [] | |
# Add each result to the appropriate list, and then display the lists of | |
# matching videos, channels, and playlists. | |
for search_result in search_response.get("items", []): | |
if search_result["id"]["kind"] == "youtube#video": | |
videos.append(search_result) | |
xbmc.log(str(search_result)) | |
return videos | |
# | |
# Cargar resultados | |
# Load the list of items | |
# | |
def construir_lista_canciones(videos): | |
lista_canciones = [] | |
xbmcplugin.setContent(addon_handle, 'songs') | |
for video in videos: | |
# Creamos un elemento de lista | |
li = xbmcgui.ListItem(label=video["snippet"]["title"], thumbnailImage=video["snippet"]["thumbnails"]["high"]["url"]) | |
# Indicamos la imagen de la cancion | |
li.setProperty('fanart_image', video["snippet"]["thumbnails"]["high"]["url"]) | |
li.setProperty('IsPlayable', 'true') | |
url = "%s?1%s" % (sys.argv[0], video["id"]["videoId"]) | |
urlDownload = "%s?2%s" % (sys.argv[0], video["id"]["videoId"]) | |
li.addContextMenuItems([('Descargar', 'XBMC.RunScript(' + urlDownload + ')')]) | |
xbmcplugin.addDirectoryItem(addon_handle, url, li, totalItems = 25) | |
# xbmcplugin.addDirectoryItems(handle=addon_handle, items=lista_canciones, totalItems=len(lista_canciones)) | |
xbmcplugin.endOfDirectory(addon_handle) | |
return None | |
# | |
# VentanaBusqueda | |
# Interfaz para introducir el texto de busqueda | |
# | |
class VentanaBusqueda(pyxbmct.AddonDialogWindow): | |
def __init__(self, titulo='Buscar cancion'): | |
# Llamamos al constructor heredado | |
super(VentanaBusqueda, self).__init__(titulo) | |
# Establecemos el tamano de ventana y distribucion | |
self.setGeometry(450, 240, 4, 3) | |
# Creamos una descripcion | |
descripcion = pyxbmct.Label('Youtube', alignment=pyxbmct.ALIGN_CENTER) | |
# Ponemos el texto en la ventana | |
self.placeControl(descripcion, 0,0, columnspan=3) | |
# Creamos una entrada de texto | |
self.busqueda = pyxbmct.Edit('') | |
self.placeControl(self.busqueda, 1, 0, columnspan=3) | |
# Creamos y situamos el boton de busqueda | |
boton_buscar = pyxbmct.Button('Buscar') | |
self.placeControl(boton_buscar, 2, 1, columnspan=1) | |
# Conectamos el boton con la funcion Buscar() | |
self.connect(boton_buscar, self.buscar) | |
def buscar(self): | |
texto = self.busqueda.getText() | |
resultados = youtube_search(texto) | |
self.close() | |
construir_lista_canciones(resultados) | |
# | |
# Main code | |
# | |
if sys.argv[2] == "": | |
# Search form to get Youtube ID | |
ventana = VentanaBusqueda() | |
ventana.doModal() | |
else: | |
YDStreamExtractor.disableDASHVideo(True) | |
idVideo = "http://www.youtube.com/watch?v=%s" % (sys.argv[2][2:]) | |
vid = YDStreamExtractor.getVideoInfo(idVideo, quality=1) | |
opcion = sys.argv[2][1] | |
#if (opcion == 1): # Visionado | |
# Playing selected item | |
item = xbmcgui.ListItem(path=vid.streamURL()) | |
#item = sys.listitem.setPath(vid.streamURL()) | |
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment