mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting mps-youtube up and running -- if you're experiencing issues check here first

windowswithoutborders opened this issue · comments

I've been using mps-youtube for a couple weeks now and absolutely love it. Unfortunately, it's not as simple as installing it to get it up and running. But through the work of some skilled and helpful people on here, I'd like to share the additional steps that have been discovered that should get mps-youtube working again. I hope this can benefit those just coming across this project and understanding the appeal of a program like this. Note, these steps resulted in a perfectly usable mps-youtube on arch and macos. And of course, all of this assumes you have a player installed. I use mpv and will mention certain issues specific to mpv.

Anyways, let's start with installation:

Installing

$ pip3 install --user mps-youtube ### Stable branch

or

$ pip3 install --user -U git+https://github.com/mps-youtube/mps-youtube.git ### Development branch

I say get the development branch. I'm sure there are some other differences, but I noticed the development branch added tab complete to the set parameters you'll choose within mpsyt, which is actually pretty nice. I haven't noticed any bugs in the branch either so it seems perfectly usable.

Be sure to get the dependencies as well. Although I already had youtube-dl installed through my package manager, mps-youtube wouldn't work until I got it from pip. If you do have youtube-dl on your system through a package manager, potential conflicts between the two packages won't be an issue as the --user install flag ensures that it is only installed locally to your user. That is to say, should you invoke youtube-dl on your command line, your path variable should choose the youtube-dl bin from the package manager over the one installed from pip.

$ pip3 install --user youtube-dl
$ pip3 install --user pyperclip ### optional, but adds link copy functionality though so you should get it

You can upgrade these packages with
$ pip3 install --user <package-name> --upgrade

OPTIONAL: Installing with pipx

It doesn't really matter, but I prefer to use pipx for installing packages from pip just to isolate them that much further from packages installed from my package manager. Pipx will install packages into their own isolated virtual environments. I especially like doing this on macOS because pipx will install packages into ~/.local, which is where I would expect pip install --user to place them, but on mac they go into ~/Library/Python instead.

$ pip3 install --user pipx
$ pipx ensurepath ### ensures install path for pipx is present in your path variable. should show ~/.local/bin
$ pipx install git+https://github.com/mps-youtube/mps-youtube.git
$ pipx inject mps-youtube youtube-dl ### inject adds dependencies to the package environment, in this case, youtube-dl is injected into the package environment pipx created for mps-youtube
$ pipx inject mps-youtube pyperclip

You can upgrade with
$ pipx upgrade-all --include-injected ### upgrade everything installed through pipx

Create a youtube api key

Despite the installation being complete, don't bother with a first run of mpsyt, you're going to want to create a youtube api key to use with mpsyt first. This is discussed at length in this thread #1063. It's reiterated multiple ways in the thread, but this specific comment #1063 (comment) quickly goes over the steps required for creating an api key:

  • Go to https://console.cloud.google.com, create a project, then enable Youtube Data Api V3 and create credential and get the API_KEY for public use.
  • Then remove the cache rm ~/.config/mps-youtube/cache_py*
  • Set the new api key mpsyt set api_key YOUR_KEY_HERE
  • Quit mpsyt (if there are any opened mpsyt instances"
    Open it again and use it normally (it worked for me after following these steps)

I wouldn't bother with a first launch yet to set your api key, because if you're using mpv, you're probably going to experience playback issues anyways.

Fixing MPV issues

So this issue has been discussed here #1134 (comment) and here #1128 (comment). Apparently the solution detailed in #1134 works, but I needed to follow the steps in #1128 to get it to work for me. The steps are self-explanatory, so try either method. The one thing to note is the location of these files. Use the following commands to find where mps-youtube is located on your system:

$ pip3 show mps-youtube | grep -i location
$ pipx list ### you'll want to go into the venvs folder for mps-youtube

You'll ultimately end up in the ../site-packages/mps_youtube directory

Let's go over the steps in #1128 for fixing mpv playback. You'll have to add a line of code to two files.

The code:
if 'data' in resp:

The files:
../site-packages/mps_youtube/mpris.py
and
../site-packages/mps_youtube/player.py (STABLE BRANCH)
OR
../site-packages/mps_youtube/players/mpv.py (DEV BRANCH)

the code to edit comes after the comment in both files: "# deals with bug in mpv 0.7 - 0.7.3". Search this line in your editor and you should be able to easily spot where you need to add the code from there. The code must look like this:

mpris.py

++              if 'data' in resp:
                    if resp.get('event') == 'property-change':
                        self.setproperty(resp['name'], resp['data'])

player.py OR player/mpv.py

++              if 'data' in resp:
                    if resp.get('event') == 'property-change' and resp['id'] == 1:
                        if resp['data'] is not None:
                            elapsed_s = int(resp['data'])

With all of that out of the way, we can go onto configuring mps-youtube.

First launch and configuration

Run mpsyt and type in set. You'll see a list of parameters you can specify. The most important being api_key. Get the youtube api key you created and pass it into mpsyt. Additionally, you can set these extra parameters as well:

set api_key paste_your_created_key
set order relevance ### I believe this is set by default. How youtube.com displays search results.
set user_order date ### perfect when visiting a specific youtube channel and you want to see the latest upload
set columns user:19 date ### show usernames column and give 19 characters before truncating username, and show video upload date column
set search_music false ### search_music limits search results to music category only. set to false to show all youtube results.

With all that being done, type q to quit, navigate to ~/.config/mps-youtube and delete the cache file inside. Relaunch mpsyt and play your first video. I hope it worked!

Closing

Thank you to the author of this program, all contributors, and everyone who left a comment addressing the issues that have popped up. Stuff like that is why I love the open-source community. This is a great project and with some tweaking here and there it's still perfectly usable. I hope this will benefit you and your workflow the way it has for me. Be sure to look into the set parameters and dialing them into what works best for you, for instance I have some arguments set for playerargs. Also, look into the help section, especially help basic help search help invoke help config and help tips. Enjoy mps-youtube :).

TLDR

  • install mps-youtube and its dependencies through pip (or set it up through pipx if you're so inclined)
  • create a youtube api key as the one set by default in mpsyt is inoperable. check #1063 for more information
  • if using mpv, edit the mpris.py file and the player.py (if on stable) or players/mpv.py (if on dev) file to address mpv playback issues. check #1134 and #1128 for more information. note -- #1128 is what worked for me, but #1134 might work for you. (I think this is mpv specific, but try anyways if you are getting KeyError: data when trying to play video??)
  • launch mpsyt, set your new api key and any additional parameters, quit, delete the cache file in ~/.config/mps-youtube, relaunch mpsyt and enjoy

Troubleshooting

  • if you are having issues with setup and you're on the stable branch, switch to development
  • if you are having issues with setup and you're on the development branch, switch to stable
  • delete the cache file in the .config/mps-youtube folder

@windowswithoutborders excellent work outlining the steps required, it will help future users to properly get mpsyt up and running.I do wonder why the devs have a lack of interest in updating this project with the necessary fixes.

commented

even after all of this i still end up with
Command-line option --title: option requires parameters
lol

@archtheseus

Ah, sorry to hear that. Not that I have any solution, but for troubleshooting purposes could you post the output of mpv --version and pip3 show youtube-dl /pipx list --include-injected?

For me on macOS with pipx:

> mpv --version
mpv 0.33.0 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on Mon Nov 23 23:02:08 CET 2020
FFmpeg library versions:
   libavutil       56.51.100
   libavcodec      58.91.100
   libavformat     58.45.100
   libswscale      5.7.100
   libavfilter     7.85.100
   libswresample   3.7.100
FFmpeg version: 4.3.1
> pipx list --include-injected
venvs are in /Users/aoede/.local/pipx/venvs
apps are exposed on your $PATH at /Users/aoede/.local/bin
   package mps-youtube 0.2.8, Python 3.9.1
    - mpsyt
    Injected Packages:
      - pyperclip 1.8.1
      - youtube-dl 2021.2.4.1

even after all of this i still end up with
Command-line option --title: option requires parameters
lol

I had the same issue when installing the stable branch. When I switched to the development branch, this issue was fixed for me (I just installed the development branch, didn't explicitly remove the stable branch).

Is it possible to use it without an API? I have no problem playing audio or video with Mpv and I have not set any API whatsoever with it.

even after all of this i still end up with
Command-line option --title: option requires parameters
lol

I had the same issue when installing the stable branch. When I switched to the development branch, this issue was fixed for me (I just installed the development branch, didn't explicitly remove the stable branch).

Can confirm that switching to dev fixed this one. Thanks!

commented

I followed and i get this error

Traceback (most recent call last):
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/pafy/util.py", line 34, in call_gdata
    data = g.opener.open(url).read().decode('utf-8')
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mpsyt", line 33, in <module>
    sys.exit(load_entry_point('mps-youtube==0.2.8', 'console_scripts', 'mpsyt')())
  File "/usr/local/bin/mpsyt", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/init.py", line 58, in init
    cache.load()
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/cache.py", line 34, in load
    pafy.load_cache(cached['pafy'])
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/pafy/pafy.py", line 184, in load_cache
    set_categories(newcache.get('categories', {}))
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/pafy/pafy.py", line 171, in set_categories
    catinfo = call_gdata('videoCategories', query)
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/pafy/util.py", line 42, in call_gdata
    raise GdataError(errmsg)
pafy.util.GdataError: Youtube Error 403: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.