[vlc-commits] share: add wrapper script for the YoutubeDL Python module
Rémi Denis-Courmont
git at videolan.org
Sun Sep 27 15:16:39 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Sep 20 21:36:57 2020 +0300| [3f5d4031d90692bd532ac46308f00572cb76bf50] | committer: Rémi Denis-Courmont
share: add wrapper script for the YoutubeDL Python module
This script generates a JSON playlist from a given URL, providing a
simple serial format that can be read and parsed by another process.
The JSON schema is the same as YoutubeDL's.
There are in principles two other alternative ways to access it:
1) Calling the YoutubeDL module directly in-process through CPython.
This poses a number of problems:
- CPython must be loaded by the main executable. Python modules will
fail to resolve their CPython symbols otherwise.
- Multiple CPython interpreters are still very immature; GIL behaves
weirdly. CPython is really not meant for multithread.
- The GIL prevents concurrent uses (that's the whole point of it).
- CPython network I/O cannot be interrupted by VLC interruptions, so
the calling thread may get stuck inside CPython.
- A build-time dependency on CPython is added.
2) Calling the YouTubeDL executable directly. This is impractical
because logging infos get interleaved on the standard output
alongside the proper output data. Worse yet, there are no obvious
ways to separate (flat) playlist extraction and item parsing
(which becomes necessary in a later patch in the series).
3) Using a playlist format already supported by VLC (as done in
previous versions of the patchest). This causes loss of potentially
useful information.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3f5d4031d90692bd532ac46308f00572cb76bf50
---
share/Makefile.am | 2 ++
share/ytdl-extract.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/share/Makefile.am b/share/Makefile.am
index 2373ffbe91..8a92f04360 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -49,6 +49,8 @@ nobase_dist_pkgdata_SCRIPTS = \
utils/audio-vlc-default.sh \
utils/video-vlc-default.sh \
$(NULL)
+
+dist_pkgdata_SCRIPTS = ytdl-extract.py
endif
EXTRA_DIST += \
diff --git a/share/ytdl-extract.py b/share/ytdl-extract.py
new file mode 100755
index 0000000000..107a77ec13
--- /dev/null
+++ b/share/ytdl-extract.py
@@ -0,0 +1,46 @@
+#! /usr/bin/python3
+#
+# Copyright (C) 2020 Rémi Denis-Courmont
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+
+import sys
+import json
+import youtube_dl
+
+class logger(object):
+ def debug(self, msg):
+ pass
+
+ def warning(self, msg):
+ pass
+
+ def error(self, msg):
+ sys.stderr.write(msg + '\n')
+
+def url_extract(url):
+ opts = {
+ 'logger': logger(),
+ 'youtube_include_dash_manifest': False,
+ }
+
+ dl = youtube_dl.YoutubeDL(opts)
+
+ # Process a given URL
+ infos = dl.extract_info(url, download=False)
+ print(json.dumps(infos))
+
+url = sys.argv[1]
+url_extract(url)
More information about the vlc-commits
mailing list