You are not logged in.

#151 2020-10-04 08:27:56

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

Search youtube without a browser, choose from results & copy page link to clipboard:
https://notabug.org/ohnonot/stuff/src/m … ube-search


BL quote proposals to this thread please.
my repos / my repos

Offline

#152 2020-10-04 12:44:09

Martin
Member
From: Stockholm, Sweden
Registered: 2015-10-01
Posts: 472
Website

Re: Handy command-line stuff for terminals or scripts

martin@he2:~$ youtube-search.py GC32
  File "/home/martin/bin/youtube-search.py", line 32
    def __init__(self, search_terms: str, max_results=None):
                                   ^
SyntaxError: invalid syntax

/Martin


"Problems worthy of attack
prove their worth by hitting back."
Piet Hein

Offline

#153 2020-10-04 12:56:08

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,437

Re: Handy command-line stuff for terminals or scripts

same error here.


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#154 2020-10-04 14:53:27

vasa1
Member
Registered: 2015-09-29
Posts: 190

Re: Handy command-line stuff for terminals or scripts

Works for me (on Kubuntu 20.04) with Python 3.8.2.


Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)

Offline

#155 2020-10-04 15:48:34

Martin
Member
From: Stockholm, Sweden
Registered: 2015-10-01
Posts: 472
Website

Re: Handy command-line stuff for terminals or scripts

Changing to

#!/usr/bin/python3

made it work for me.

/Martin


"Problems worthy of attack
prove their worth by hitting back."
Piet Hein

Offline

#156 2020-10-04 16:16:56

sleekmason
Member
Registered: 2018-05-22
Posts: 209

Re: Handy command-line stuff for terminals or scripts

Martin wrote:

Changing to

#!/usr/bin/python3

made it work for me.

/Martin

Here as well:)  Thank you!  What a cool script!

Offline

#157 2020-10-06 06:08:31

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

Martin wrote:

Changing to

#!/usr/bin/python3

made it work for me.

Wow, I didn't know Debian still defaults to python2!
Anyhow, Code fixed, updated.


BL quote proposals to this thread please.
my repos / my repos

Offline

#158 2020-10-07 04:29:55

vasa1
Member
Registered: 2015-09-29
Posts: 190

Re: Handy command-line stuff for terminals or scripts

@ohnonot, when I enter "python" or "python scripts" or "coding in python" with or without quotes as the search term, I don't get any results in youtube-search.

Changing "python" to "haskell" works fine

Last edited by vasa1 (2020-10-07 13:05:02)


Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)

Offline

#159 2020-10-07 14:59:31

sleekmason
Member
Registered: 2018-05-22
Posts: 209

Re: Handy command-line stuff for terminals or scripts

Everybody needs a one-liner toggle for menus and keybinds:)

bash -c 'if ! pkill -x compton; then exec compton; fi'

Use it for compton, conky, xclip, etc.. No need to script a toggle!

Offline

#160 2020-10-07 20:35:54

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

vasa1 wrote:

@ohnonot, when I enter "python" or "python scripts" or "coding in python" with or without quotes as the search term, I don't get any results in youtube-search.

Changing "python" to "haskell" works fine

Not sure why you crossed that out again, but I have noticed something similar too.
I suspect YT has its own way of determining whether it likes your query or not - esp. after you've been playing with the script for a while, making dozens of searches. Usually it works again when you simply enter the same search term again.
But I cannot enter the search term "search youtube" - it always returns 0 results. Weird.


BL quote proposals to this thread please.
my repos / my repos

Offline

#161 2020-10-08 02:27:39

vasa1
Member
Registered: 2015-09-29
Posts: 190

Re: Handy command-line stuff for terminals or scripts

ohnonot wrote:

Not sure why you crossed that out again, but I have noticed something similar too.
I suspect YT has its own way of determining whether it likes your query or not - esp. after you've been playing with the script for a while, making dozens of searches. Usually it works again when you simply enter the same search term again.
But I cannot enter the search term "search youtube" - it always returns 0 results. Weird.

Thanks for confirming!

I crossed out my post because I noticed the problem wasn't 100% reproducible and had a feeling it was possibly something wrong at my end.

All the same it's very useful. Search for something and pop the link into mpv!

(BTW, for my personal use, I've removed the input_with_prefill aspect and changed |xclip to |xclip -selection clipboard.)


Using the Openbox (3.5.2) session of Lubuntu 14.04 LTS but very interested in BL :)

Offline

#162 2020-10-10 07:13:24

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

vasa1 wrote:

for my personal use, I've removed the input_with_prefill aspect

Yes, that can be annoying when the clipboard is filled with useless and sometimes long text, but again very useful for highlight & search situations (like e.g. FF's context menu has).

The script would need command line options, I guess that will be my next foray into the wrold of python.


BL quote proposals to this thread please.
my repos / my repos

Offline

#163 2020-10-15 19:14:28

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

I added command line options to youtube-search:

$> youtube-search -h

Search Youtube.

Usage: youtube-search [OPTIONS] [SEARCH STRING]

You can provide a search string on the command line or enter it interactively.

It helps if xclip and/or tput are available, but the script works without those.

OPTIONS
    -c      Use Clipboard instead of primary selection
    -p      Prefill the search with whatever is found in the selected clipboard
    -l      List more detail for each result
    -f      Don't cut long strings to terminal width
    -m int  Maximum number of results shown
    -a      Append to /tmp/youtube-search.log instead of overwriting
    -h      This help

https://notabug.org/ohnonot/stuff/src/m … ube-search
Enjoy!

Empty search results can sometimes happen; AFAICS that is entirely YT's decision and not a problem with the script. Just try a few times.


BL quote proposals to this thread please.
my repos / my repos

Offline

#164 2020-10-15 21:24:04

damo
....moderator....
Registered: 2015-08-20
Posts: 6,329

Re: Handy command-line stuff for terminals or scripts

Very cool script smile

Now in my main menu as

Youtube Search,x-terminal-emulator -e yt-search.py

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#165 2020-10-16 12:47:04

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

Thanks.
I have now added tor functionality: the script can connect to an existing tor session. It actually works better that way for me (I guess YT does not like my IP very much).
Then I've added a wrapper shell script that starts a dedicated tor session, then performs the YT search.
If both youtube-search and youtube-search-tor are in PATH it should work.
Tor functionality also adds a dependency for python 'requests', which seems to be provided by the 'python3-requests' package. I would appreciate feedback about how this works on Debian stable.

BTW, notabug seems to be under DOS attack atm, try framagit:
https://framagit.org/ohnonot/stuff/


BL quote proposals to this thread please.
my repos / my repos

Offline

#166 2020-10-16 20:35:15

Martin
Member
From: Stockholm, Sweden
Registered: 2015-10-01
Posts: 472
Website

Re: Handy command-line stuff for terminals or scripts

My first try was not a smashing success:

martin@he2:~$ youtube-search-tor
tor is /usr/sbin/tor
youtube-search is /home/martin/bin/youtube-search
Pidof tor: 15002
------------------------------------------------------------------------------------
Enter search terms for youtube (minimum length 3 chars): 
eastory
Timeout reached, no response.
Traceback (most recent call last):
  File "/home/martin/bin/youtube-search", line 267, in <module>
    results = YoutubeSearch(uts, max_results).to_dict()
  File "/home/martin/bin/youtube-search", line 54, in __init__
    self.videos = self.search()
  File "/home/martin/bin/youtube-search", line 81, in search
    results = self.parse_html(response)
UnboundLocalError: local variable 'response' referenced before assignment

Doing the same search just using youtube-search works fine.

I have never used tor before...

/Martin


"Problems worthy of attack
prove their worth by hitting back."
Piet Hein

Offline

#167 2020-10-17 07:48:48

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

Apparently tor is installed.
Try using the tor browser - does that work normally? In other words, does tor work on your system?
This seems to be a timeout problem. You might have hit a very slow node, tor chooses them randomly. Have you just tried again?
There's also /tmp/youtube-search-tor-<username>.log


BL quote proposals to this thread please.
my repos / my repos

Offline

#168 2020-10-17 14:33:53

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 270

Re: Handy command-line stuff for terminals or scripts

Hey! Thanks for that!

I had to slightly change both scripts according to naming and version problems, I guess.
I just took the script from notabug and saved it as ~/bin/yt-search.py, so I had to update the calls in youtube-search-tor accordingly and than the script from notabug doesn't take the -P and -T options, but after coping with this everything works fine:

┌─[naik@GerryTSSD ~]
└──$ ~/bin/youtube-search-tor
tor ist /usr/sbin/tor
/home/naik/bin/youtube-search-tor: Zeile 4: type: youtube-search: Nicht gefunden.
┌─[naik@GerryTSSD ~]
└──$ nano ~/bin/youtube-search-tor
┌─[naik@GerryTSSD ~]
└──$ ~/bin/youtube-search-tor
tor ist /usr/sbin/tor
yt-search.py ist /home/naik/bin/yt-search.py
Pidof tor: 23197
/home/naik/bin/youtube-search-tor: Zeile 32: youtube-search: Kommando nicht gefunden.
┌─[naik@GerryTSSD ~]
└──$  ~/bin/youtube-search-tor
tor ist /usr/sbin/tor
yt-search.py ist /home/naik/bin/yt-search.py
Pidof tor: 23293
/home/naik/bin/youtube-search-tor: Zeile 32: youtube-search: Kommando nicht gefunden.
┌─[naik@GerryTSSD ~]
└──$ geany ~/bin/youtube-search-tor
┌─[naik@GerryTSSD ~]
└──$ ~/bin/youtube-search-tor
tor ist /usr/sbin/tor
yt-search.py ist /home/naik/bin/yt-search.py
Pidof tor: 23644
option -T not recognized

Search Youtube.

Usage: youtube-search [OPTIONS] [SEARCH STRING]

You can provide a search string on the command line or enter it interactively.

It helps if xclip and/or tput are available, but the script works without those.

OPTIONS
    -c      Use Clipboard instead of primary selection
    -p      Prefill the search with whatever is found in the selected clipboard
    -l      List more detail for each result
    -f      Don't cut long strings to terminal width
    -m int  Maximum number of results shown
    -a      Append to /tmp/yt-search.py.log instead of overwriting
    -h      This help

┌─[naik@GerryTSSD ~]
└──$ ~/bin/youtube-search-tor "Käpt'n Peng"
tor ist /usr/sbin/tor
yt-search.py ist /home/naik/bin/yt-search.py
Pidof tor: 23812
option -T not recognized

Search Youtube.

Usage: youtube-search [OPTIONS] [SEARCH STRING]

You can provide a search string on the command line or enter it interactively.

It helps if xclip and/or tput are available, but the script works without those.

OPTIONS
    -c      Use Clipboard instead of primary selection
    -p      Prefill the search with whatever is found in the selected clipboard
    -l      List more detail for each result
    -f      Don't cut long strings to terminal width
    -m int  Maximum number of results shown
    -a      Append to /tmp/yt-search.py.log instead of overwriting
    -h      This help

┌─[naik@GerryTSSD ~]
└──$ geany ~/bin/youtube-search-tor
┌─[naik@GerryTSSD ~]
└──$ ~/bin/youtube-search-tor "Käpt'n Peng"
tor ist /usr/sbin/tor
yt-search.py ist /home/naik/bin/yt-search.py
Pidof tor: 24534
Search string: 9222 Käpt'n Peng
1 ----------------------------------------------------------------------------------
  Title:       Shaban & Käptn Peng - Sie mögen sich
  Description: Ein Lied vom Album "Die Zähmung der Hydra" Zeichnungen: Lane Schäfer 
  Duration:    6:56
  Url:         https://www.youtube.com/watch?v=apCal7ihvy0
2 ----------------------------------------------------------------------------------
  Title:       Käptn Peng im Wortgewand
  Description: Der Käptn hat seinen Verstand noch immer nicht wieder gefunden. Dafür
  Duration:    2:30
  Url:         https://www.youtube.com/watch?v=RvUeTzcBdsI
3 ----------------------------------------------------------------------------------
  Title:       shaban & Käptn Peng - werbistich
  Description: Ein Waldspaziergang, eigentlich nix verfängliches.. Aber wenn einen d
  Duration:    6:47
  Url:         https://www.youtube.com/watch?v=MpOVJWi6ul8
4 ----------------------------------------------------------------------------------
  Title:       Käptn Peng & Die Tentakel von Delphi - Der Anfang ist nah
  Description: Das erste Lied vom Album "Expedition ins O" von den Tentakeln von Del
  Duration:    5:45
  Url:         https://www.youtube.com/watch?v=vqRWMDv0r78
5 ----------------------------------------------------------------------------------
  Title:       KÄPTN PENG & DIE TENTAKEL VON DELPHI - Gelernt
  Description: Ein Lied aus dem Album "Das Nullte Kapitel" konsumquatsch: Kreismusik
  Duration:    3:21
  Url:         https://www.youtube.com/watch?v=JtULNuoS3jg
6 ----------------------------------------------------------------------------------
  Title:       shaban & Käptn Peng - parantatatam
  Description: Nachdem der Käptn den Verstand verlor und das Rätsel seines eigenen G
  Duration:    4:23
  Url:         https://www.youtube.com/watch?v=QEXVqYgHrsY
7 ----------------------------------------------------------------------------------
  Title:       Shaban & Käptn Peng -  Kündigung 2.0
  Description: Ein Lied vom Album "Die Zähmung der Hydra" http://www.kreismusik.de K
  Duration:    3:15
  Url:         https://www.youtube.com/watch?v=ojrwKSWrNCs
8 ----------------------------------------------------------------------------------
  Title:       KÄPTN PENG & DIE TENTAKEL VON DELPHI - Neue Freunde
  Description: Album "Das nullte Kapitel" ab dem 19.05.2017 bei www.kreismusik.de un
  Duration:    4:56
  Url:         https://www.youtube.com/watch?v=g3oQxIxaJIU
9 ----------------------------------------------------------------------------------
  Title:       Käptn Peng - Liebes Leben
  Description: http://www.kreismusik.de.
  Duration:    2:37
  Url:         https://www.youtube.com/watch?v=c1cIn4Ni7rw
------------------------------------------------------------------------------------
Your choice (1-9, q to quit, s to search again): q
Results can be found in /tmp/yt-search.py.log

Naik --greetz


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

#169 Yesterday 08:19:36

Martin
Member
From: Stockholm, Sweden
Registered: 2015-10-01
Posts: 472
Website

Re: Handy command-line stuff for terminals or scripts

ohnonot wrote:

Apparently tor is installed.
Try using the tor browser - does that work normally? In other words, does tor work on your system?
This seems to be a timeout problem. You might have hit a very slow node, tor chooses them randomly. Have you just tried again?
There's also /tmp/youtube-search-tor-<username>.log

Sorry for the late reply. I spent yesterday covering my boat for winter.

I have downloaded and tried the Tor Browser as well as trying Brave's Tor mode. Both work but does it tell us anything about the tor called by your script? While trying Brave's Tor mode I noticed youtube's response times, but nothing else, became really long and eventually I was blocked from watching videos (including my own). I saw none of this while using the Tor Browser.

I don't have a /tmp/youtube-search-tor-<username>.log

/Martin


"Problems worthy of attack
prove their worth by hitting back."
Piet Hein

Offline

#170 Yesterday 10:28:50

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

@Naik: wouldn't it be easier to just symlink /path/to/repo/youtube-search to ~/bin, instead of copying it over under a different name then rewriting the script?
If you need to edit to the script, tell me what it is, I'll try to make that a command line option instead (so that the repo remains untouched).

@all:
During your last posts development was in heavy flux, there might have been a temporary mismatch between the 2 scripts.
I changed the -T (=Tor) option to -S (=Socks) because all it does is try to connect to a socks5 proxy. It does not provide actual tor functionality, but tor provides a socks5 proxy to connect to by default.
So -T is now -S, in both scripts.

So please make sure you use the newest version, and tell me if you felt the need to edit the scripts, I'll try to accomodate that.

youtube-search-tor uses only European nodes by default - if you want to remove that restriction, pass -c '', like so:

youtube-search-tor -c ''

All further arguments are passed on to youtube-search.


Martin wrote:

I have downloaded and tried the Tor Browser as well as trying Brave's Tor mode. Both work but does it tell us anything about the tor called by your script?

It just tells us that tor is working in general.
But my script creates a new connection on a dedicated port (9222, currently hardcoded).
BTW, tor-browser uses port 9150 by default, you can try youtube-search -S (it defaults to port 9150) while the tor-browser is running.

I don't have a /tmp/youtube-search-tor-<username>.log

That's weird; is your /tmp not user-writeable?
BTW, it should be just /tmp/youtube-search-tor.log now.


BL quote proposals to this thread please.
my repos / my repos

Offline

#171 Today 07:05:17

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,326
Website

Re: Handy command-line stuff for terminals or scripts

@ohnonot maybe this project deserves its own thread, rather than sitting in the middle of a bunch of CLI tips?

Would you like me to split it off?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#172 Today 12:58:01

ohnonot
...again
Registered: 2015-09-29
Posts: 4,917
Website

Re: Handy command-line stuff for terminals or scripts

johnraff wrote:

Would you like me to split it off?

Yes please!
Thanks.


BL quote proposals to this thread please.
my repos / my repos

Offline

Board footer

Powered by FluxBB