Class: Blitzcrank::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/blitzcrank/video.rb

Direct Known Subclasses

Movie, TVShow

Constant Summary collapse

TV_SHOW_REGEX =

Supports s01e01, 1x03

/(.*?)[\. ]s?(\d{1,2})[ex](\d{2})/i
MOVIE_REGEX =
/^(.*?).(\d{4}|dvdrip)/i

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Video

Returns a new instance of Video.



41
42
43
44
# File 'lib/blitzcrank/video.rb', line 41

def initialize(file_path)
  @file_path = file_path
  @file_name = Video.file_name file_path
end

Class Method Details

.file_name(file_path) ⇒ Object



18
19
20
# File 'lib/blitzcrank/video.rb', line 18

def self.file_name(file_path)
  file_path.split('/').last
end

.is_movie?(file_name) ⇒ Boolean

movie methods

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/blitzcrank/video.rb', line 28

def self.is_movie?(file_name)
  if Video.is_tv_show?(file_name)
    return false
  elsif MOVIE_REGEX.match(file_name).nil? == false
    movie_name = $1
    nice_movie_name = movie_name.gsub('.', ' ').downcase
    i = Imdb::Search.new(nice_movie_name)
    i.movies.size > 0
  else
    false
  end
end

.is_tv_show?(file_name) ⇒ Boolean

returns if this is a TV show or not

Returns:

  • (Boolean)


23
24
25
# File 'lib/blitzcrank/video.rb', line 23

def self.is_tv_show?(file_name)
  TV_SHOW_REGEX.match(file_name).nil? == false
end

.with_path(file_path) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/blitzcrank/video.rb', line 8

def self.with_path(file_path)
  file_name = Video.file_name(file_path)
  if Video.is_tv_show? file_name
    return TVShow.new file_path
  elsif Video.is_movie? file_name
    return Movie.new file_path
  end
  return Video.new file_path
end

Instance Method Details

#file_nameObject



50
51
52
# File 'lib/blitzcrank/video.rb', line 50

def file_name
  @file_name
end

#is_movie?Boolean

movie methods

Returns:

  • (Boolean)


75
76
77
# File 'lib/blitzcrank/video.rb', line 75

def is_movie?
  Video.is_movie?(@file_name)
end

#is_tv_show?Boolean

returns if this is a TV show or not

Returns:

  • (Boolean)


70
71
72
# File 'lib/blitzcrank/video.rb', line 70

def is_tv_show?
  Video.is_tv_show?(@file_name)
end

#nice_nameObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/blitzcrank/video.rb', line 54

def nice_name
  unless TV_SHOW_REGEX.match(@file_name).nil?
    showName = $1
    wordsInShowName = showName.gsub(/[\._]/, ' ').downcase.split(" ") # strip . and _
    wordsInShowName.each do |word|
      if wordsInShowName.index(word) == 0 || /^(in|a|the|and|on)$/i.match(word).nil?
        word.capitalize!
      end
    end
    wordsInShowName.join(" ").gsub(/\b(us|uk|\d{4})$/i, '(\1)') # adding parens around US/UK marked shows, or shows with years
  else
    @file_name
  end
end

#remote_pathObject



46
47
48
# File 'lib/blitzcrank/video.rb', line 46

def remote_path
  @file_path
end