Code Monkey home page Code Monkey logo

youtube_stream_capture's Introduction

youtube_stream_capture

Record YouTube livestreams from start to finish, that includes the ability to rewind up to 12 hours regardless of whether the actual YouTube player allows it or not. Unlike other recording solutions such as streamlink, youtube_stream_capture does not need to be restarted after six hours and therefore can record livestreams without any gaps.

Deprecation notice

This repository is no longer being maintained by me. I've marked it as read-only and disabled the issues tab. While it was the first tool capable of retroactively archiving YouTube livestreams, the code could always best be described as a whole bunch of band-aid fixes stacked on top of one another. Since then better tools have made their way onto the internet capable of doing the exact same thing, one of them being ytarchive, which has many of the features that I wanted to implement myself but never got around to, including threads.

This code might break at some point in the future, please don't bother reaching out to me about it.

Installation

Requires python3, aria2c, ffmpeg as well as ffprobe (usually bundled with ffmpeg) to be installed and on your systems' PATH. Example using Ubuntu:

# Install FFmpeg
$ sudo apt-get install ffmpeg
$ sudo apt-get install aria2
# Install required python modules
$ python3 -m pip install -r requirements.txt

If you're more of a visual learner, here is a video showing you how to install and use the script.

Usage

Starting the livestream capture:

$ python3 youtube_stream_capture.py [Link to the livestream] [optional: --output-directory (PATH TO DIRECTORY)] [optional: --start-segment (INT)] [optional: --cookie-file (PATH TO COOKIE.TXT)]

Merging all the segments after the stream has ended:

$ python3 merge.py [Link to the livestream] [optional: --output-directory (PATH TO DIRECTORY)]

Example for Windows:

$ python .\youtube_stream_capture.py python https://www.youtube.com/watch?v=wSYFfVrCipA --output-directory C:\Users\mrwnwttk\Desktop\ --start-segment 10
$ python .\merge.py https://www.youtube.com/watch?v=wSYFfVrCipA --output-directory C:\Users\mrwnwttk\Desktop\

Example for Linux:

$ python3 youtube_stream_caputure.py https://www.youtube.com/watch?v=OIW4RnlYvgs --output-directory /mnt/c/Users/mrwnwttk/Desktop/
$ python3 merge.py https://www.youtube.com/watch?v=OIW4RnlYvgs --output-directory /mnt/c/Users/mrwnwttk/Desktop/

Note: if you used the --output-directory parameter to start the livestream recording, then you also need to use it as a parameter for merge.py.

The cookie inside of youtube_stream_capture.py has intentionally been left empty. If you run into any 429 errors (Too many requests), try to use your own. Simply export it using a browser extension such as cookies.txt and pass it as an argument into the script.

Example for Linux:

$ python3 youtube_stream_capture.py https://www.youtube.com/watch?v=ADyrjlsfcs --cookie-file /mnt/c/Users/mrwnwttk/Desktop/cookie.txt

[INFO] Found cookie at /mnt/c/Users/X1C4/Downloads/e11d26ef-2825-4311-8ab1-89af050d6b37.txt
[INFO] Cookie: {'VISITOR_INFO1_LIVE': 'XXXXXXXXXXX', 'LOGIN_INFO': 'XXXXXXXXXXXXXXXXXXXXXXXXXX', 'HSID': 'XXXXXXXXXXXXXXXXX', 'SSID': 'XXXXXXXXXXXXX', 'APISID': 'XXXXXXXXXXXX/XXXXXXXXXXXXXXXXX', 'SAPISID': 'XXXXXXXXXXXXXX/XXXXXXXXXXXXXX', '__Secure-3PAPISID': 'XXXXXXX/XXXXXXXXX', 'CONSENT': 'XXXX', '__Secure-3PSID': 'XXXXXXXXX', 'SID': 'XXXXXXXXXXXXXXXXXXXX', 'PREF': 'XXXXXXXX', 'YSC': 'XXXXXXXXXXX', 'SIDCC': 'XXXXXXXXXXXXXXXXXXXXXX', '__Secure-3PSIDCC': 'XXXXXXXXXXXXXXXXXXXX'}

Support

Livestreams that have been running for multiple days (such as the 24/7 music livestreams) are not supported. youtube_stream_capture attempts to go back to the very first segment of a livestream by design. The first segments of those livestreams have long been deleted at this point, so the script just fails. The time limit here is usually about 12 hours.

Support for VP9 livestreams has been added, but is highly experimental at this point and therefore commented out. Use at your own risk and don't bother opening up any issues if something breaks or the video goes out of sync. I don't want to deal with it.

License

The source code is licensed under GPL v3. For more information, consult the LICENSE file.

youtube_stream_capture's People

Contributors

cl-jeremy 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.