Created
April 2, 2013 00:15
-
-
Save AnimaWish/5288904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# good UI | |
# more sorting options | |
# detect downloads, give shows update prompt - make a daemon? how do i do that | |
# groups/genres? | |
# priority? | |
# import from rtf | |
# {Show => [[Seasons, Episodes], Complete?, Genre?, Notes]} | |
require "yaml" | |
yamllocation = "/Users/Caius/Documents/Notes/series.yaml" | |
class SeriesList | |
attr_accessor :file | |
def initialize(file) | |
@file = file | |
end | |
def addseries(title) | |
if title == '' | |
puts "Error: No title entered." | |
elsif @file.key?(title) == false | |
puts title | |
@file[title] = [[0,0], false, [], ''] | |
else | |
puts "Error: Series already exists in list." | |
end | |
end | |
def removeseries(title) | |
puts "Are you sure you want to remove _#{title}_? (Yes/No)" | |
print ">" | |
response = gets.chomp | |
if response == "Yes" | |
deletion = true | |
@file.delete(title) {|title| puts "Error: '#{title}' not found."; deletion = false} | |
puts "Series _#{title}_ was deleted." if deletion | |
end | |
end | |
def displayseries(solo, title, showgenres) | |
displaytitle = title | |
#titlevariable = 1 | |
unless solo #truncates display if title is too long | |
#titlevariable = -22 | |
if title.length > 18 #(-1 * titlevariable) | |
displaytitle = title[0..14] + '...' | |
end | |
end | |
if @file[title][1] #completion | |
completedisplay = 'x' | |
end | |
if @file[title][0][1] == 0 | |
episode = '' | |
else | |
episode = '.' + @file[title][0][1].to_s | |
end | |
if showgenres #sticks in genres if true | |
if @file[title][2].length > 0 | |
genres = "(" + @file[title][2].sort.join(', ') + ")" | |
end | |
else | |
genres = '' | |
end | |
printf "%#-18s - %2s%-3s[%1s] %s %s \n", displaytitle, @file[title][0][0], episode, completedisplay, genres, @file[title][3] | |
end | |
def list(argument) | |
puts "__Series List__" | |
if argument.include? 'g' #genre argument | |
showgenre = true | |
else | |
showgenre = false | |
end | |
if argument.include? 'e' #example argument | |
genreexample = '' | |
genreexample = '(genre) ' if showgenre | |
puts "Title - S#.E#[x] %sNotes" % genreexample | |
end | |
@file.sort_by {|title, seasonEpisode, complete, genres, notes| title.downcase}.each do |x| | |
if argument.include? "-x" #show/hid completed arguments | |
unless x[1][1] | |
displayseries(false, x[0], showgenre) | |
end | |
elsif argument.include? "+x" | |
if x[1][1] | |
displayseries(false, x[0], showgenre) | |
end | |
else | |
displayseries(false, x[0], showgenre) | |
end | |
end | |
end | |
def find(title) | |
found = @file.select{|key, value| key.downcase =~ /#{title.downcase}/} | |
solostatus = false | |
if found.count == 1 | |
solostatus = true | |
end | |
@findcountey = found.count | |
found.each do |x| | |
displayseries(solostatus, x[0], true) | |
@lasttitle = x[0] | |
end | |
end | |
def changeseries(title, season, episode, completion, genres, notes) | |
@file[title] = [[season.to_i, episode.to_i], completion, genres, notes] | |
end | |
def updateseries(title, editTitle) | |
find(title) | |
if @findcountey > 1 | |
puts "Error: Multiple matches found." | |
elsif @findcountey == 0 | |
puts "Error: No matches found." | |
elsif @findcountey == 1 | |
if editTitle | |
puts "Editing title of _#{@lasttitle}_ (! to cancel)" | |
print ">" | |
input = gets.chomp | |
if input == '!' | |
puts "Title edit for _#{@lasttitle}_ cancelled." | |
elsif input == '' | |
puts "Error: No title entered, title edit cancelled." | |
else | |
@file[input] = @file[@lasttitle] | |
@file.delete(@lasttitle) | |
puts "Title _#{@lasttitle}_ was changed to _#{input}_" | |
end | |
else | |
puts "Editing data for _#{@lasttitle}_, [S#].[E#][x/o][genre,genre]; notes (! to cancel)" | |
puts "ex: 2.0x[anime,drama]; Shinigami like apples." | |
print ">" | |
input = gets.chomp | |
inputarray = input.split(';') | |
season = inputarray[0].split('.')[0] | |
episode = inputarray[0].split('.')[1] | |
#GENRES | |
genres = "" | |
if inputarray[0] =~ /\[(.*)\]/ #finds genres, saves them to a variable, then deletes them | |
genres = $1.downcase.split(",") | |
p genres | |
inputarray[0].delete!($1) | |
end | |
#COMPLETION | |
if inputarray[0].include? 'x' #if there's an x, completion is true, and removes the x | |
completion = true | |
inputarray[0].delete!('x') | |
elsif inputarray[0].include? 'o' #if there's an o, completion is false, removes the o | |
completion = false | |
inputarray[0].delete!('o') | |
elsif @file[@lasttitle][1] #if there isn't a character but it was true before, it's true now | |
completion = true | |
else | |
completion = false | |
end | |
#SILLY CANCELLATION | |
if inputarray[0].include?('!') | |
puts "Edit cancelled."; cancellation = true | |
end | |
#NOTES | |
unless inputarray[1] == nil | |
notes = inputarray[1].strip #if there are notes, here they are | |
else | |
notes = @file[@lasttitle][3] #otherwise, use old notes | |
end | |
#SEASON, EPISODE, GENRES back compat | |
if season == "" #if season isn't given, use old season | |
season = @file[@lasttitle][0][0] | |
end | |
if episode == nil #if episode isn't given, use old episode | |
episode = @file[@lasttitle][0][1] | |
end | |
if genres == "" | |
genres = @file[@lasttitle][2] | |
end | |
changeseries(@lasttitle, season, episode, completion, genres, notes) | |
#@file[@lasttitle] = [[season.to_i, episode.to_i], completion, genres, notes] | |
puts "Data for _#{@lasttitle}_ was edited." unless cancellation | |
end | |
end | |
end | |
end | |
def help() | |
puts "__Available Commands__" | |
puts "ls(+x/-x,e,g) List all shows alphabetically (Show/hide completed series, show example, show genres)." | |
puts "+seriestitle Add a series to the list." | |
puts "--seriestitle Remove a series from the list. This cannot be undone." | |
puts "*seriestitle Update stored information for a series." | |
puts "=seriestitle Edit a series title." | |
puts "/seriestitle Search the series list." | |
puts "quit Exit program." | |
end | |
#Creates a new file if one isn't there - this works, but it doesn't read empty files correctly maybe | |
if File.exists?(yamllocation) | |
openedfile = YAML.load(File.open(yamllocation)) | |
else | |
puts "Error: File not found, creating new 'series.yaml' file at #{yamllocation}" | |
openedfile = SeriesList.new(File.new(yamllocation, "w").puts YAML::dump(SeriesList.new(Hash.new))) #this might have fixed it nope | |
end | |
serieslist = openedfile | |
puts serieslist.class | |
def import(list, txt) # this is incomplete | |
splitarray = Array.new | |
File.read(txt).split(/\n+/).each do |x| | |
splitarray << x.split(/\t+/) | |
end | |
splitarray.each do |x| | |
x[0] = x[0].split(' ').map {|y| y.capitalize}.join(' ') | |
end | |
p splitarray | |
end | |
puts "Television Series Sorter" | |
loop do | |
print ">" | |
input = gets.chomp | |
case input | |
when /^ls(.*)/ | |
serieslist.list($1.strip) | |
when /^\+(.*)/ | |
serieslist.addseries($1.strip) | |
when /^\-\-(.*)/ | |
serieslist.removeseries($1.strip) | |
when /^\*(.*)/ | |
serieslist.updateseries($1.strip, false) | |
when /^\=(.*)/ | |
serieslist.updateseries($1.strip, true) | |
when /^\/(.*)/ | |
serieslist.find($1.strip) | |
when 'help' | |
help() | |
when 'import' | |
import(serieslist, "/Users/Caius/Documents/Notes/Shows.txt") | |
when 'quit' | |
puts "Save Changes? (y/n)" | |
print ">" | |
input = gets.chomp | |
if input == "y" | |
File.open(yamllocation, "w").puts YAML::dump(serieslist) | |
break | |
elsif input == "n" | |
break | |
else | |
puts "Error: Input not understood." | |
end | |
else | |
puts "Error: Input not understood." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment