├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── api.png
├── contributing.json
├── demo1.png
├── demo2.png
├── demo3.png
├── demo4.png
└── ivy-youtube.el
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ivy-youtube@brunno.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Anand Iyer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)
2 |
3 | #Ivy-YouTube
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Ivy-YouTube is a simple plugin to query YouTube via emacs and play videos in your browser.
12 |
13 | **IMPORTANT:** Remember to set your 'ivy-youtube-key' variable!
14 |
15 | ## Based on Helm-Youtube
16 |
17 | This package was based on [Maximilian Roquemore](https://github.com/maximus12793)'s package called [helm-youtube](https://github.com/maximus12793/helm-youtube).
18 | Thanks Maximilian to create this awesome package.
19 |
20 |
21 | ## Installation
22 |
23 | The installation process is very simple:
24 |
25 | - M-x package-install: ivy-youtube
26 | - Obtain new google API key
27 | [here](https://console.developers.google.com/ "Google Developer Console")
28 |
29 | 
30 |
31 | - To create this API key you need to go to `Credentials` ->
32 | `Create Credentials` and select `API Key`
33 | - After create you need to **enable** it: go to `Library`, select
34 | `YouTube Data API` and click in `Enable` button on top.
35 |
36 | - **IMPORTANT:** Set 'ivy-youtube-key' variable
37 |
38 | ``` el
39 | M-x customize-variable ;; search 'ivy-youtube-key'
40 | Ivy Youtube Key: replace "NONE" with "API KEY" ;; FROM STEP 2
41 | ```
42 |
43 | ## Where do you want to play the video?
44 |
45 | By default Ivy Youtube play the selected video in your default browser, but you can configure that:
46 |
47 | ### Change the default browser:
48 |
49 | Set browse-url-generic and add to .emacs
50 |
51 | ``` elisp
52 | ;;start ivy-youtube.el
53 | (autoload 'ivy-youtube "ivy-youtube" nil t)
54 | (global-set-key (kbd "C-c y") 'ivy-youtube) ;; bind hotkey
55 |
56 | ;;set default browser for you will use to play videos/default generic
57 | (setq browse-url-browser-function 'browse-url-generic)
58 | (setq browse-url-generic-program "google-chrome-open-url")
59 | ```
60 |
61 | ### Using an external player (beta)
62 |
63 | You can set a external player to watch your videos, like `mpv` or
64 | `vlc`. To do that you need to set the custom varialble
65 | `ivy-youtube-play-at`: `M-x
66 | customize-variableivy-youtube-play-at`.
67 | You can set in this field any binary that receives the youtube url as
68 | parameter like: `/usr/bin/mpv` or `/usr/bin/vlc`.
69 |
--------------------------------------------------------------------------------
/api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/squiter/ivy-youtube/e7a7cc860e967500857e5fd85d8e397c6d752ee1/api.png
--------------------------------------------------------------------------------
/contributing.json:
--------------------------------------------------------------------------------
1 | // https://gitmagic.io/rules
2 | {
3 | "commit": {
4 | "subject_cannot_be_empty": true,
5 | "subject_must_be_longer_than": 4,
6 | "subject_must_be_shorter_than": 101,
7 | "subject_lines_must_be_shorter_than": 51,
8 | "subject_must_be_single_line": true,
9 | "subject_must_be_in_tense": "imperative",
10 | "subject_must_start_with_case": "upper",
11 | "subject_must_not_end_with_dot": true
12 | },
13 | "pull_request": {
14 | "subject_cannot_be_empty": true,
15 | "subject_must_be_longer_than": 4,
16 | "subject_must_be_shorter_than": 101,
17 | "subject_must_be_in_tense": "imperative",
18 | "subject_must_start_with_case": "upper",
19 | "subject_must_not_end_with_dot": true,
20 |
21 | "body_cannot_be_empty": true,
22 | "body_must_include_verification_steps": false
23 | },
24 | "issue": {
25 | "subject_cannot_be_empty": true,
26 | "subject_must_be_longer_than": 4,
27 | "subject_must_be_shorter_than": 101,
28 | "subject_must_be_in_tense": "imperative",
29 | "subject_must_start_with_case": "upper",
30 | "subject_must_not_end_with_dot": true,
31 |
32 | "body_cannot_be_empty": true
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/demo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/squiter/ivy-youtube/e7a7cc860e967500857e5fd85d8e397c6d752ee1/demo1.png
--------------------------------------------------------------------------------
/demo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/squiter/ivy-youtube/e7a7cc860e967500857e5fd85d8e397c6d752ee1/demo2.png
--------------------------------------------------------------------------------
/demo3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/squiter/ivy-youtube/e7a7cc860e967500857e5fd85d8e397c6d752ee1/demo3.png
--------------------------------------------------------------------------------
/demo4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/squiter/ivy-youtube/e7a7cc860e967500857e5fd85d8e397c6d752ee1/demo4.png
--------------------------------------------------------------------------------
/ivy-youtube.el:
--------------------------------------------------------------------------------
1 | ;;; ivy-youtube.el --- Query YouTube and play videos in your browser
2 |
3 | ;; Copyright (C) 2017 Brunno dos Santos
4 |
5 | ;; Author: Brunno dos Santos
6 | ;; Version: 0.3.1
7 | ;; Package-Requires: ((request "0.2.0") (ivy "0.8.0") (cl-lib "0.5"))
8 | ;; URL: https://github.com/squiter/ivy-youtube
9 | ;; Created: 2017-Jan-02
10 | ;; Keywords: youtube, multimedia, mpv, vlc
11 |
12 | ;;; Commentary:
13 |
14 | ;; This package provides an interactive prompt to search
15 | ;; youtube as you code :)
16 |
17 | ;; This package was based on Maximilian Roquemore's package called
18 | ;; helm-youtube. You can find the original code in:
19 | ;; https://github.com/maximus12793/helm-youtube
20 |
21 | ;; Thank you Maximilian to create this awesome package.
22 |
23 | ;;; MIT License
24 | ;;
25 | ;; Permission is hereby granted, free of charge, to any person obtaining
26 | ;; a copy of this software and associated documentation files (the
27 | ;; "Software"), to deal in the Software without restriction, including
28 | ;; without limitation the rights to use, copy, modify, merge, publish,
29 | ;; distribute, sublicense, and/or sell copies of the Software, and to
30 | ;; permit persons to whom the Software is furnished to do so, subject to
31 | ;; the following conditions:
32 | ;;
33 | ;; The above copyright notice and this permission notice shall be
34 | ;; included in all copies or substantial portions of the Software.
35 | ;;
36 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39 | ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
40 | ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
41 | ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
42 | ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 |
44 | ;;; Code:
45 |
46 | (require 'cl-lib)
47 | (require 'ivy)
48 | (require 'request)
49 | (require 'json)
50 |
51 | (defgroup ivy-youtube nil
52 | "Ivy-youtube settings."
53 | :group 'tools)
54 |
55 | (defcustom ivy-youtube-key nil
56 | "Your Google API key.";; INSERT YOUR KEY FROM GOOGLE ACCOUNT!!!
57 | :type '(string)
58 | :group 'ivy-youtube)
59 |
60 | (defcustom ivy-youtube-play-at "browser"
61 | "Where do you want to play the video. You can set browser, emms, or process."
62 | :type '(string)
63 | :group 'ivy-youtube-play-at)
64 |
65 | (defcustom ivy-youtube-history-file (format "%sivy-youtube-history" user-emacs-directory)
66 | "History file for your searches.
67 |
68 | If nil then don't keep a search history"
69 | :type '(string)
70 | :group 'ivy-youtube)
71 |
72 | (defcustom ivy-youtube-max-results 50
73 | "The max amount of results displayed after search
74 |
75 | Increasing this value too much might result in getting connection errors"
76 | :type '(integer)
77 | :group 'ivy-youtube)
78 |
79 | (defun ivy-youtube-read-lines (filePath)
80 | "Return a list of lines of a file at FILEPATH."
81 | (with-temp-buffer
82 | (insert-file-contents filePath)
83 | (split-string (buffer-string) "\n" t)))
84 |
85 | (defun ivy-youtube-history-list ()
86 | "Return a list with content of file or an empty list."
87 | (if (and ivy-youtube-history-file (file-readable-p ivy-youtube-history-file))
88 | (ivy-youtube-read-lines ivy-youtube-history-file)
89 | '()))
90 |
91 | ;;;###autoload
92 | (defun ivy-youtube ()
93 | (interactive)
94 | (unless ivy-youtube-key
95 | (error "You must set `ivy-youtube-key' to use this command"))
96 | (request
97 | "https://www.googleapis.com/youtube/v3/search"
98 | :params `(("part" . "snippet")
99 | ("q" . ,(ivy-youtube-search))
100 | ("type" . "video")
101 | ("maxResults" . ,(int-to-string ivy-youtube-max-results))
102 | ("key" . ,ivy-youtube-key));; <--- GOOGLE API KEY
103 | :parser 'json-read
104 | :success (cl-function
105 | (lambda (&key data &allow-other-keys)
106 | (ivy-youtube-wrapper data)));;function
107 | :status-code '((400 . (lambda (&rest _) (message "Got 400.")))
108 | ;; (200 . (lambda (&rest _) (message "Got 200.")))
109 | (418 . (lambda (&rest _) (message "Got 418.")))
110 | (403 . (lambda (&rest _)
111 | (message "403: Unauthorized. Maybe you need to enable your youtube api key"))))
112 | :complete (cl-function
113 | (lambda (&rest args)
114 | (message "Search finished")))))
115 |
116 | (defun ivy-youtube-tree-assoc (key tree)
117 | "Build the tree-assoc from KEY TREE for youtube query."
118 | (when (consp tree)
119 | (cl-destructuring-bind (x . y) tree
120 | (if (eql x key) tree
121 | (or (ivy-youtube-tree-assoc key x) (ivy-youtube-tree-assoc key y))))))
122 |
123 | (defun ivy-youtube-playvideo (video-url)
124 | "Play the video based on users choice."
125 | (cond ((equal ivy-youtube-play-at "browser")
126 | (ivy-youtube-play-on-browser video-url))
127 | ((equal ivy-youtube-play-at nil)
128 | (ivy-youtube-play-on-browser video-url))
129 | ((equal ivy-youtube-play-at "")
130 | (ivy-youtube-play-on-browser video-url))
131 | ((equal ivy-youtube-play-at "emms")
132 | (ivy-youtube-play-on-emms video-url))
133 | (t (ivy-youtube-play-on-process video-url))))
134 |
135 | (defun ivy-youtube-play-on-browser (video-url)
136 | "Open your browser with VIDEO-URL."
137 | (message "Opening your video on browser...")
138 | (browse-url video-url))
139 |
140 | (defun ivy-youtube-play-on-emms (video-url)
141 | "Play VIDEO-URL using emms."
142 | (message "Opening URL using emms...")
143 | (emms-play-url video-url))
144 |
145 | (defun ivy-youtube-play-on-process (video-url)
146 | "Start a process based on ivy-youtube-play-at variable passing VIDEO-URL."
147 | (message (format "Starting a process with: [%s %s]" ivy-youtube-play-at video-url))
148 | (make-process :name "Ivy Youtube"
149 | :buffer "*Ivy Youtube Output*"
150 | :sentinel (lambda (process event)
151 | (message
152 | (format "Ivy Youtube: Process %s (Check buffer *Ivy Youtube Output*)" event)))
153 | :command `(,ivy-youtube-play-at ,video-url)))
154 |
155 | (defun ivy-youtube-build-url (video-id)
156 | "Create a usable youtube URL with VIDEO-ID."
157 | (concat "http://www.youtube.com/watch?v=" video-id))
158 |
159 | (defun ivy-youtube-wrapper (*qqJson*)
160 | "Parse the json provided by *QQJSON* and provide search result targets."
161 | (let (results '())
162 | (let ((search-results (cdr (ivy-youtube-tree-assoc 'items *qqJson*))))
163 | (dotimes (i (length search-results))
164 | (push (cons (cdr (ivy-youtube-tree-assoc 'title (aref search-results i)))
165 | (cdr (ivy-youtube-tree-assoc 'videoId (aref search-results i))))
166 | results)))
167 | (ivy-read "Youtube Search Results"
168 | (reverse results)
169 | :action (lambda (cand)
170 | (ivy-youtube-playvideo (ivy-youtube-build-url (cdr cand)))))))
171 |
172 | (defun ivy-youtube-search ()
173 | "Use ivy-read to select your search history."
174 | (ivy-read "Search YouTube: "
175 | (ivy-youtube-history-list)
176 | :action (lambda (cand)
177 | (ivy-youtube-append-history cand))))
178 |
179 | (defun ivy-youtube-append-history (candidate)
180 | "Save the new CANDIDATE to the history file."
181 | (if ivy-youtube-history-file
182 | (let* ((history-words (ivy-youtube-history-list))
183 | (history-words-with-candidate (add-to-list 'history-words candidate))
184 | (unique-words (delq nil (delete-dups history-words-with-candidate))))
185 | (write-region (mapconcat 'identity unique-words "\n") nil ivy-youtube-history-file nil))))
186 |
187 | (provide 'ivy-youtube)
188 |
189 | ;; Local Variables:
190 | ;; End:
191 |
192 | ;;; ivy-youtube.el ends here
193 |
--------------------------------------------------------------------------------