Giter VIP home page Giter VIP logo

youtube-unofficial's Introduction

Unofficial YouTube API client

Use this library to do things the real YouTube API does not let you do. DO NOT USE THIS FOR ANY ACCOUNT OTHER THAN YOUR OWN!

This library supports Python 3.6+.

Use a netrc file

Please note for the time being, logging in is not working. For more details, see this youtube-dl issue.

Every command can take a --username and --password argument.

You should consider using a netrc file for your login. Example at ~/.netrc:

machine youtube login LOGIN password YOUR_PASSWORD

You can specify a custom netrc file with the --netrc argument.

Usage

Command line

  • youtube-clear-history - Clear your Watch History
  • youtube-clear-search-history - Clear your Search History
  • youtube-clear-watch-later - Clear your Watch Later queue
  • youtube-print-history-ids - Print Watch History video IDs
  • youtube-print-playlist-ids - Print video IDs from a specific playlist
  • youtube-print-watch-later-ids - Print Watch Later video IDs
  • youtube-remove-history-entries - Remove videos from your Watch History
  • youtube-remove-videoid - Remove a video from a playlist
  • youtube-remove-watch-later-videoid - Remove a video from your Watch Later queue
  • youtube-toggle-search-history - Turn on/off Search History
  • youtube-toggle-watch-history - Turn on/off Watch History

Every command takes a --debug argument.

You can use exported cookies in Netscape format with the --cookies COOKIES_FILE argument. By default, cookies are read from ~/.local/share/cookies/youtube.txt.

Some commands accept a -j/--json argument to print machine-readable output.

Download commands

  • ytdl-history - Use youtube-dl to download your history
  • ytdl-liked - Use youtube-dl to download your liked videos
  • ytdl-playlist - Use youtube-dl to download a playlist
  • ytdl-watch-later - Use youtube-dl to download your Watch Later playlist

For downloads to work, youtube-dl must be in PATH. To pass arguments to youtube-dl, specify -- before those arguments. Example with arguments to youtube-dl:

ytdl-history --output-dir ~/Downloads --delete-after -- --extract-audio --audio-format m4a --audio-quality 0

Each download command has a -D/--delete-after option, which makes the script delete the entry from the set of videos after a successful download.

In Python

from os.path import expanduser
from youtube_unofficial import YouTube

yt = YouTube(cookies_path=expanduser('~/my-cookies-file.txt'), logged_in=True)

# Clear watch history
yt.clear_watch_history()

# Remove a single video ID from Watch Later queue
yt.remove_video_id_from_playlist('WL', video_id)

# Clear entire Watch Later queue
yt.clear_watch_later()

Contributing

For a new feature to be accepted, it must be something that cannot be achieved with Google's official API.

Code must run through mypy and pylint based on the project settings.

youtube-unofficial's People

Contributors

dnicolson avatar kasnder avatar tatsh avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

youtube-unofficial's Issues

Login broken by Google ?

the login function fails on "galx = re.search(r'(?s)<input.+?name="GALX".+?value="(.+?)"', login_page).group(1)" :

Traceback (most recent call last):
  File "./<edited path>.py", line 210, in <module>
    yt.login()
  File "/<edited path>/youtube_unofficial/__init__.py", line 160, in login
    login_page).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

If I manually look at the source code for the login page, I can't find any "GALX" attribute anywhere.

Not Found for url: https://www.youtube.com/service_ajax?name=feedbackEndpoint

When trying to delete videos from the watch history (remove_video_ids_from_history), I get the following the following error:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    print(yt.remove_video_ids_from_history([entries[0]['videoRenderer']['videoId']]))
  File "/home/konrad/.local/lib/python3.8/site-packages/youtube_unofficial/__init__.py", line 409, in remove_video_ids_from_history
    self._download_page(
  File "/home/konrad/.local/lib/python3.8/site-packages/youtube_unofficial/download.py", line 43, in _download_page
    return download_page(self._sess, url, data, method, headers, params,
  File "/home/konrad/.local/lib/python3.8/site-packages/youtube_unofficial/download.py", line 25, in download_page
    r.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.youtube.com/service_ajax?name=feedbackEndpoint

login issuee

hi sir

when i try login everytime telling incorrect password

Login state is no longer checked properly

It seems that Youtube has changed the default home page, following condition is always true (line ~146 in init.py :
if 'signin-container' not in content:
I fixed it by replacing it with :
if '<yt-formatted-string id="text" class="style-scope ytd-button-renderer style-brand">Sign in</yt-formatted-string>' not in content:, this might not be the best string to test, but I needed a quickfix.

KeyError: 'DELEGATED_SESSION_ID'

Hello,

I'm trying to use your wonderful API, using an extracted cookies file from my Mozilla Firefox.

Unfortunately, I get the following error, when calling toggle_watch_history:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    yt.toggle_watch_history()
  File "/home/konrad/.local/lib/python3.8/site-packages/youtube_unofficial/__init__.py", line 487, in toggle_watch_history
    return self._toggle_history(WATCH_HISTORY_URL, 3)
  File "/home/konrad/.local/lib/python3.8/site-packages/youtube_unofficial/__init__.py", line 476, in _toggle_history
    return self._single_feedback_api_call(
  File "/home/konrad/.local/lib/python3.8/site-packages/youtube_unofficial/__init__.py", line 459, in _single_feedback_api_call
    user=dict(onBehalfOfUser=ytcfg['DELEGATED_SESSION_ID'])),
KeyError: 'DELEGATED_SESSION_ID'

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.