grastello / ytel

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

support for "date" limit #10

Open spiderbit opened 4 years ago

spiderbit commented 4 years ago

I added in my branch support for date limitation, sorry did see that I did not have commited it and not in the mental state to do that now, so I post the relevant code here for now:

(defun ytel--query (string n)
...
`(("q" ,string)
("date" ,(symbol-name ytel-date-criterion))
("sort_by" ,(symbol-name ytel-sort-criterion))
("page" n)
("fields" ,ytel-invidious-default-query-fields))

(defcustom ytel-date-criterion 'year
  "Criterion to date limit the results of the search query."
  :type 'symbol
  :options '(hour day week month year)
  :group 'ytel)

(defun ytel-search (query)
  "Search youtube for `QUERY', and redraw the buffer."
  (interactive "sSearch terms: ")
  (setf ytel-current-page 1)
  (let* ((query-words (split-string query))
     (terms (seq-group-by (lambda (elem)
                (s-contains-p ":" elem))
                  query-words)))
    (setf ytel-search-term
      (s-join " " (assoc-default nil terms)))
    (if-let ((date (seq-find
            (lambda (s) (s-starts-with-p "date:" s) )
            (assoc-default t terms))))
    (setf ytel-date-criterion (intern (substring date 5)))
      (setf ytel-date-criterion 'year)))
  (setf ytel-videos (ytel--query ytel-search-term ytel-current-page))
  (ytel--draw-buffer))

It may not be the best way to use the search term to limit you could also implement it as toggle, where you can toggle through day/week/month/year.

grastello commented 4 years ago

I suppose this is best implemented as just a variable that the user can change instead of using the search term.

spiderbit commented 4 years ago

yeah I also think pressing as example d should toggle through the date limitation and refresh the search each time.

spiderbit commented 4 years ago

I just merged my changes to my master branch and tried to rebase your changes somehow I ended up with 2 merges and some commits double in my history, probably have to revert a lot and copy my current ytel.el file over it and make fresh commits, or something.

But you could look at the code or test it, and tell me what you think about it, next thing I probably do today would be a toggle for time limitation, well that merge shit throws me a bit off right now, not sure I have the nerve to deal with that now.

But would be nice to get some feedback for the things I have done:

  1. add capability to search with date:
  2. add a ytel-region-search for searching marked strings

https://github.com/spiderbit/ytel

spiderbit commented 4 years ago

ok fixed the history could make a pull request.