From ba9289e05184ae2eecc34ad0d7e9d7aa9e071553 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Tue, 25 May 2021 14:15:23 +0300 Subject: [PATCH] minor fix for vlc init --- app/tools/media.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/app/tools/media.py b/app/tools/media.py index adbbc53c..3fdf4cc2 100644 --- a/app/tools/media.py +++ b/app/tools/media.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 Dmitriy Yefremov +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# Author: Dmitriy Yefremov +# + + import os import sys from abc import ABC, abstractmethod @@ -328,6 +356,9 @@ class VlcPlayer(Player): def __init__(self, mode, widget, buf_cb, position_cb, error_cb, playing_cb): try: + if sys.platform == "win32": + os.add_dll_directory(r"C:\Program Files\VideoLAN\VLC") + from app.tools import vlc from app.tools.vlc import EventType @@ -335,7 +366,7 @@ class VlcPlayer(Player): self._player = vlc.Instance(args).media_player_new() vlc.libvlc_video_set_key_input(self._player, False) vlc.libvlc_video_set_mouse_input(self._player, False) - except (OSError, AttributeError) as e: + except (OSError, AttributeError, NameError) as e: log("{}: Load library error: {}".format(__class__.__name__, e)) raise ImportError("No VLC is found. Check that it is installed!") else: @@ -414,7 +445,7 @@ class VlcPlayer(Player): elif sys.platform == "darwin": self._player.set_nsobject(self.get_window_handle(video_widget)) else: - log("Video widget initialization error: platform '{}' is not supported. ".format(sys.platform)) + self._player.set_hwnd(self.get_window_handle(video_widget)) class Recorder: @@ -425,6 +456,9 @@ class Recorder: def __init__(self, settings): try: + if sys.platform == "win32": + os.add_dll_directory(r"C:\Program Files\VideoLAN\VLC") + from app.tools import vlc from app.tools.vlc import EventType except OSError as e: @@ -450,7 +484,7 @@ class Recorder: path = self._settings.records_path os.makedirs(os.path.dirname(path), exist_ok=True) d_now = datetime.now().strftime(_DATE_FORMAT) - path = "{}{}_{}".format(path, name.replace(" ", "_"), d_now.replace(" ", "_")) + path = "{}{}_{}".format(path, name.replace(" ", "_"), d_now.replace(" ", "_").replace(":", "-")) cmd = self.get_transcoding_cmd(path) if self._settings.activate_transcoding else self._CMD.format(path) media = self._recorder.get_instance().media_new(url, cmd) media.get_mrl()