shell和awk配合使用
#!/bin/sh
#$1 video id
#$2 save result file
#####################################################################
#function decrypt_signature() {
decrypt_signature() {
encrypted_sig="$1"
video_id="$2"
player_url="$3"
age_gate="$4"
url_start=`awk -v url=$player_url 'BEGIN{print index(url,"//");}'`
echo url_start=$url_start
if [ "$url_start" = "1" ];then
player_url="https:""$player_url"
fi
echo player_url=$player_url
wget $player_url -O "$fpipe_new0"
echo fpipe_new0=$fpipe_new0
}
version="youtube_get_play_url:v2.0\n"
helpContent="Parameter1:video_id\nParameter2:result save file\nexample:\nyoutube_get_play_url ACFADSFxf file\n"
if [ "$1" = "--version" ];then
printf "$version"
exit 0
fi
if [ "$1" = "--help" ];then
printf "$helpContent"
exit 0
fi
if [ -z "$1" ];then printf "$helpContent"; exit 0; fi
if [ -z "$2" ];then printf "$helpContent"; exit 0; fi
vurl="$1"
fresult="$2"
fpipe="$2""_tmp"
fpipe2="$2""_tmp2"
fpipe_new0="$2""_tmp3"
fpipe_new1="$2""_tmp4"
echo vurl=$vurl
echo fresult=$fresult
rm "$fresult" -rf
rm "$fpipe" -rf
rm "$fpipe2" -rf
url="http://www.youtube.com/watch?v=""$vurl""&gl=US&hl=en&has_verified=1"
detail_url="https://www.youtube.com/get_video_info?&video_id=""$vurl""&el=detailpage&ps=default&eurl=&gl=US&hl=en"
wget $url -O "$fpipe"
cp "$fpipe" "$fpipe_new0"
age_gate=`grep "player-age-gate-content" < "$fpipe_new0"`
tr -d "\0" < "$fpipe" > "$fpipe2"
sed -i 's/, "/\n/g' "$fpipe2"
grep "url_encoded_fmt_stream_map" < "$fpipe2" > "$fpipe"
sed -i 's/,/\n/g' "$fpipe"
grep -m 1 "x-flv" < "$fpipe" > "$fpipe2"
sed -i 's/\\u0026/\n/g' "$fpipe2"
grep -E "url=|sig=|s=" < "$fpipe2" > "$fpipe"
str_grep=`grep "s=" < "$fpipe"`
if [ -n "$str_grep" ];then
echo "$str_grep"
echo "$str_grep" > "$fpipe2"
sed -i "s/^s=//" "$fpipe2"
if [ -n "$age_gate" ];then
echo age_gate=$age_gate
else
grep -E "\"assets\":*" <"$fpipe_new0" >"$fpipe_new1"
sed -i 's/;/\n/g' "$fpipe_new1"
sed -i 's/,/\n/g' "$fpipe_new1"
sed -i 's/}/\n/g' "$fpipe_new1"
sed -i 's/:/\n/g' "$fpipe_new1"
sed -i 's/ /\n/g' "$fpipe_new1"
sed -i 's/"//g' "$fpipe_new1"
sed -i 's/\\//g' "$fpipe_new1"
player_url=`grep "html5player" < "$fpipe_new1"`
echo player_url=$player_url
decrypt_signature $str_grep $vurl $player_url $age_gate
fi
str_sig=`youtube_rev "$fpipe2"`
echo "sig=""$str_sig"
sed -i "s/^s=.*$/signature=""$str_sig""/" "$fpipe"
fi
sed -i 's/%26/\&/g' "$fpipe"
sed -i 's/%3D/=/g' "$fpipe"
sed -i 's/%25/%/g' "$fpipe"
sed -i 's/%2F/\//g' "$fpipe"
sed -i 's/%3A/:/g' "$fpipe"
sed -i 's/%3F/?/g' "$fpipe"
sed -i 's/^sig=/signature=/' "$fpipe"
#sed -i 's/^s=/signature=/' "$fpipe"
ARG1=`cat "$fpipe" | grep "url=http" | sed -e 's/^.*url=//g'`
ARG2=`cat "$fpipe" | grep "signature="`
echo "$ARG1""&""$ARG2" > "$fpipe2"
echo "[Http] URL="$url
if [ -s "$fpipe2" ];then
mv "$fpipe2" "$fresult"
echo "got video url."
else
echo "this video is removed."
rm "$fpipe" -rf
rm "$fpipe2" -rf
fi
exit 0
shell和awk配合使用的更多相关文章
- AWK增强的文本处理shell特征--AWK完全手册
AWK这是一个很好的文字处理工具. 它不仅 Linux 中也是不论什么环境中现有的功能最强大的数据处理引擎之中的一个. 本文主要摘录池中龙写的Unixawk使用手冊(第二版),对当中内容略微修改.感谢 ...
- CU社区shell板块awk十三问整理
CU社区shell板块awk十三问整理 一.RS="" 当 RS="" 时,会将\n强制加入到FS变量中,因为RS为空时,是将连续多空行作为分隔符,近似于\n\ ...
- Shell 学习—AWK介绍
Shell 学习—AWK = = = 安装awk root@kiki-desktop:~/shell# apt-get install gawk gawk-doc = = = awk 是一种程序语言. ...
- Shell之awk
Shell之awk 目录 Shell之awk 一.awk概述 1. awk的工作原理 2. 命令格式 3. awk常见的内建变量(可直接用) 二.操作实例 1. 按行输出文本 2. 按字段输出文本 3 ...
- shell中awk用法
简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...
- shell 统计 awk
time awk '{a[$1]++}END{for(i in a){printf("%d\t%s\n",a[i],i)}}' access.log | sort -nr | he ...
- shell 之awk 关联数组高级应用
最近由于数据迁移过,有些用户信息需要再次确认下,也许数据量比较大,但是需要最终确认的比如说是用户ID和其对应的用户积分数,这样就会导致出现文本a(老的数据),文本b(新的数据).比如 这是文本a.tx ...
- shell脚本 awk工具
awk工具概述awk编程语言/数据处理引擎基于模式匹配检查输入文本,逐行处理并输出通常在shell脚本中,或取指定的数据单独用时,可对文本数据做统计 命令格式格式一:awk [选项] '[条件]{编辑 ...
- 【shell】awk按域去除重复行
首先解释一下什么叫“按域去除重复行”: 有的时候我们需要去除的重复行并不是整行都重复,两行的其中一列的元素相同我们有的时候就需要认定这两行重复,因此有了今天的内容. 去除重复行shell有一个原生命令 ...
随机推荐
- 【对比分析二】Web Storage和cookie的区别
1) 存储空间不同. a) Web Storage能提供5MB的存储空间(不同浏览器的提供的空间不同).Cookie仅4KB. b) Web Storage每个域(包括子域)有独立的存储空间,各 ...
- maven -- 问题解决(一)解决eclipse中maven项目配置过程和maven install时出现的问题
问题一: 配置项目时出现的错误: error: Cannot change version of project facet Dynamic Web Module to 2.5. error: One ...
- Linux-JDK+Tomcat的安装笔记
Linux-JDK+Tomcat的安装 一.JDK的安装 1. 使用命令uname –a查看系统的版本确定系统的位数,然后去JDK官网下载相应位数的安装程序,进行安装. 2. 使用rz命令将下载的 ...
- 基于Landmark的人脸对齐以及裁剪方法
利用Landmarks进行人脸对齐裁剪是人脸检测中重要的一个步骤.效果如下图所示: 基本思路为: a.人脸检测 人脸的检测不必多说了,基本Cascade的方式已经很不错了,或者用基于HOG/FHOG的 ...
- 理解PHP数组的序列化和反序列化
当我们想要将数组值存储到数据库时,就可以对数组进行序列化操作,然后将序列化后的值存储到数据库中.其实PHP序列化数组就是将复杂的数组数据类型转换为字符串,方便数组存库操作.对PHP数组进行序列化和反序 ...
- Html基本操作实例代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- blurImage做图片模糊处理报错free(): invalid next size
$image = new Imagick($url); $image->blurImage($x, $y); 调用blurImage($x, $y)函数报错: 原因是:原来的图片是CMYK的是印 ...
- Matlab的linprog解决简单线性规划问题
一个简单的线性规划问题,使用Matlab的linprog解决 假定有n种煤,各种煤的配比为x1,x2,x3,……首先需要满足下列两个约束条件,即 x1+x2+x3……+xn=1 x1≥0, x2≥0, ...
- 访问自身子画面的方法 [self.view viewWithTag:100];
UIImageView *view1 = (UIImageView*)[self.view viewWithTag:100];
- Mybatis 传入List类型参数,报错:There is no getter for property named '__frch_item_0' in
错误如下: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.Re ...