Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix youtube search #547

Open
LaurentLouf opened this issue Jul 19, 2020 · 1 comment
Open

Fix youtube search #547

LaurentLouf opened this issue Jul 19, 2020 · 1 comment

Comments

@LaurentLouf
Copy link

Hello !

I'm currently trying to make the Youtube search (and I guess play), so I thought it might be interesting to share my progress with others here, until I reach the point where I'll do a PR (if I have time).

First thing I've done is to change the Youtube API key that is in the mopidy-youtube package by one of my own. Just search Google API console, create a new project, then add an API and select the Youtube API data V3 API. The file you have to edit after that is located at `/usr/local/lib/python2.7/dist-packages/mopidy_youtube/backend.py :

# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import re
import string
import unicodedata
from multiprocessing.pool import ThreadPool
from urlparse import parse_qs, urlparse

from mopidy import backend
from mopidy.models import Album, SearchResult, Track

import pafy

import pykka

import requests

from mopidy_youtube import logger

yt_api_endpoint = 'https://www.googleapis.com/youtube/v3/'
yt_key = 'yourYTAPIkeyhere'
session = requests.Session()

video_uri_prefix = 'youtube:video'
search_uri = 'youtube:search'

The second step is to update pafy and youtube-dl. Below the process with some trials in between and confirmation that the package works after the updates :

root@MusicBox:~# ytdl B31Vgqytoa4
ERROR: B31Vgqytoa4: YouTube said: HTTP is not supported.
Traceback (most recent call last):
  File "/usr/local/bin/ytdl", line 199, in <module>
    main()
  File "/usr/local/bin/ytdl", line 141, in main
    vid = pafy.new(args.url)
  File "/usr/local/lib/python2.7/dist-packages/pafy/pafy.py", line 124, in new
    return Pafy(url, basic, gdata, size, callback, ydl_opts)
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_youtube_dl.py", line 29, in __init__
    super(YtdlPafy, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_shared.py", line 96, in __init__
    self._fetch_basic()
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_youtube_dl.py", line 41, in _fetch_basic
    raise IOError(str(e).replace('YouTube said', 'Youtube says'))
IOError: ERROR: B31Vgqytoa4: Youtube says: HTTP is not supported.
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# sudo pip install --upgrade pafy
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.
  utils.DeprecatedIn23,
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/bindings/openssl/binding.py:163: CryptographyDeprecationWarning: OpenSSL version 1.0.1 is no longer supported by the OpenSSL project, please upgrade. A future version of cryptography will drop support for it.
  utils.CryptographyDeprecationWarning
Collecting pafy
  Downloading https://files.pythonhosted.org/packages/74/69/829919eeadff695338f98fa12bb99e45490761a2010c8d688d88b6df194a/pafy-0.5.5-py2.py3-none-any.whl
Installing collected packages: pafy
  Found existing installation: pafy 0.5.4
    Uninstalling pafy-0.5.4:
      Successfully uninstalled pafy-0.5.4
Successfully installed pafy-0.5.5
You are using pip version 18.1, however version 20.2b1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# ytdl B31Vgqytoa4
ERROR: B31Vgqytoa4: YouTube said: Invalid parameters.
Traceback (most recent call last):
  File "/usr/local/bin/ytdl", line 209, in <module>
    main()
  File "/usr/local/bin/ytdl", line 151, in main
    vid = pafy.new(args.url)
  File "/usr/local/lib/python2.7/dist-packages/pafy/pafy.py", line 124, in new
    return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_youtube_dl.py", line 31, in __init__
    super(YtdlPafy, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_shared.py", line 97, in __init__
    self._fetch_basic()
  File "/usr/local/lib/python2.7/dist-packages/pafy/backend_youtube_dl.py", line 43, in _fetch_basic
    raise IOError(str(e).replace('YouTube said', 'Youtube says'))
IOError: ERROR: B31Vgqytoa4: Youtube says: Invalid parameters.
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# sudo pip install --upgrade youtube-dl==2020.06.16.1
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.
  utils.DeprecatedIn23,
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/bindings/openssl/binding.py:163: CryptographyDeprecationWarning: OpenSSL version 1.0.1 is no longer supported by the OpenSSL project, please upgrade. A future version of cryptography will drop support for it.
  utils.CryptographyDeprecationWarning
Collecting youtube-dl==2020.06.16.1
  Downloading https://files.pythonhosted.org/packages/a4/5f/db1fb30596fbfabd3500e741cd9c73d0cb1d25387582fd21289bed05a9c2/youtube_dl-2020.6.16.1-py2.py3-none-any.whl (1.8MB)
    100% |################################| 1.8MB 907kB/s 
Installing collected packages: youtube-dl
  Found existing installation: youtube-dl 2019.1.2
    Uninstalling youtube-dl-2019.1.2:
      Successfully uninstalled youtube-dl-2019.1.2
Successfully installed youtube-dl-2020.6.16.1
You are using pip version 18.1, however version 20.2b1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# 
root@MusicBox:~# ytdl 4XUipCxjmmw
Stream Type    Format Quality         Size            
------ ----    ------ -------         ----            
1      normal  mp4    [540x360]      272 MB           
2      audio   webm   [160k]          56 MB           
3      audio   m4a    [128k]          55 MB           
4      audio   webm   [70k]           28 MB           
5      audio   webm   [50k]           21 MB           
root@MusicBox:~#

And well, it seems to work for the search, stay tuned for making sure that it actually works when trying to play a thune

Screenshot from 2020-07-19 22-04-32

@LeChatNoir666
Copy link

Great so far!
Got the search to work too...
Any ideas how to play the songs now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants