From b1ddeadca12fe37adb756c0b9e27e76109b4446c Mon Sep 17 00:00:00 2001 From: Clinton Ebadi Date: Fri, 22 Nov 2019 20:52:56 -0500 Subject: [PATCH] Add basic youtube upload support Rather than using the Kodi youtube extension, this downloads the video and extracts the audio has vorbis in order to apply replaygain. Otherwise videos can be jarringly louder than music that's properly replaygained. This also has the benefit of working on the upstream Kodi and not just my patched version that allows queuing videos when in party mode without quitting party mode instantly. No error checking whatsoever, and no attempt is made to display good metadata in the queue yet. --- party-upload/normals.cgi | 2 +- party-upload/partyparty.py | 32 ++++++++++++++++++++++++++++++++ party-upload/youtube.html | 28 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 party-upload/youtube.html diff --git a/party-upload/normals.cgi b/party-upload/normals.cgi index 40de5b8..d05378b 100755 --- a/party-upload/normals.cgi +++ b/party-upload/normals.cgi @@ -42,7 +42,7 @@ sys.stdout.flush () print ("\npartyparty beb") print (partyparty.css ()) -print '

Upload A Song | home | browse

' +print '

Upload A Song | Add From YouTube | home | browse

' diff --git a/party-upload/partyparty.py b/party-upload/partyparty.py index e3d222d..21886c0 100644 --- a/party-upload/partyparty.py +++ b/party-upload/partyparty.py @@ -25,6 +25,7 @@ import subprocess from xbmcjson import XBMC import urllib from yattag import Doc +import youtube_dl xbmc = None @@ -209,6 +210,33 @@ class Upload: self.attempt_rpgain () return self.filename +class Youtube: + upload_dir = '/srv/archive/incoming/youtube-moosic' + ydl_opts = { + 'format': 'bestaudio/best', + 'outtmpl': upload_dir + '/%(id)s.%(ext)s', + 'quiet': True, + 'postprocessors': [ + { + 'key': 'FFmpegMetadata', + }, + { + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'vorbis', + }], + + } + + def __init__ (self, form, field): + self.ydl = youtube_dl.YoutubeDL(self.ydl_opts) + self.url = form.getvalue (field) + + def save (self): + info = self.ydl.extract_info (self.url, download=True) + filename = '{}/{}.ogg'.format (self.upload_dir, info['display_id']) + subprocess.call (["/usr/bin/vorbisgain", "-q", filename]) + return filename + def css (): doc, tag, text = Doc ().tagtext () @@ -335,6 +363,10 @@ class PartyManager: upload = Upload (form, 'song') filename = upload.save () self.randomqueue ({"file": filename}, 1 if 'asap' not in form else 3) + elif 'youtubego' in form: + youtube = Youtube (form, 'youtubeurl') + filename = youtube.save () + self.randomqueue ({"file": filename}, 1 if 'asap' not in form else 3) elif 'partyon' in form: if 'error' in xbmc.Player.SetPartymode (partymode=True, playerid=0): xbmc.Player.Open (item={"partymode": "music"}) diff --git a/party-upload/youtube.html b/party-upload/youtube.html new file mode 100644 index 0000000..c915c60 --- /dev/null +++ b/party-upload/youtube.html @@ -0,0 +1,28 @@ + + + + + + +
+

+ + + + + + +

+
+ + -- 2.20.1