itunes_video 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/itunes_video.rb +130 -0
- metadata +46 -0
data/lib/itunes_video.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# utility methods
|
4
|
+
class Itunes_video
|
5
|
+
|
6
|
+
require 'pathname'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
attr_accessor :id, :kind, :name, :genre, :year, :description, :comment, :unplayed, :rating, :season_num, :episode_num, :show_name
|
10
|
+
|
11
|
+
def initialize(file)
|
12
|
+
if !(Pathname.new file).absolute?
|
13
|
+
if File.exist?(FileUtils.pwd + "/" + file)
|
14
|
+
file = FileUtils.pwd + "/" + file
|
15
|
+
else
|
16
|
+
raise "could not find video to import"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
import = `osascript -e 'tell application \"iTunes\" to add POSIX file \"#{file}\"'`
|
20
|
+
if import.split(" ")[3].nil?
|
21
|
+
raise "could not import video"
|
22
|
+
else
|
23
|
+
@id = import.split(" ")[3]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def kind=(kind)
|
28
|
+
kinds = ["tv show", "movie", "music video", "none"]
|
29
|
+
if !kinds.include?(kind)
|
30
|
+
raise "video kind must be one of: #{kinds}"
|
31
|
+
else
|
32
|
+
if `osascript -e 'tell application \"iTunes\" to set video kind of file track id #{@id} to #{kind}'`
|
33
|
+
@kind = kind
|
34
|
+
else
|
35
|
+
raise "could not set 'kind' for video"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# sets episode name for tv show or movie title for movie
|
41
|
+
def name=(name)
|
42
|
+
if `osascript -e 'tell application \"iTunes\" to set name of file track id #{@id} to \"#{name}\"'`
|
43
|
+
@name = name
|
44
|
+
else
|
45
|
+
raise "could not set 'name' for video"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def genre=(genre)
|
50
|
+
if `osascript -e 'tell application \"iTunes\" to set genre of file track id #{@id} to \"#{genre}\"'`
|
51
|
+
@genre = genre
|
52
|
+
else
|
53
|
+
raise "could not set 'genre' for video"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def year=(year)
|
58
|
+
year = year.to_s
|
59
|
+
if !(year =~ /^\d{4}$/)
|
60
|
+
raise "year must be a four-digit number"
|
61
|
+
elsif `osascript -e 'tell application \"iTunes\" to set year of file track id #{@id} to \"#{year}\"'`
|
62
|
+
@year = year
|
63
|
+
else
|
64
|
+
raise "could not set 'year' for video"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def description=(desc)
|
69
|
+
if `osascript -e 'tell application \"iTunes\" to set description of file track id #{@id} to \"#{desc}\"'`
|
70
|
+
@description = desc
|
71
|
+
else
|
72
|
+
raise "could not set 'description' for video"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def comment=(comment)
|
77
|
+
if `osascript -e 'tell application \"iTunes\" to set comment of file track id #{@id} to \"#{comment}\"'`
|
78
|
+
@comment = comment
|
79
|
+
else
|
80
|
+
raise "could not set 'comment' for video"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def unplayed=(unplayed)
|
85
|
+
if !["true", "false"].include? unplayed
|
86
|
+
raise TypeError, "unplayed must be 'true' or 'false'"
|
87
|
+
elsif `osascript -e 'tell application \"iTunes\" to set unplayed of file track id #{@id} to \"#{unplayed}\"'`
|
88
|
+
@unplayed = unplayed
|
89
|
+
else
|
90
|
+
raise "could not set 'unplayed' for video"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def rating=(rating)
|
95
|
+
rating_int = rating.to_i
|
96
|
+
if !rating_int.between?(0,100)
|
97
|
+
raise "rating must be between 0 and 100"
|
98
|
+
elsif `osascript -e 'tell application \"iTunes\" to set rating of file track id #{@id} to #{rating_int}'`
|
99
|
+
@rating = rating
|
100
|
+
else
|
101
|
+
raise "could not set 'rating' for video"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# tv show specific methods
|
106
|
+
def season_num=(season_num)
|
107
|
+
if `osascript -e 'tell application \"iTunes\" to set season number of file track id #{@id} to #{season_num.to_i}'`
|
108
|
+
@season_num = season_num
|
109
|
+
else
|
110
|
+
raise "could not set 'season number' for video"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def episode_num=(episode_num)
|
115
|
+
if `osascript -e 'tell application \"iTunes\" to set episode number of file track id #{@id} to \"#{episode_num.to_i}\"'`
|
116
|
+
@episode_num = episode_num
|
117
|
+
else
|
118
|
+
raise "could not set 'episode number' for video"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def show_name=(show_name)
|
123
|
+
if `osascript -e 'tell application \"iTunes\" to set show of file track id #{@id} to \"#{show_name}\"'`
|
124
|
+
@show_name = show_name
|
125
|
+
else
|
126
|
+
raise "could not set 'show name' for video"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itunes_video
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Richard Myers
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A gem to import and organize your video collection in iTunes. Mac OS
|
15
|
+
X only.
|
16
|
+
email: rick.myers@me.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/itunes_video.rb
|
22
|
+
homepage: https://github.com/movesmyers/itunes_video
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.24
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Import and organize videos in iTunes
|
46
|
+
test_files: []
|