• Link to Youtube
  • Link to Reddit
  • Link to Soundcloud
  • Link to X
  • Link to Mail
  • Link to Discord
  • Link to Twitch
N.E.M. Productions
  • Home
  • Blog
  • Adam
  • Donation
  • Menu Menu
All The Things, Personal Work, Projects

Wanna Play a Random Movie? No Problem!

I’m back again with a short script that I just figured out using a few Python libraries including “subprocess”, “random”, and “glob”. It’s been a while since I’ve delved into Python, and with no surprise to me, I forgot most everything I knew about the language. Again. The only thing I haven’t forgotten is my ability to Google-fu anything I need to find, so figuring it out and refreshing my brain on something so simple wasn’t too hard to do. It works by using the glob library to grab all of the files in my Movies folder, as well as all of the subdirectories for things like movie series, etc., find the different file types associated with video files (.avi, .mp4, .mkv), using the random library to make a random selection from the acrued list, and the subprocess library to run the bash command to open VLC and play the random selection.

 

Moving forward I plan to expand the script by adding more functionality by being able to make a playlist of a certain amount of movies, and also be able to see if the movie is part of a series (based on it’s parent folder) so it can either play the first one or add all of the related movies to the playlist. The script can also be modified to show music, pdf, really any kind of file you are looking for, and open it, or use that information to do any number of imaginable things.

 

import glob
import random
import subprocess

project_files = glob.glob(‘/media/rawrface//My Passport/Movies/**/*.mp4’) + glob.glob(‘/media/rawrface//My Passport/Movies/**/*.avi’) + glob.glob(‘/media/rawrface//My Passport/**/*.mkv’)

play = random.choice(project_files)

subprocess.run([“vlc”, play, “–fullscreen”])

#in order to use glob.glob() to see things in directories and sub directories you do “directory/**/*.extension”
#in subprocess.run the bash command goes in “”, and after a comma you can run a python variable

September 10, 2021/by Adam Maddox
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://thisisnem.com/wp-content/uploads/2019/11/2019-10-24-10-00-53_front-300x200.png 0 0 Adam Maddox https://thisisnem.com/wp-content/uploads/2019/11/2019-10-24-10-00-53_front-300x200.png Adam Maddox2021-09-10 16:53:552021-09-10 16:53:55Wanna Play a Random Movie? No Problem!

Pages

  • About Adam Maddox
  • Blog
  • Donate
  • Homepage
  • My events!

Categories

  • All The Things
  • Blog
  • Personal Work
  • Projects
  • Published Articles
  • Uncategorized

Archive

  • February 2022
  • September 2021
  • December 2020
  • November 2020
  • August 2020
  • July 2020
  • May 2020
  • April 2020
  • March 2020
  • April 2017

NEM started a little while ago when I got bored and thought I needed something to do. Thank you for checking out my shenanigans.

Important Links

  • Blog
  • Adam
  • Donate

Recent Posts

  • Automating ObsidianFebruary 21, 2022 - 3:45 pm
  • A New Coding AdventureSeptember 14, 2021 - 2:00 pm
  • Wanna Play a Random Movie? No Problem!September 10, 2021 - 4:53 pm
© Copyright - N.E.M. Productions | Hosted by JNL Hosting
  • Link to Youtube
  • Link to Reddit
  • Link to Soundcloud
  • Link to X
  • Link to Mail
  • Link to Discord
  • Link to Twitch
Link to: Mr. T (Rex) Link to: Mr. T (Rex) Mr. T (Rex) Link to: A New Coding Adventure Link to: A New Coding Adventure A New Coding Adventure
Scroll to top Scroll to top Scroll to top