Skip to content

Instantly share code, notes, and snippets.

@valachi
Created April 1, 2013 15:28
Show Gist options
  • Save valachi/5285572 to your computer and use it in GitHub Desktop.
Save valachi/5285572 to your computer and use it in GitHub Desktop.
@Video =
current: -> _V_('my_video') if $('video:visible').length
resource: -> $("[href=#{location.hash}]").data('href')
class @Episode
formats = [
/^(.+?)s(\d{1,2})e(\d{1,2})/i
/^(.+?)(\d{1,2})[x.](\d{1,2})/i
/^(.+?)Season (\d{1,2}) Episode (\d{1,2})/i
]
constructor: (file) ->
name = file.name
data = @parse name
if data
@show = $.trim data[1].replace(/[._\[\]-]/g, ' ').toLowerCase()
@season = parseInt data[2], 10
@number = parseInt data[3], 10
@showLetters = @show.replace(/\W/g, '')
isSame: (file) ->
anotherEpisode = new Episode file
anotherEpisode.showLetters == @showLetters and
anotherEpisode.season == @season and
anotherEpisode.number == @number
parse: (name) ->
for format in formats
result = name.match format
return result if result
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment