目前我正在使用Advanced Renamer脚本方法(它提供了一个编写自己的JavaScript的窗口)来编写我的自定义脚本,但有了这个我不认为我将能够使用IMDB API或除了以外的任何其他资源写一些脚本来删除点,日期,大写字母。
所以我的问题是,如果我想为电视节目和电影制作文件重命名程序,我应该从哪里开始?我知道网上已经有很多可用的工具,但我想自己制作;如果有可能使用PHP和JavaScript那么它会很棒。
答案 0 :(得分:3)
我建议您使用库。有lm使用imdbpy并且就像ls
命令一样,但是对于电影而且它是用python编写的,我没有测试它。还有guessit
你也可以从你自己做的一切,但我个人认为这是一个很大的挑战。
首先,你需要一种从不可读的电影名称解析电影片名的方法(通过猜测它们),比你想要将标题发送到imdb api,一旦你认为答案还可以,你必须问你的程序重命名原始文件。
在php和javascript中做所有事情是可能的,但我认为用python这样的语言更容易实现。我在php中开始做一些事情,但在这个答案的最后,有一个很好的解决方案,使用python和guessit;)
我使用omdbapi,因为imdb api, see on stack overflow
没有文档假设您有一个填充了电影文件的movies
目录;如果你想模拟一些东西
touch Iron.Man.and.Captain.America.Heroes.United.2014.1080p.WEB-DL.x26.mkv
touch Batman.Assault.on.Arkham.2014.1080p.WEB-DL.x264.AAC-RARBG.mkv
touch The.Great.Hypnoti.2014.1080p.WEB-DL.x264.AAC-SeeHD.mkv
touch Taxi!\ Taxi!\ 2013\ 1080p\ WEB-DL\ x264\ AAC-SeeHD.mkv
touch Everybody\'s\ Business.2013.1080p.WEB-DL.x264.AAC-SeeHD.mkv
touch Jack.Frost.1998.1080p.WEB-DL.DD5.1.H.264.HKD.mkv
touch How.High.2001.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
touch Crazy.Sexy.Cool.The.TLC.Story.2013.1080p.WEB-DL.AC3.x264-FraMeST.mkv
touch Batman.Assault.on.Arkham.2014.1080p.WEB-DL.DD5.1.H264-RARBG.mkv
touch Iron.Man.and.Captain.America.Heroes.United.2014.1080p.WEB-DL.DD5.mkv
touch A.Haunted.House.2.2014.1080p.WEB-DL.DD5.1.H264-RARBG.mkv
touch Batman.Assault.on.Arkham.2014.1080p.WEB-DL.DD5.1.H.264-YFN.mkv
touch Puff.Puff.Pass.2006.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
touch My.Man.Is.a.Loser.2014.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
touch Welcome.Home.Roscoe.Jenkins.2008.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
注意:我甚至不知道大多数这些电影,那些只是文件名,我并不真正关心找到一个好的电影文件列表。哦,支付你喜欢的电影;)
现在好了,这是一个 awesome index.php
,带有一个工作示例示例:
<!doctype html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
// magical local jquery fallback
if (!window.jQuery) {
document.write('<script src="js/jquery-2.1.1.min.js"><\/script>');
}
</script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<?php
$dir = './movies';
// returns an array of only files (won't show ".", ".." and folders)
$files = array_filter(scandir($dir), function($item) {
return !is_dir($item);
});
echo "<ul id='movies'>";
// very dumb name extraction
foreach ($files as $file => $value) {
// remove extension
$files[$file] = preg_replace('/\\.[^.\\s]{3,4}$/', '', $value);
// replace dots with spaces
$files[$file] = str_replace('.', ' ', $files[$file]);
// keep name before year
$files[$file] = preg_split("/\d{4}/", $files[$file])[0];
// display on page with data-attribute filename
echo '<li class="file"><a href="#" data-filename=\'' . $files[$file] . '\')">' . $files[$file] . '</a></li>';
}
echo "</ul>";
?>
</body>
</html>
这是/js/app.js
:
$( document ).ready(function() {
get_imdb_data = function (strMovieTitle, where_to_show_poster_selector) {
$.ajax({
url: "http://www.omdbapi.com/?t=" + strMovieTitle,
dataType: 'jsonp',
success: function(results){
console.log(results);
where_to_show_poster_selector.append("<img name='" + results['Title'] + "' src='" + results['Poster'] + "'/>");
}
});
}
$('#movies .file a').each(function() {
get_imdb_data($(this).data('filename'), $('body'));
});
});
所有这些都会导致这个丑陋的页面;)
效果不好,有些图片丢失,可能是因为名字猜测部分,或者因为我选择了非常糟糕的电影名称,无论如何。
它目前没有重命名文件,但您可以使用rename function轻松地在php中执行某些操作。
pip install guessit
ls movies | xargs -I {} guessit {}
For: movies:
GuessIt found: {
[1.00] "type": "movie",
[0.60] "title": "movies"
}
For: A.Haunted.House.2.2014.1080p.WEB-DL.DD5.1.H264-RARBG.mkv
GuessIt found: {
[1.00] "mimetype": "video/x-matroska",
[1.00] "videoCodec": "h264",
[1.00] "container": "mkv",
[0.60] "title": "A Haunted House 2",
[1.00] "format": "WEB-DL",
[1.00] "releaseGroup": "RARBG",
[1.00] "audioChannels": "5.1",
[1.00] "screenSize": "1080p",
[1.00] "year": 2014,
[1.00] "type": "movie",
[1.00] "audioCodec": "DolbyDigital"
}
For: Batman.Assault.on.Arkham.2014.1080p.WEB-DL.DD5.1.H.264-YFN.mkv
GuessIt found: {
[1.00] "mimetype": "video/x-matroska",
[1.00] "videoCodec": "h264",
[1.00] "container": "mkv",
[1.00] "format": "WEB-DL",
[0.40] "series": "Batman Assault on Arkham",
[1.00] "releaseGroup": "YFN",
[1.00] "audioChannels": "5.1",
[1.00] "screenSize": "1080p",
[1.00] "year": 2014,
[1.00] "type": "episode",
[1.00] "audioCodec": "DolbyDigital"
}
For: Batman.Assault.on.Arkham.2014.1080p.WEB-DL.DD5.1.H264-RARBG.mkv
GuessIt found: {
[1.00] "mimetype": "video/x-matroska",
[1.00] "videoCodec": "h264",
[1.00] "container": "mkv",
[0.60] "title": "Batman Assault on Arkham",
[1.00] "format": "WEB-DL",
[1.00] "releaseGroup": "RARBG",
[1.00] "audioChannels": "5.1",
[1.00] "screenSize": "1080p",
[1.00] "year": 2014,
[1.00] "type": "movie",
[1.00] "audioCodec": "DolbyDigital"
}
For: Batman.Assault.on.Arkham.2014.1080p.WEB-DL.x264.AAC-RARBG.mkv
GuessIt found: {
[1.00] "mimetype": "video/x-matroska",
[1.00] "videoCodec": "h264",
[1.00] "container": "mkv",
[0.60] "title": "Batman Assault on Arkham",
[1.00] "format": "WEB-DL",
[1.00] "releaseGroup": "RARBG",
[1.00] "screenSize": "1080p",
[1.00] "year": 2014,
[1.00] "type": "movie",
[1.00] "audioCodec": "AAC"
}
For: Business.2013.1080p.WEB-DL.x264.AAC-SeeHD.mkv
GuessIt found: {
[1.00] "mimetype": "video/x-matroska",
[1.00] "videoCodec": "h264",
[1.00] "container": "mkv",
[0.60] "title": "Business",
[1.00] "format": "WEB-DL",
[1.00] "releaseGroup": "SeeHD",
[1.00] "screenSize": "1080p",
[1.00] "year": 2013,
[1.00] "type": "movie",
[1.00] "audioCodec": "AAC"
}
For: Crazy.Sexy.Cool.The.TLC.Story.2013.1080p.WEB-DL.AC3.x264-FraMeST.mkv
GuessIt found: {
[1.00] "mimetype": "video/x-matroska",
[1.00] "videoCodec": "h264",
[1.00] "container": "mkv",
[0.60] "title": "Crazy Sexy Cool The TLC Story",
[1.00] "format": "WEB-DL",
[1.00] "releaseGroup": "FraMeST",
[1.00] "screenSize": "1080p",
[1.00] "year": 2013,
[1.00] "type": "movie",
[1.00] "audioCodec": "AC3"
}
xargs: unterminated quote
我没有xargs: unterminated quote
的解决方案,在python脚本中使用guessit
作为python模块时不会发生这种情况。
在玩完所有东西后,我做了这个python循环,它运行得很好;)
import guessit, sys
import os
for root, dirs, filenames in os.walk("./movies"):
for filename in filenames:
data = guessit.guess_movie_info(filename, info=['filename'])
if data.confidence('title') > 0.5:
extension = os.path.splitext(filename)[1]
new_filename = data['title'] + " (" + str(data['year']) + ")" + extension
os.rename(os.path.join(root, filename), os.path.join(root, new_filename))
print "renamed", filename, "to" + new_filename
else:
print 'not sure for', filename, data['title']
print "confidence:", data.confidence('title')
A.Haunted.House.2.2014.1080p.WEB-DL.DD5.1.H264-RARBG.mkv
Batman.Assault.on.Arkham.2014.1080p.WEB-DL.DD5.1.H.264-YFN.mkv
Batman.Assault.on.Arkham.2014.1080p.WEB-DL.DD5.1.H264-RARBG.mkv
Batman.Assault.on.Arkham.2014.1080p.WEB-DL.x264.AAC-RARBG.mkv
Business.2013.1080p.WEB-DL.x264.AAC-SeeHD.mkv
Crazy.Sexy.Cool.The.TLC.Story.2013.1080p.WEB-DL.AC3.x264-FraMeST.mkv
Everybody's Business.2013.1080p.WEB-DL.x264.AAC-SeeHD.mkv
How.High.2001.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
Iron.Man.and.Captain.America.Heroes.United.2014.1080p.WEB-DL.DD5.mkv
Iron.Man.and.Captain.America.Heroes.United.2014.1080p.WEB-DL.x26.mkv
Jack.Frost.1998.1080p.WEB-DL.DD5.1.H.264.HKD.mkv
My.Man.Is.a.Loser.2014.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
Puff.Puff.Pass.2006.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
The.Great.Hypnoti.2014.1080p.WEB-DL.x264.AAC-SeeHD.mkv
Welcome.Home.Roscoe.Jenkins.2008.1080p.WEB-DL.AC3.x264-FraMeSToR.mkv
A Haunted House 2 (2014).mkv
Batman Assault on Arkham (2014).mkv
Business (2013).mkv
Crazy Sexy Cool The TLC Story (2013).mkv
Everybody's Business (2013).mkv
How High (2001).mkv
Iron Man and Captain America Heroes United (2014).mkv
Jack Frost (1998).mkv
My Man Is a Loser (2014).mkv
Puff Puff Pass (2006).mkv
The Great Hypnoti (2014).mkv
Welcome Home Roscoe Jenkins (2008).mkv
出了什么事,一些蝙蝠侠消失了;)(你可能需要添加一些用户提示或检查文件是否存在并相应地命名,等等。)
祝你好运,玩得开心;)