Code Monkey home page Code Monkey logo

myyt's Introduction

myyt

Script I wrote to search youtube with command line easily.

Requirements

You need to set the environment variable YT_API_KEY to the value of the token.

See tutorial on the API key if you need help, or start directly in the console if you are familiar with the platform.

Install the required programs: fzf, dmenu, mpv jq, awk and youtube-dl.

See video for futher detail

myyt's People

Contributors

avindra avatar bugswriter avatar keystroke3 avatar sudo-julia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

myyt's Issues

Script doesn't work outside the terminal

I'll explain the title here. So when the script is invoked with the standard dmenu_run script, everything works fine but with my dmenu script which should basically work the same way as the former, I get this error from jq:
jq: error (at <stdin>:14): can't iterate over null (null)
How I found out about this bug is that if I run your two scripts in the terminal, it works as expected but when I put a key binding in the header file for dwm, I was getting empty prompts i.e. the search results weren't being displayed. And apparently that was happening because of the fq error.
The only workaround I have right now is to invoke the standard dmenu_run script, type your script's name and do the search from there.
Since this is a new project, the issues are expected. However, your script is very helpful. Thanks.
Also, please check this video.
All the requirements are fulfilled.

use scraper to eliminate the requirement for API KEY

Since using Youtoube API for simple search seems like too much trouble (and is limited in the number of uses anyways), why not use a webpage scraper?

By a quick google, I found youtube-search (pip3 install youtube-search), and I changed the bash script to use the following python script instead of querying youtube API:

#!/usr/bin/env python3
from youtube_search import YoutubeSearch
from sys import argv

search_terms = str(argv)

results=YoutubeSearch(search_terms, max_results=10).to_dict()
urlString = '\n'.join((r['title']+' '+r['id'] for r in results))
print(urlString)

main bash lines then become:

urlstring=$(./new_python_script_name.py "${query}")
mpv "https://youtu.be/$( echo "${urlstring}" \
    | fzf --with-nth='1..-2' +m \
    | awk '{print $NF}' \
)"

It works great for me. It does require some polishing regarding the location of both scripts which influences how you call python from bash etc. The two scripts could probably be even merged into one (heredocs in bash or use python to call fzf and mpv) for extra points :)

So I'm just leaving this idea here with you, if I ever foolproof it, I'l turn it into a merge request.

./myyt: 9: Syntax error: redirection unexpected

Hi Bugswriter, thanks for the script!

When running ./dmenyt or ./myyt it prompts for the search query. Regardless of what I enter I receive the syntax error

$ ./myyt
Search query: test
./myyt: 9: Syntax error: redirection unexpected

Dependencies:

fzf is already the newest version (0.20.0-1).
mpv is already the newest version (0.32.0-1ubuntu1).
suckless-tools is already the newest version (44-1). [This contains dmenu]
youtube-dl is already the newest version (2020.03.24-1).

API key is properly inserted as variable in terminal,
output of echo:

user@desktop$: echo $YT_API_KEY
AIzaSyB-rGfbeC2w8dMxxxxxxx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.