Archive

Archive for the ‘bash’ Category

download with youtube-dl

June 20, 2017 Leave a comment

For downloading a YouTube playlist, or for downloading all the videos of a YouTube user, I use this script:

URL="https://..."    # youtube user / playlist

youtube-dl --ignore-errors --download-archive downloaded.txt -f 22 "$URL"

The videos will be saved in .mp4 format. You can stop the script and re-run it later. The already saved videos are stored in downloaded.txt and they will be skipped if you re-run the script.

Categories: bash Tags: ,

JSON Path

May 20, 2017 1 comment

I wrote a command-line program that outputs the full path of every key / value in a JSON file.

Example

$ ./json_path.py sample.json
root.a => 1
root.b.c => 2
root.b.friends[0].best => Alice
root.b.friends[1].second => Bob
root.b.friends[2][0] => 5
root.b.friends[2][1] => 6
root.b.friends[2][2] => 7
root.b.friends[3][0].one => 1
root.b.friends[3][1].two => 2

More information at the project’s github page.

Categories: bash, python Tags: ,

streamlink

Streamlink is a command-line utility that allows you to watch online video streams in popular video players, such as VLC, MPlayer or mpv.

(Under Manjaro it’s installable with yaourt.)

Example:

$ streamlink twitch.tv/sscait 
[cli][info] Found matching plugin twitch for URL twitch.tv/sscait
Available streams: 720p_alt, audio_only, 160p (worst), 360p, 480p, 720p (best)

$ streamlink twitch.tv/sscait best

If you just want to listen to it, select “audio_only” instead of “best”. It has lots of options, see the man for more info. For scripting, there is also a “-j” switch to produce a JSON output instead of normal text.

When is it useful? For instance you have a favourite channel that is streaming right now, but you don’t want to open it in the browser. Just launch it from the command-line and watch it in VLC. Or, if it’s a talk show, you just want to listen to it (see “audio_only”).

Categories: bash Tags: , , ,

sending e-mails from your app.

If you want to send e-mails from your application, check out https://www.mailgun.com/. You can register for free and with your free account you can also send a good number of e-mails. And if you pay for it, you can send thousands of mails if you want. Their service can be used from Bash, Python, PHP, etc.

On my VPS I used a command-line solution (see here) that sends e-mails with sendmail. Unfortunately, Gmail treats these mails as spam, so it’s not appropriate for sending messages to other people. Mailgun is a better solution.

Categories: api, bash, python Tags: ,

increase sudo timeout

February 12, 2017 Leave a comment

Problem
You want to increase the sudo password remember timeout.

Solution
Run “sudo visudo“, then add this line to the end:

Defaults    timestamp_timeout=60

Where 60 means 60 minutes. If you specify -1, then the password is never forgotten (which is not a good idea IMO).

Tip from here.

Categories: bash, linux Tags: ,

Don’t paste blindly to your terminal

January 27, 2017 2 comments

Most of the time when we see a code snippet online to do something, we often blindly copy paste it to the terminal.

Well, the copied text may contain some malicious code. Here is a post about that with a demo.

Categories: bash Tags: , ,