[vlc-devel] [PATCH 1/4] share: add wrapper script for the YoutubeDL Python module

Steve Lhomme robux4 at ycbcr.xyz
Tue Sep 22 10:19:48 CEST 2020


On 2020-09-22 10:04, Rémi Denis-Courmont wrote:
> Marvin already explained to you that it just fails safe on error.

If you mean
"If the library is not there or its the wrong version so API does not 
match, it the script would just fail which IIUC is handled properly by 
the access module calling the script."

That's not the subject of my question. I'm asking if youtube-dl fails to 
find a suitable URL to point to, we seem to generate a M3U no matter 
what. If it generates an error that doesn't seem to be handled either 
(dunno how errors are passed in Python).

> 
> Le 22 septembre 2020 10:30:28 GMT+03:00, Steve Lhomme <robux4 at ycbcr.xyz> 
> a écrit :
> 
>     On 2020-09-22 9:16, Rémi Denis-Courmont wrote:
> 
>         Hi,
> 
>         No. That question was already addressed in more details in the
>         first
>         review thread.
> 
> 
>     I read it and I read it again. I found nothing that talks about error
>     handling in this script. So either point to the answer or provide an
>     answer. Thanks.
> 
>         Le 22 septembre 2020 08:35:04 GMT+03:00, Steve Lhomme
>         <robux4 at ycbcr.xyz>
>         a écrit :
> 
>         diff --git a/share/ytdl-extract.py b/share/ytdl-extract.py
>         new file mode 100755
>         index 0000000000..71c79e0156
>         --- /dev/null
>         +++ b/share/ytdl-extract.py
>         @@ -0,0 +1,102 @@
>         +#! /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 youtube_dl
>         +
>         +class logger(object):
>         + def debug(self, msg):
>         + pass
>         +
>         + def warning(self, msg):
>         + pass
>         +
>         + def error(self, msg):
>         + sys.stderr.write(msg)
>         +
>         +def formats_choose_best(fmts):
>         + # Pick our preferred format out of many
>         + best_abr = -1
>         + best_height = -1
>         + best_format = None
>         +
>         + for f in fmts:
>         + if 'height' in f and f['height']:
>         + height = f['height']
>         + else:
>         + height = 0
>         +
>         + if height < best_height:
>         + continue
>         +
>         + if 'abr' in f and f['abr']:
>         + abr = f['abr']
>         + else:
>         + abr = 0
>         +
>         + if height == best_height or abr < best_abr:
>         + continue
>         +
>         + best_abr = abr
>         + best_height = height
>         + best_format = f
>         +
>         + return best_format
>         +
>         +def entry_extract(entry):
>         + # Process a given entry of a playlist
>         + if 'formats' in entry:
>         + fmt = formats_choose_best(entry['formats'])
>         + else:
>         + fmt = entry
>         +
>         + if 'title' in entry:
>         + print('#EXTINF:,,' + entry['title'].splitlines()[0])
>         +
>         + if 'url' in fmt:
>         + print('#EXTVLCOPT:no-ytdl') # don't parse recursively
>         + print(fmt['url'])
>         + else:
>         + print('vlc://nop')
>         +
>         +def url_extract(url):
>         + opts = {
>         + 'logger': logger(),
>         + }
>         +
>         + dl = youtube_dl.YoutubeDL(opts)
>         + #dl.add_default_info_extractors()
>         +
>         + # Process a given URL
>         + infos = dl.extract_info(url, download=False)
> 
> 
>         What happens if there's an error here ? Should the function/script
>         return an error rather than an empty M3U ?
> 
>         +
>         + print('#EXTM3U')
>         +
>         + if 'title' in infos:
>         + print('#PLAYLIST:' + infos['title'].splitlines()[0])
>         +
>         + if 'entries' in infos:
>         + # URL is a playlist: iterate over entries
>         + for entry in infos['entries']:
>         + entry_extract(entry)
>         + else:
>         + # URL is a single media
>         + entry_extract(infos)
>         +
>         +
>         +url_extract(sys.argv[1])
>         -- 
>         2.28.0
>         ------------------------------------------------------------------------
>         vlc-devel mailing list
>         To unsubscribe or modify your subscription options:
>         https://mailman.videolan.org/listinfo/vlc-devel
> 
> 
>         -- 
>         Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez
>         excuser
>         ma brièveté.
>         ------------------------------------------------------------------------
>         vlc-devel mailing list
>         To unsubscribe or modify your subscription options:
>         https://mailman.videolan.org/listinfo/vlc-devel
> 
>     ------------------------------------------------------------------------
>     vlc-devel mailing list
>     To unsubscribe or modify your subscription options:
>     https://mailman.videolan.org/listinfo/vlc-devel
> 
> 
> -- 
> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser 
> ma brièveté.
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list