Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Haron-Prime committed Sep 17, 2017
1 parent a091aba commit 9690a56
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .config/Transmission Remote GUI/transgui.ini
Expand Up @@ -237,7 +237,7 @@ UpSpeeds=0,10,25,50,100,250,500,750,1000,2500,5000,7000
[AddTorrent.desktop]
FolderCount=10
Folder0=/home/haron/Video/tmp
LastMoveDir=/home/haron/Video
LastMoveDir=/home/haron/Video/tmp
Folder1=/home/haron/Video
Folder2=/home/haron/Video/FANTASTIC
Folder3=/home/haron/Video/FANTASTIC/A&P
Expand Down
Binary file modified .config/dconf/user
Binary file not shown.
2 changes: 1 addition & 1 deletion .config/mc/ini
Expand Up @@ -97,7 +97,7 @@ menubar_visible=0
free_space=1
horizontal_split=0
vertical_equal=1
left_panel_size=119
left_panel_size=136
horizontal_equal=1
top_panel_size=31

Expand Down
2 changes: 1 addition & 1 deletion .config/mpv/mpv.conf
Expand Up @@ -2,7 +2,7 @@
save-position-on-quit=yes
fullscreen=yes
hwdec=auto
vo=opengl-hq
profile=opengl-hq
volume-max=700
sub-codepage=enca:ru:utf8
osd-duration=5000
Expand Down
127 changes: 127 additions & 0 deletions .config/mpv/scripts/sopcast.lua
@@ -0,0 +1,127 @@
-- sopcast hook for mpv
--
-- How to use this script:
-- 1. Move this script to ~/.config/mpv/scripts
-- 2. Make sure sp-sc-auth/sp-sc is in your $PATH or in ~/.config/mpv
-- 3. Install luasocket

local utils = require 'mp.utils'
local msg = require 'mp.msg'
local socket = require 'socket'

local vars = {
sopcast = "sp-sc-auth",
sopcast_names = {"sp-sc-auth", "sp-sc"},
sopcast_args = "",
sock = nil,
url = "",
port = 8902,
timeout = 10,
debug = false
}

local function sleep(s)
local ntime = os.time() + s
repeat until os.time() > ntime
end

local function exec(args)
local ret = utils.subprocess({args = args})
return ret.status, ret.stdout
end

local function find_unused_port()
local command = { "ps", "-o", "command" }
local status, processes = exec(command)

local result = vars.port
for i in string.gmatch(processes, "[^\r\n]+") do
for j, name in ipairs(vars.sopcast_names) do
if not (string.find(i, name .. " sop://", 1, true) == nil) then
local port = tonumber(i:sub(i:match(".* ()")))
if (port >= result) then
result = port+1
end
end
end
end
return result
end

local function get_info()
vars.sock:send("s\n")
local response, status, partial = vars.sock:receive()
info = {}
for ele in response:gmatch("%w+") do table.insert(info, ele) end
return info
end

function debug_on_tick(event)
if vars.sock == nil then return end
local info = get_info()
msg.warn("cache: " .. info[1] .. " ur: " .. info[2] .. " dr: " .. info[3] ..
" us: " .. info[4] .. " ds: " .. info[5] .. " peers: " .. info[6])
end

local function on_start()
vars.url = mp.get_property("stream-open-filename")

if (vars.url:find("sop://") == 1) then
-- find sopcast binary, search various names
for i, name in ipairs(vars.sopcast_names) do
local sopcast_bin = mp.find_config_file(name)
if not (sopcast_bin == nil) then
msg.verbose("found sopcast at: " .. sopcast_bin)
vars.sopcast = sopcast_bin
break
end
end

-- find an unused port, needed for simultaneous streams
vars.port = find_unused_port()

-- start sopcast
msg.verbose("starting sopcast on port " .. vars.port)
vars.sopcast_args = vars.url .. " 3908 " .. vars.port
io.popen(vars.sopcast .. " " .. vars.sopcast_args .. " &")

-- try up to vars.timeout times to connect to sopcast
local timeout = 0
while (vars.sock == nil and timeout < vars.timeout) do
timeout = timeout + 1
vars.sock = socket.connect("localhost", vars.port)
sleep(1)
end

-- check if connection worked
if vars.sock ~= nil then
-- print debug info on tick
if vars.debug then
-- prepare sopcast for cache status
vars.sock:settimeout(10)
assert(vars.sock:send("state\ns\n"))
mp.register_event("tick", debug_on_tick)
end

-- open the local sopcast stream
mp.set_property("stream-open-filename", "http://localhost:" .. vars.port)
else
msg.warn("could not connect to sopcast. unresponsive or unuvailable channel.")
mp.command("quit")
return
end

end
end

function on_end(event)
if vars.sock ~= nil then
mp.unregister_event(tick)
vars.sock:close()
os.execute("pkill -f \"".. vars.sopcast .. " " .. vars.sopcast_args .. "\"" )
msg.verbose("sopcast terminated.")
end
end

mp.add_hook("on_load", 50, on_start)
mp.add_hook("on_unload", 50, on_end)
Empty file removed .config/psd/.psd.conf
Empty file.
1 change: 0 additions & 1 deletion .config/systemd/user/default.target.wants/psd.service

This file was deleted.

11 changes: 7 additions & 4 deletions Drafts/bash_command
Expand Up @@ -53,7 +53,6 @@ if [ "$a" -le "$b" ]
сравнение строк

=

равно

if [ "$a" = "$b" ]
Expand Down Expand Up @@ -97,13 +96,17 @@ if [ "$a" \> "$b" ]

Обратите внимание! Символ ">" необходимо экранировать внутри [ ].

См. Пример 25-6 относительно применения этого оператора сравнения.

-z
строка "пустая", т.е. имеет нулевую длину

-n
строка не "пустая".

Caution
Оператор -n требует, чтобы строка была заключена в кавычки внутри квадратных скобок. Как правило, проверка строк, не заключенных в кавычки, оператором ! -z, или просто указание строки без кавычек внутри квадратных скобок (см. Пример 7-6), проходит нормально, однако это небезопасная, с точки зрения отказоустойчивости, практика. Всегда заключайте проверяемую строку в кавычки. [1]
-o or ||
или

-a and &&
и

Оператор -n требует, чтобы строка была заключена в кавычки внутри квадратных скобок. Как правило, проверка строк, не заключенных в кавычки, оператором ! -z, или просто указание строки без кавычек внутри квадратных скобок, проходит нормально, однако это небезопасная, с точки зрения отказоустойчивости, практика. Всегда заключайте проверяемую строку в кавычки.
Binary file modified Man/s4a_latest.pdf
Binary file not shown.
Binary file added Man/zsh-refcard.pdf
Binary file not shown.

0 comments on commit 9690a56

Please sign in to comment.