Coder Social home page Coder Social logo

lucas-c / youtube_playlist_watcher Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 0.0 89 KB

Backup Youtube playlists and alert you on songs deletions

Shell 12.59% Python 87.41%
youtube-playlist youtube-api youtube python python-script playlist-changes-watched alert

youtube_playlist_watcher's Introduction

build status Known Vulnerabilities

Do you get frustrated by videos disappearing from your Youtube playlist, because of copyright infringement, new region restrictions or just because the guy who uploaded them removed it ? With no way for you to find out which where those clips: because Youtube does not keep trace of those dead videos, your only chance to recall what were their names is a Google search based on their video ids.

But no more !

This Python script will keep JSON backups of your playlists on your computer, detect changes like disappearing videos, and alert you with console messages or emails like this:

SUBJECT: [YPW] Change detected in Youtube playlist FLF8xTv55ZmwikWWmWLPEAZQ
Playlist: https://www.youtube.com/playlist?list=FLF8xTv55ZmwikWWmWLPEAZQ
REGION RESTRICTIONS CHANGED for Sade - The Best Of Sade | Full Album : {"blocked": ["DE"]}-> {} https://www.youtube.com/watch?v=zX8nZI8U9XY
-> find another video named like that: https://www.youtube.com/results?search_query=Sade+-+The+Best+Of+Sade+%7C+Full+Album
BECAME PRIVATE: https://www.youtube.com/watch?v=T4ZCJzjufYs
-> find another video named like that: https://www.youtube.com/results?search_query=Patrick+Bruel+%22J%27te+l%27dis+quand+m%C3%AAme%22
DELETED: The Cure - Burn 1994 HQ (The Crow)
-> find another video named like that: https://www.youtube.com/results?search_query=The+Cure+-+Burn+1994+HQ+%28The+Crow%29

Requirements

A computer with:

  • Python 3.7 at least
  • a Youtube Data API key (it's free)
  • and either:
    • the ability to run daily jobs (e.g. standard Linux cron jobs) + mail, mutt or any other command-line email client
    • a Bash-based console (Cygwin is ok) that you open frequently, so you'll see the reports inside

Installation in .bashrc to get reports in your temrinal

If installed this way, YPW will do the following:

  • each time you'll open a new terminal, it'll check if it has already been executed today, and else launch a background task to dump & check your playlist for changes.
  • the next time you'll open a console after this task completed, you'll see the report at the top of your terminal (it can be empty if no changes were detected).

To install it, run the following in a console (just remember to substitute the ... on the last line by real values) :

cd /path/to/your/installation/directory # the JSON dumps will be stored there by default
wget https://rawgit.com/Lucas-C/youtube_playlist_watcher/master/youtube_playlist_watcher.py
wget https://rawgit.com/Lucas-C/youtube_playlist_watcher/master/install_bashrc_banner.sh
wget https://rawgit.com/Lucas-C/youtube_playlist_watcher/master/requirements.txt
chmod u+x *.sh *.py
pip install -r requirements.txt
./install_bashrc_banner.sh YOUTUBE_API_KEY=... PLAYLIST_ID=...

This last script will append some lines to your ~/.bashrc, that implement the logic detailed above. It will also define a ypw_check shell function that you can invoke manually if you want.

If you want to watch multiple playlists, keep more or less JSON dumps in history or change the kind of playlist changes watched, simply edit this section of your ~/.bashrc manually.

Installation as a cron job sending emails

Run the following in a console (just remember to substitute the ... on the last line by real values) :

cd /path/to/your/installation/directory # the JSON dumps will be stored there by default
wget https://rawgit.com/Lucas-C/youtube_playlist_watcher/master/youtube_playlist_watcher.py
wget https://rawgit.com/Lucas-C/youtube_playlist_watcher/master/install_crontask.sh
wget https://rawgit.com/Lucas-C/youtube_playlist_watcher/master/requirements.txt
chmod u+x *.sh *.py
pip install -r requirements.txt
./install_crontask.sh YOUTUBE_API_KEY=... PLAYLIST_ID=... EMAIL_DEST=...

This last script will generate a youtube_playlist_watcher_crontask.sh script that will be invoked by a cron job, running every day at midnight.

If you want to watch multiple playlists, use another email client command (the default is mail), keep more or less JSON dumps in history or change the kind of playlist changes watched, simply edit this file manually.

Python script manual usage

To compare a dump taken at any date with the latest one:

./youtube_playlist_watcher.py --playlist $playlist_id compare 2015-01-01 LATEST

Want to find more secret features ? The --help flag is your friend.

Or use the power Luke: READ THE SOURCE !

Removing "ghost" playlist items

If you repeatedly get reports like this:

IS PRIVATE: AURORA - All Is Soft Inside - LYRICS https://www.youtube.com/watch?v=tUiWQiUvWas (217th video in the playlist)
 -> find another video named like that: https://www.youtube.com/results?search_query=AURORA+-+All+Is+Soft+Inside+-+LYRICS
DELETED: Deleted video https://www.youtube.com/watch?v=Y9QHak8h1AQ (437th video in the playlist)
 -> find another video named like that: https://www.youtube.com/results?search_query=Nujabes+-+Lady+Brown

Use Youtube Data API web "shooter" to remove the corresponding playlist items: https://developers.google.com/youtube/v3/docs/playlistItems/delete

You can extract all playlistItemId of deleted videos from a youtube-playlist-$playlist_id-$timestamp.json file using the following jq command:

jq '.[] | select(.snippet.title=="Deleted video") | .id' $json_file

It cannot easily be done with a script, as this API endpoint also requires an OAuth2 access token.

Contributing

Bug reports or features suggestions are warmly welcome !

For the devs:

pip install -r dev-requirements.txt
pre-commit install

youtube_playlist_watcher's People

Contributors

henrik9999 avatar lucas-c avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

youtube_playlist_watcher's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-python v3
pip_requirements
dev-requirements.txt
requirements.txt

  • Check this box to trigger a request for Renovate to run again on this repository

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.