grastello / ytel

Youtube "front-end" for Emacs
GNU General Public License v3.0
48 stars 10 forks source link

Cannot find any results #17

Open OrionRandD opened 3 years ago

OrionRandD commented 3 years ago

M-x ytel search: Emacs ytel search gives me: json-read: End of file while parsing JSON :(

grastello commented 3 years ago

Probably because the default Invidious instance has been shutted down. Actually I think it was shutted down in September and I haven't done anything about it.

It should be fixable by pointing ytel-invidious-api-url to a working invidious instance. If this does not work I cannot think of a reason for the error off the top of my head.

OrionRandD commented 3 years ago

@gRastello Have you tested yourself with another instance? I did with yewtu.be and it gave me the same error Or this is an abandoned project...

Some instances here: // invidio instances // https://instances.invidio.us/ //invidious.snopyta.org //yewtu.be //invidious.tube //invidious.xyz //etc...

pablobc-mx commented 3 years ago

The snopyta instance works for me. Maybe you could try it out.

OrionRandD commented 3 years ago

@pablobc-mx How did you set that up? In init.el? invidious.snopyta.org

mooseyboots commented 3 years ago

@OrionRandD you can simply put (setq ytel-invidious-api-url "https://your.url") in yr init to override the initial setting in the package.

@gRastello

i wrote some code to prompt the user to choose an invidious instance (from a list of the 12 healthiest ones as returned by the api) prior to searching.

not sure if it is any good/the right way to go about things, but just to show:

(defvar invidious-instances-url
      "https://api.invidious.io/instances.json?pretty=1&sort_by=health")

(defun ytel-instances-fetch-json ()
  "Fetch list of invidious instances as json, sorted by health."
  (let
      ((url-request-method "GET")
       (url-request-extra-headers
        '(("Accept" . "application/json"))))
    (with-current-buffer
        (url-retrieve-synchronously invidious-instances-url)
      (goto-char (point-min))
      (re-search-forward "^$")
      (let* ((json-object-type 'alist)
             (json-array-type 'list)
             (json-key-type 'string))
        (json-read)))))

(defun ytel-instances-alist-from-json ()
  "Make the json of invidious instances into an alist."
  (let ((jsonlist (ytel-instances-fetch-json))
        (inst ()))
    (while jsonlist
      (push (concat "https://" (caar jsonlist)) inst)
      (setq jsonlist (cdr jsonlist)))
    (nreverse inst)))

(defun ytel-choose-instance ()
  "Prompt user to choose an invidious instance to use."
  (interactive)
  (setq ytel-invidious-api-url
        (or (condition-case nil
                (completing-read "Using instance: "
                                 (subseq (ytel-instances-alist-from-json) 0 11) nil "confirm" "https://") ; "healthiest" 12 instances; no require match
              (error nil))
            "https://invidious.synopyta.org"))) ; fallback
OrionRandD commented 3 years ago

@gRastello thx a lot for the function. I can choose between them, but I get this error.: json-read: JSON readtable error: 60

OrionRandD commented 3 years ago

Here is the whole stuff... Since the beginning I have had problems related to json file :(

;; ytel - youtube-watch ;; https://github.com/gRastello/ytel

(use-package! ytel)

(defvar invidious-instances-url "https://api.invidious.io/instances.json?pretty=1&sort_by=health")

(defun ytel-instances-fetch-json () "Fetch list of invidious instances as json, sorted by health." (let ((url-request-method "GET") (url-request-extra-headers '(("Accept" . "application/json")))) (with-current-buffer (url-retrieve-synchronously invidious-instances-url) (goto-char (point-min)) (re-search-forward "^$") (let* ((json-object-type 'alist) (json-array-type 'list) (json-key-type 'string)) (json-read)))))

(defun ytel-instances-alist-from-json () "Make the json of invidious instances into an alist." (let ((jsonlist (ytel-instances-fetch-json)) (inst ())) (while jsonlist (push (concat "https://" (caar jsonlist)) inst) (setq jsonlist (cdr jsonlist))) (nreverse inst)))

(defun ytel-choose-instance () "Prompt user to choose an invidious instance to use." (interactive) (setq ytel-invidious-api-url (or (condition-case nil (completing-read "Using instance: " (subseq (ytel-instances-alist-from-json) 0 11) nil "confirm" "https://") ; "healthiest" 12 instances; no require match (error nil)) "https://invidious.synopyta.org"))) ; fallback

;; (defun ytel-watch () ;; "Stream video at point in mpv." ;; (interactive) ;; (let* ((video (ytel-get-current-video)) ;; (id (ytel-video-id video))) ;; (start-process "ytel mpv" nil ;; "mpv" ;; (concat "https://www.youtube.com/watch?v=" id)) ;; "--ytdl-format=bestvideo[height<=?720]+bestaudio/best") ;; (message "Starting streaming..."))

;; (define-key ytel-mode-map "y" #'ytel-watch)

;; youtube-comments

;; https://github.com/xFA25E/ytel-show ;; (use-package! ytel-show ;; :after ytel ;; :bind (:map ytel-mode-map ("RET" . ytel-show)))

OrionRandD commented 3 years ago

@gRastello @pablobc-mx @mooseyboots Thx. I solved the issue. :)

WorldsEndless commented 2 years ago

@OrionRandD share how?

OrionRandD commented 2 years ago

@OrionRandD share how?

This works for me, now...

;; ytel - youtube-watch ;; https://github.com/gRastello/ytel ;; https://api.invidious.io/ - instances

(use-package ytel :ensure t)

(defvar invidious-instances-url "https://api.invidious.io/instances.json?pretty=1&sort_by=health")

(defun ytel-instances-fetch-json () "Fetch list of invidious instances as json, sorted by health." (let ((url-request-method "GET") (url-request-extra-headers '(("Accept" . "application/json")))) (with-current-buffer (url-retrieve-synchronously invidious-instances-url) (goto-char (point-min)) (re-search-forward "^$") (let* ((json-object-type 'alist) (json-array-type 'list) (json-key-type 'string)) (json-read)))))

(defun ytel-instances-alist-from-json () "Make the json of invidious instances into an alist." (let ((jsonlist (ytel-instances-fetch-json)) (inst ())) (while jsonlist (push (concat "https://" (caar jsonlist)) inst) (setq jsonlist (cdr jsonlist))) (nreverse inst)))

(defun ytel-choose-instance () "Prompt user to choose an invidious instance to use." (interactive) (setq ytel-invidious-api-url (or (condition-case nil (completing-read "Using instance: " (subseq (ytel-instances-alist-from-json) 0 11) nil "confirm" "https://") ; "healthiest" 12 instances; no require match (error nil)) "https://invidious.tube"))) ; fallback

;; default fallback "https://invidious.synopyta.org"

(defun ytel-watch () "Stream video at point in mpv." (interactive) (let* ((video (ytel-get-current-video)) (id (ytel-video-id video))) (start-process "ytel mpv" nil "mpv" (concat "https://www.youtube.com/watch?v=" id)) "--ytdl-format=bestvideo[height<=?720]+bestaudio/best") (message "Starting streaming..."))

;; (define-key ytel-mode-map "y" #'ytel-watch)

;; youtube-comments

;; https://github.com/xFA25E/ytel-show ;; (use-package ytel-show ;; :after ytel ;; :bind (:map ytel-mode-map ("RET" . ytel-show)) ;; )

OrionRandD commented 2 years ago

https://invidious.osi.kr -> works :) https://yewtu.be -> NOT working here :(