Created
May 7, 2016 13:34
-
-
Save Nama/ee13131c6a00a9f958f366a929e605fd to your computer and use it in GitHub Desktop.
Send various Youtube-Links to kodi over TCP. No need for the webinterface. TCP needs to be enabled. List and Channel links arent implemented yet.
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
#!/usr/bin/python | |
import os | |
from sys import argv | |
import socket | |
from random import randrange | |
import urllib.parse | |
yt_vid_add = {"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 1, "item": {"file": "plugin://plugin.video.youtube/play/?video_id="}}} | |
playlist_clear = {"jsonrpc": "2.0", "method": "Playlist.Clear", "params": {"playlistid": 1}} | |
playlist_play = {"jsonrpc": "2.0", "method": "Player.Open", "params": {"item": {"playlistid": 1, "position": 0}}} | |
def parse_yt_link(link): | |
url_data = urllib.parse.urlparse(link) | |
try: | |
# Long Youtube Video-URL | |
query = urllib.parse.parse_qs(url_data.query) | |
link_id = query['v'][0] | |
# Playlist-URL | |
# query = urllib.parse.parse_qs(url_data.query) | |
# link_id = query['list'][0] | |
except: | |
# Short Youtube Video-URL | |
link_id = url_data.path[1:] | |
return link_id | |
def yt_video(link, play): | |
video = parse_yt_link(link) | |
jsonstring = yt_vid_add | |
jsonstring['params']['item']['file'] += video | |
cmd_id = randrange(1, 1000) | |
jsonstring['id'] = cmd_id | |
if play: | |
sendlist = [playlist_clear, jsonstring, playlist_play] | |
else: | |
sendlist = jsonstring | |
s.send(str(sendlist).replace('\'', '"').encode()) | |
returncode = s.recv(1024).decode() | |
if __name__ == '__main__': | |
ip = 123.456.789.1 | |
port = 9090 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((ip, port)) | |
yt_video(argv[1], True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment