DEV Community

munazhé
munazhé

Posted on

[casdrop.py]: Casting media files in python to Chromecast from a desktop folder

 
REPO_LINK.GIT
 
 

What does it do?

So, I made a python script that connects to a Chromecast and plays video & audio (.mp4 || .mp3) as soon as you drop your file in the chromecast folder...

The idea came when I was looking for a quick way to share files onto my TV or Google Home Max without having to need a dedicated app. So, I hacked the b*tch!

On a serious note...

 
 

Here's what you need, before we get started:

A. Know the "friendly" name of your TV (CASDROP_TV_NAME) and Speaker (CASDROP_SPKR_NAME).

B. Make sure your machine is running python ~> 3.9.7 (not mandatory, but you need at least python 3).

C. Install all dependencies to run this program: pip install requirements.txt

 
 

Once that's done...

Step1. Open a new terminal on your unix/linux based computer

NOTE: I ran these commands in a BASH environment, so I suggest doing the same...

 
Step2. Open params.sh and edit the <> with your own values. I ran into a few mistakes because I was putting in the wrong IP address.

 
Step3. Run the following command in your terminal:
ONLY RUN THIS ONCE!

bash params.sh #you may need to run this command with elevated privileges

 
Step4. Run the app:

1. Start a simple HTTP server:
    `python -m SimpleHTTPServer`

2. Run the casting service: 
    `python3 casdrop.py`

3. Drop a file in your watch `CASDROP_WATCH_FOLDER` folder. Which in this case should be the folder we are looking to drop our files.
Enter fullscreen mode Exit fullscreen mode

 

**At this point, your uploaded files should start streaming on the device(s).**
Enter fullscreen mode Exit fullscreen mode

 
 
 
A side note: I know this is very short and cut to the point. However, I did this on purpose...Most of what you need is already on the internet. With that said, feel free to ask question if you lost, in the comment section below.
 
 
 

Reference:

  • CASDROP_WATCH_FOLDER => A folder you drop files in, to cast to device(s)

  • CASDROP_SERVER_URL => The IP address you get from SimpleHTTPServer a.k.a (http://<ip_address>)

  • CASDROP_SPKR_NAME and CASDROP_TV_NAME=> Displayed name of devices with (Ussually shown in cast menu on YouTube or Spotify mobile app)

Here's my sample param.sh file

Image description

 

Features / Suggestions / TODO:

Currently you can drop a .mp3 or .mp4 which will cast with zero problem. However, I plan on adding more features down
the road...

Let me know in the comments if you'd like me to make a video explaining this is more detail

Discussion (0)