apple-tv-converter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README.md +13 -2
- data/bin/apple-tv-converter +5 -0
- data/lib/apple_tv_converter.rb +1 -0
- data/lib/apple_tv_converter/command_line.rb +94 -0
- data/lib/apple_tv_converter/media_converter.rb +17 -27
- data/lib/apple_tv_converter/media_converter_adapter.rb +12 -9
- data/lib/apple_tv_converter/media_converter_mac_adapter.rb +6 -6
- data/lib/apple_tv_converter/version.rb +1 -1
- metadata +5 -2
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -9,8 +9,19 @@ Media converter for AppleTV.
|
|
9
9
|
- Uses Subler for adding the subtitles and setting the iTunes metadata tags (http://code.google.com/p/subler/)
|
10
10
|
- Uses MKVToolNix for extracting the embedded subtitles from MKV files (http://www.bunkus.org/videotools/mkvtoolnix/)
|
11
11
|
|
12
|
+
## Command line usage
|
13
|
+
|
14
|
+
``` bash
|
15
|
+
apple-tv-converter option [option] [option]...
|
16
|
+
|
17
|
+
options:
|
18
|
+
- --no-subtitles # Skips subtitles extraction and addition
|
19
|
+
- --no-metadata # Skips adding metadata to the converted file
|
20
|
+
- --no-cleanup # Skips deleting the source files
|
21
|
+
- Anything not starting with -- is considered a file to convert
|
22
|
+
```
|
23
|
+
|
12
24
|
# TODO
|
13
25
|
|
14
26
|
- Windows implementation
|
15
|
-
- Tests!
|
16
|
-
- Create a Mac OSX executable for running the script
|
27
|
+
- Tests!
|
data/lib/apple_tv_converter.rb
CHANGED
@@ -12,6 +12,7 @@ require 'language_list'
|
|
12
12
|
|
13
13
|
require 'apple_tv_converter/version'
|
14
14
|
require 'apple_tv_converter/io_patch'
|
15
|
+
require 'apple_tv_converter/command_line'
|
15
16
|
require 'apple_tv_converter/media_converter'
|
16
17
|
require 'apple_tv_converter/media'
|
17
18
|
require 'apple_tv_converter/media_converter_adapter'
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module AppleTvConverter
|
2
|
+
class CommandLine
|
3
|
+
def initialize(*args)
|
4
|
+
@skip_subtitles = false
|
5
|
+
@skip_metadata = false
|
6
|
+
@skip_cleanup = false
|
7
|
+
|
8
|
+
begin
|
9
|
+
options = parse_arguments(args)
|
10
|
+
|
11
|
+
media_objects = options.delete(:media)
|
12
|
+
|
13
|
+
converter = AppleTvConverter::MediaConverter.new(options)
|
14
|
+
|
15
|
+
media_objects.each do |media|
|
16
|
+
converter.process_media media
|
17
|
+
end
|
18
|
+
rescue ArgumentError => e
|
19
|
+
puts "Error: #{e.message}"
|
20
|
+
rescue => e
|
21
|
+
puts "Error: #{e.message}"
|
22
|
+
puts e.backtrace
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_arguments(arguments)
|
29
|
+
data = {
|
30
|
+
:skip_subtitles => false,
|
31
|
+
:skip_metadata => false,
|
32
|
+
:skip_cleanup => false,
|
33
|
+
:media => []
|
34
|
+
}
|
35
|
+
|
36
|
+
raise ArgumentError.new("No arguments supplied") unless arguments.any?
|
37
|
+
|
38
|
+
arguments.each do |argument|
|
39
|
+
if argument.strip =~ /^--/
|
40
|
+
# Can be a switch, starting with --
|
41
|
+
if argument.strip =~ /^--no-subtitles$/i
|
42
|
+
data[:skip_subtitles] = true
|
43
|
+
elsif argument.strip =~ /^--no-metadata$/i
|
44
|
+
data[:skip_metadata] = true
|
45
|
+
elsif argument.strip =~ /^--no-cleanup$/i
|
46
|
+
data[:skip_cleanup] = true
|
47
|
+
else
|
48
|
+
raise ArgumentError.new("Unknown switch: #{argument}")
|
49
|
+
end
|
50
|
+
else
|
51
|
+
# Or a file
|
52
|
+
raise ArgumentError.new("File not found: #{argument}") unless File.exists?(argument)
|
53
|
+
|
54
|
+
media = parse_filename(argument)
|
55
|
+
|
56
|
+
raise ArgumentError.new("Invalid media file: #{argument}") unless media
|
57
|
+
|
58
|
+
data[:media] << media
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
raise ArgumentError.new("No media file supplied") unless data[:media].any?
|
63
|
+
|
64
|
+
return data
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_filename(file)
|
68
|
+
return nil unless FFMPEG::Movie.new(file).valid?
|
69
|
+
|
70
|
+
# match
|
71
|
+
# [0] - Full string
|
72
|
+
# [1] - Show name
|
73
|
+
begin
|
74
|
+
e = AppleTvConverter::Media.new
|
75
|
+
# Extract name
|
76
|
+
match = File.dirname(file).match(/.*\/(.*?)(?:S(\d+))?$/i)
|
77
|
+
e.show = match[1].strip
|
78
|
+
|
79
|
+
# Extract season an media number
|
80
|
+
match = File.basename(file).match(/.*S?(\d+)[Ex](\d+).*/i)
|
81
|
+
if match
|
82
|
+
e.season = match[1].to_i if match[1]
|
83
|
+
e.number = match[2].to_i if match[2]
|
84
|
+
end
|
85
|
+
e.original_filename = file
|
86
|
+
|
87
|
+
return e
|
88
|
+
rescue => exc
|
89
|
+
puts "Couldn't parse filename, skipping: #{File.basename(file)}"
|
90
|
+
return nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -5,45 +5,35 @@ module AppleTvConverter
|
|
5
5
|
def is_windows? ; RUBY_PLATFORM =~/.*?mingw.*?/i ; end
|
6
6
|
def is_macosx? ; RUBY_PLATFORM =~/.*?darwin.*?/i ; end
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = {
|
10
|
+
:skip_subtitles => false,
|
11
|
+
:skip_metadata => false,
|
12
|
+
:skip_cleanup => false
|
13
|
+
}.merge(options)
|
14
|
+
|
9
15
|
@adapter = is_windows? ? AppleTvConverter::MediaConverterWindowsAdapter.new : AppleTvConverter::MediaConverterMacAdapter.new
|
10
16
|
end
|
11
17
|
|
12
18
|
def process_media(media)
|
13
|
-
AppleTvConverter.logger.debug "
|
19
|
+
AppleTvConverter.logger.debug " ** #{File.basename(media.original_filename)}"
|
14
20
|
AppleTvConverter.logger.debug "* Video codec: #{media.ffmpeg_data.video_codec}"
|
15
21
|
AppleTvConverter.logger.debug "* Audio codec: #{media.ffmpeg_data.audio_codec}"
|
16
22
|
AppleTvConverter.logger.debug "* Container: #{media.ffmpeg_data.container}" rescue nil
|
17
23
|
|
18
|
-
|
24
|
+
puts "*" * (4 + File.basename(media.original_filename).length)
|
25
|
+
puts "* #{File.basename(media.original_filename)} *"
|
26
|
+
puts "*" * (4 + File.basename(media.original_filename).length)
|
27
|
+
|
28
|
+
extract_subtitles(media) if media.is_mkv? && @options[:skip_subtitles] != true
|
19
29
|
|
20
30
|
if @adapter.transcode(media)
|
21
|
-
@adapter.add_subtitles
|
22
|
-
@adapter.tag
|
31
|
+
@adapter.add_subtitles(media) unless @options[:skip_subtitles] == true
|
32
|
+
@adapter.tag(media) unless @options[:skip_metadata] == true
|
23
33
|
|
24
|
-
# add_to_itunes media
|
25
|
-
@adapter.clean_up
|
34
|
+
# @adapter.add_to_itunes media
|
35
|
+
@adapter.clean_up(media) unless @options[:skip_cleanup] == true
|
26
36
|
end
|
27
37
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
# HELPERS
|
32
|
-
def process_all_medias(medias)
|
33
|
-
medias.each_with_index do |media, index|
|
34
|
-
puts '*' * 80
|
35
|
-
puts "* [#{(index + 1).to_s.rjust(medias.length.to_s.length, ' ')}/#{medias.length}] #{File.basename(media.original_filename)}"
|
36
|
-
|
37
|
-
process_media media
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def process_file(file)
|
42
|
-
puts '*' * 80
|
43
|
-
puts "* #{file}"
|
44
|
-
|
45
|
-
media = parse_filename(file)
|
46
|
-
process_media media
|
47
|
-
end
|
48
38
|
end
|
49
39
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module AppleTvConverter
|
2
2
|
class MediaConverterAdapter
|
3
3
|
def extract_subtitles(media)
|
4
|
-
printf "
|
4
|
+
printf "* Extracting subtitles"
|
5
5
|
media.mkv_data.extract_subtitles(File.dirname(media.original_filename)) do |progress|
|
6
|
-
printf "\r* Progress: #{progress}%%"
|
6
|
+
printf "\r * Progress: #{progress}%%"
|
7
7
|
end
|
8
|
-
puts "\r* Progress: [DONE]"
|
8
|
+
puts "\r * Progress: [DONE]"
|
9
9
|
end
|
10
10
|
|
11
11
|
def transcode(media)
|
12
12
|
if convert?(media)
|
13
|
-
puts "
|
13
|
+
puts "* Encoding"
|
14
14
|
|
15
15
|
options = {
|
16
16
|
:video_codec => convert_video?(media) ? 'mpeg4' : 'copy',
|
@@ -20,10 +20,13 @@ module AppleTvConverter
|
|
20
20
|
options[:custom] = "-qscale 1" if convert_video?(media)
|
21
21
|
|
22
22
|
transcoded = media.ffmpeg_data.transcode(media.converted_filename, options) do |progress|
|
23
|
-
printf
|
23
|
+
printf "\r" + (" " * 40)
|
24
|
+
printf %Q[\r* Encoding Progress: #{(progress * 100).round(2)}%%]
|
24
25
|
end
|
25
26
|
|
26
|
-
status transcoded.valid?
|
27
|
+
status = transcoded.valid?
|
28
|
+
|
29
|
+
printf "\r" + (" " * 40)
|
27
30
|
|
28
31
|
if status
|
29
32
|
puts "\r* Encoding: [DONE]#{' ' * 20}"
|
@@ -31,7 +34,7 @@ module AppleTvConverter
|
|
31
34
|
puts "\r* Encoding: [ERROR]#{' ' * 20}"
|
32
35
|
end
|
33
36
|
else
|
34
|
-
puts "
|
37
|
+
puts "* Encoding: [UNNECESSARY]"
|
35
38
|
status = true
|
36
39
|
end
|
37
40
|
|
@@ -51,10 +54,10 @@ module AppleTvConverter
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def clean_up(media)
|
54
|
-
printf "
|
57
|
+
printf "* Cleaning up"
|
55
58
|
begin
|
56
59
|
FileUtils.rm(media.original_filename) unless media.original_filename == media.converted_filename
|
57
|
-
FileUtils.rm_r list_files(
|
60
|
+
FileUtils.rm_r list_files(media.original_filename.gsub(File.extname(media.original_filename), '*.srt'))
|
58
61
|
puts " [DONE]"
|
59
62
|
rescue
|
60
63
|
puts " [ERROR]"
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module AppleTvConverter
|
2
2
|
class MediaConverterMacAdapter < MediaConverterAdapter
|
3
3
|
def add_subtitles(media)
|
4
|
-
puts "
|
4
|
+
puts "* Adding subtitles"
|
5
5
|
|
6
|
-
printf "* Removing any previous subtitles"
|
6
|
+
printf " * Removing any previous subtitles"
|
7
7
|
|
8
8
|
command_line = %Q[./SublerCLI -remove -dest "#{media.converted_filename}"]
|
9
9
|
|
@@ -31,13 +31,13 @@ module AppleTvConverter
|
|
31
31
|
AppleTvConverter.logger.debug "Executing:"
|
32
32
|
AppleTvConverter.logger.debug command_line
|
33
33
|
|
34
|
-
printf "* Adding #{language.name} subtitles"
|
34
|
+
printf " * Adding #{language.name} subtitles"
|
35
35
|
output = Open3.popen3(command_line) { |stdin, stdout, stderr, wait_thr| stdout.read }
|
36
36
|
|
37
37
|
puts output.strip.empty? ? " [DONE]" : " [ERROR]"
|
38
38
|
end
|
39
39
|
else
|
40
|
-
puts "* No new subtitles found"
|
40
|
+
puts " * No new subtitles found"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -53,7 +53,7 @@ module AppleTvConverter
|
|
53
53
|
AppleTvConverter.logger.debug "Executing:"
|
54
54
|
AppleTvConverter.logger.debug command_line
|
55
55
|
|
56
|
-
printf "
|
56
|
+
printf "* Tagging"
|
57
57
|
|
58
58
|
output = Open3.popen3(command_line) { |stdin, stdout, stderr, wait_thr| stdout.read }
|
59
59
|
|
@@ -63,7 +63,7 @@ module AppleTvConverter
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def add_to_itunes(media)
|
66
|
-
printf "
|
66
|
+
printf " * Adding to iTunes"
|
67
67
|
|
68
68
|
command_line = [
|
69
69
|
"ln -s",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apple-tv-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -95,10 +95,12 @@ description: Converts movies to a format playable on Apple TV. Supporting multip
|
|
95
95
|
subtitles.
|
96
96
|
email:
|
97
97
|
- pedro@bbde.org
|
98
|
-
executables:
|
98
|
+
executables:
|
99
|
+
- apple-tv-converter
|
99
100
|
extensions: []
|
100
101
|
extra_rdoc_files: []
|
101
102
|
files:
|
103
|
+
- lib/apple_tv_converter/command_line.rb
|
102
104
|
- lib/apple_tv_converter/io_patch.rb
|
103
105
|
- lib/apple_tv_converter/media.rb
|
104
106
|
- lib/apple_tv_converter/media_converter.rb
|
@@ -110,6 +112,7 @@ files:
|
|
110
112
|
- README.md
|
111
113
|
- LICENSE
|
112
114
|
- CHANGELOG
|
115
|
+
- bin/apple-tv-converter
|
113
116
|
homepage: http://github.com/gokuu/apple-tv-converter
|
114
117
|
licenses: []
|
115
118
|
post_install_message:
|