Henry's Notebook
Many strange things
搜索
菜单
导航
首页
最近更改
随机页面
帮助
Henry's Home
个人资料
个人资料
创建账户
登录
消息
目前您没有通知。请访问您的
讨论页
以查看过去消息。
页面工具
内容页面
讨论
查看源代码
历史
首页
»
页面s
查看“Subwrap”的源代码
←
Subwrap
页面上次由
HenryHu
编辑于13年前
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:emailconfirmed
您可以查看与复制此页面的源代码。
[[Category:脚本|subwrap]] subwrap 是我写的一个小脚本,用来自动查找某视频对应的脚本,然后调用播放器播放。 因为我非常喜欢mplayer,所以目前只调用mplayer,因为我放啥都是用这个…… 因为我用的FreeBSD,所以这个脚本我只在BSD下试过。别的系统下面,file的返回结果可能不一样,要做相应修改…… 下载: [[文件:subwrap.pl]] <syntaxhighlight lang="perl"> #!/usr/bin/perl sub playfile { my($file, $sub, $encoding, $args) = @_; if ($encoding eq "") { system("mplayer \"$file\" -sub \"$sub\" -utf8 $args"); } else { # system("iconv -f $encoding -c \"$sub\" | mplayer \"$file\" -sub - -utf8 $args"); system("iconv -f $encoding -c \"$sub\" > /tmp/subtitle.sub"); system("mplayer \"$file\" -ass -sub /tmp/subtitle.sub -utf8 $args"); system("rm -f /tmp/subtitle.sub"); } } @exts = ('srt','ssa','ass'); @langs = ('en','Eng','chs','Chs','cn','sc','SC','uni_gb','gb','GB','cht','tc','TC','uni_big5','neta'); if ($#ARGV == -1) { print "Usage: subwrap <filename>\n"; exit 1; } $fname = $ARGV[0]; $argstr = ""; for ($i = 1; $i <= $#ARGV; $i = $i + 1) { $argstr = $argstr . $ARGV[$i] . " "; } if (!(-e $fname)) { print "Cannot find specified file.\n"; exit 2; } if (!($fname =~ m/(.*)\.(.*)/)) { print "Cannot find . in filename.\n"; exit 1; } for ($way = 0; $way < 2; $way++) { if ($way == 0) { $fname =~ m/(.*)\.(.*)/; $basename = $1; } else { $fname =~ m/(.*)\[.*\]\.(.*)/; $basename = $1; } # First let's try only extensions foreach $i (@exts) { $subname = $basename . "." . $i; if (-e $subname) { goto FOUND; } } # Now let's try extensions with languages foreach $i (@langs) { foreach $j (@exts) { $subname = $basename . "." . $i . "." . $j; if (-e $subname) { goto FOUND; } } } } # We failed! print "Cannot found subtitles in (@exts) or (@langs) . (@exts).\n"; exit 2; FOUND: $filetype = `file "$subname"`; print "Found sub file: $subname\n"; if ($filetype =~ m/ISO-8859/ or $filetype =~ m/extended-ASCII/) { # GBK file print "Converting from GBK encoding\n"; playfile($fname, $subname, "gbk", $argstr); } elsif ($filetype =~ m/UTF-16/) { # UTF-16 file if ($filetype =~ m/Little-endian/) { # UTF-16 Little Endian print "Converting from UTF-16LE encoding\n"; playfile($fname, $subname, "utf-16le", $argstr); } else { # UTF-16 Big Endian print "Converting from UTF-16BE encoding\n"; playfile($fname, $subname, "utf-16be", $argstr); } } else { playfile($fname, $subname, "", $argstr); } </syntaxhighlight>
返回至
Subwrap
。