Code Monkey home page Code Monkey logo

youtubeid's Introduction

youtubeid

php script that retrieves VideoId from youtube for latest video from a specific channel

###Requirements

##Installation

  1. Download the .zip file and place the .php file in /home/pi/

Or use: git clone https://github.com/Mister-Espria/youtubeid.git

When using git transfer get_youtube_videoid.php to /home/pi/

  1. Edit get_youtube_videoid.php by adding the channel id to line 3 and add your Youtube Data API key to line 4

Optional step: You can edit the code to give as output only the video id or the whole Youtube link. Standard it will add a harcoded path which i use to send Youtube videos directly to Kodi mediaplayer.

Now you are all set to use it!

##Usage

Simply run the code by: php -f get_youtube_videoid.php

This will return my hardcoded path + the latest video ID from the given channel in the terminal.

If you want to store it change the command like this: php -f get_youtube_videoid.php >./youtubeid/youtuber1.txt This will save the result in youtuber1.txt in /home/pi/youtubeid/ But you need to make sure there is a folder in/home/piwhich is called youtubeid in this case.

Multiple Youtube channels

I think it should be easy to add multiple channels to the .php file but i don't know how to implement it. But you can just copy it and change the name of the file and the channel id. and use another file as output.

Add crontab

I did setup crontab to execute the command. If a youtuber has a fixed upload time you can let the command execute arround that time. You can also just let it run every hour or anything you want. It wil just overwrite the existing file. [more info on crontab] (https://www.raspberrypi.org/documentation/linux/usage/cron.md)

crontab example:

3,10,31 16-17 * * * php -f get_youtube_videoid.php >./youtubeid/youtuber1.txt
3,10,31,50 21-22 * * * php -f get_youtube_youtuber2.php >./youtubeid/youtuber2.txt
10,50 16-23 * * * php -f get_youtube_youtuber3.php >./youtubeid/youtuber3.txt

Additional info: Send latest video from channel to Kodi using Home-Assitant

First you need to make sure you have the youtube addon installed in Kodi.

Also make sure that you have the webserver in Kodi enabled. Go to -->Settings → Services → Webserver → Allow control of Kodi via HTTP

I have also set an username and password.

For this we need to install kodi-cli by git clone https://github.com/nawar/kodi-cli Thanks to nawar for this awesome code!

Navigate to /home/pi/kodi-cli/kodi-cli and edit lines 18 to 21 to match your setup (KODI_HOST etc.).

Now you can send a youtube video with this command: /home/pi/kodi-cli/kodi-cli -y FILLHEREVIDEOID

Home Assitant

I added to my configuration.yaml the next shell command:

shell_command:
  play_youtuber1: 'sh /home/pi/youtubeid/youtuber1.txt'
  play_youtuber2: 'sh /home/pi/youtubeid/youtuber2.txt'
  play_youtuber3: 'sh /home/pi/youtubeid/youtuber3.txt

Then i created for every channel a script:

watch_youtuber1:
  sequence:
   - service: shell_command.play_youtuber1

Now you can activate the script and the Youtube video will play on your Kodi media player. Enjoy!!!

I did found the base of the .php file [here] (http://stackoverflow.com/questions/6617567/how-to-get-the-id-of-the-latest-uploaded-video-in-a-youtube-channel)

###Problems In case some command does not fire. Check Permissions on the folders and files. All the folders i used i gave all permissions but i don't know if it is mandatory.

youtubeid's People

Contributors

mister-espria avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.