├── setup.py ├── README.md ├── .gitignore ├── LICENSE └── party.py /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from setuptools import setup, find_packages 4 | 5 | version = "0.0.1" 6 | 7 | setup( 8 | name='vlc-random-videoclip', 9 | version=version, 10 | description='Play a random videoclip in vlc', 11 | author='Nikolai Nowaczyk', 12 | author_email='mail@nikno.de', 13 | license='MIT', 14 | packages=find_packages(), 15 | install_requires=['python-vlc'] 16 | ) 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # System Requirements 2 | This script has been tested with Python 3 and Windows 7. It also needs FFmpeg. 3 | 4 | # Installation 5 | * `git clone` this repo. 6 | * Execute `python setup.py install`. 7 | * Download [FFMpeg](http://ffmpeg.zeranoe.com/builds/), extract the folder and put the `ffprobe.exe` in your local repo. 8 | 9 | # Usage 10 | * Create a subfolder `videos` in your local version of the repo and put all the videos you want the script to choose from into that folder. 11 | * Run with `python party.py`. 12 | 13 | # Configuration 14 | * Change the variable `videos` in the script to use a different folder. 15 | * Change the variable `interval` to play longer or shorter clips. 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | videos/ 2 | *.exe 3 | *.mp4 4 | venv/ 5 | 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | env/ 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *,cover 51 | .hypothesis/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | 60 | # Sphinx documentation 61 | docs/_build/ 62 | 63 | # PyBuilder 64 | target/ 65 | 66 | #Ipython Notebook 67 | .ipynb_checkpoints 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Nikolai Nowaczyk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /party.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | import subprocess 4 | import vlc 5 | import os 6 | 7 | # create list of all videos in folder 'videos' 8 | subfolder = "videos" 9 | videos = os.listdir(subfolder) 10 | 11 | # specify clip length 12 | intervall = 3 # seconds 13 | 14 | # setup vlc instance 15 | player = vlc.MediaPlayer() 16 | 17 | try: 18 | print("Script running... press Ctrl+C to quit.") 19 | while True: 20 | # choose random file number 21 | n = random.randint(0, len(videos) - 1) 22 | 23 | # create path to current video file 24 | video = os.path.join(subfolder, videos[n]) 25 | 26 | # get length of video n using ffprobe 27 | ffprobe = subprocess.check_output(['ffprobe', video], 28 | shell=True, 29 | stderr=subprocess.STDOUT) 30 | 31 | # calculate length of current video in seconds 32 | i = ffprobe.find(bytes("Duration:", 'UTF-8')) 33 | duration = ffprobe[i + 9:i + 9 + 12].decode('UTF-8').strip().split(":") 34 | length = int(int(duration[0]) * 3600 + 35 | int(duration[1]) * 60 + 36 | float(duration[2]) 37 | ) 38 | 39 | # create random position in video n 40 | position = random.randint(0, length - intervall) 41 | 42 | # feed player with video and position 43 | player.set_mrl(video) 44 | player.play() 45 | player.set_time(position * 1000) 46 | 47 | # wait till next video 48 | time.sleep(intervall) 49 | except KeyboardInterrupt: 50 | pass 51 | --------------------------------------------------------------------------------