Permalink
Browse files

added media finder and two new scripts

  • Loading branch information...
jacobwgillespie committed Mar 5, 2012
1 parent ac5f8e4 commit 78f3ed01baa0c0c29aca8de0e6a7aa7e030dda11
View
@@ -0,0 +1,5 @@
+#!/bin/bash
+for arg;do
+file=$(echo "$arg" | sed 's/\.\w*$/''/')
+mencoder "$arg" -ovc lavc -oac lavc -ffourcc DX50 -o "${file}.avi"
+done
View
@@ -0,0 +1,75 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'highline/import'
+require 'fileutils'
+
+EXTS = %w(avi mpeg xvid mp4 m4v mkv wmv mpg)
+
+renames = {}
+prefix = nil
+season = 1
+
+begin
+
+ files = []
+ EXTS.each do |ext|
+ new_files = Dir.glob("*.#{ext}").sort
+ new_files = new_files.sort
+ next if new_files.empty?
+ files += new_files
+ end
+
+ files.sort!
+
+ puts "Found #{files.size} files"
+
+ first_title = files.first.gsub(/\.[a-z]+$/, '')
+ prefix_match = first_title.match(/^[^0-9]+[a-z]/i)
+ prefix_guess = !prefix_match.nil? && prefix_match[0] != "" ? prefix_match[0] : prefix
+ prefix = ask("Prefix? ") { |q|
+ q.default = prefix_guess if prefix_guess
+ }
+
+ season_match = first_title.match(/[1-9]/)
+ season_guess = !season_match.nil? && season_match[0] != '0' ? season_match[0].to_i : season
+ season = ask("Season? ", Integer) { |q|
+ q.default = season_guess
+ q.in = 0..900
+ }
+
+ previous_number = 0
+
+ files.each do |file|
+ number_match = file.sub(season.to_s, '').match(/[1-9][0-9]*/)
+ number_guess = !number_match.nil? ? number_match[0].to_i : 0
+
+ number_guess = previous_number + 1
+
+ number = ask("Episode number for \"#{file}\"? (0 to skip) ", Integer) { |q|
+ q.default = number_guess
+ q.in = 0..900
+ }
+ next if number == 0
+ previous_number = number
+ title = "%s - S%02iE%02i" % [prefix, season, number]
+ ext = File.extname file
+ ext = ext[1..-1]
+ renames["#{title}.#{ext}"] = file
+ end
+
+
+ renames = renames.select { |to, from| to != from }.sort
+ abort "No files to rename found!" if renames.empty?
+
+ puts "About to rename:"
+ renames.each { |to, from| puts "#{to} (#{from})" }
+
+ exit unless agree "Really rename all files? "
+ renames.each { |to, from| FileUtils.mv(from, to) }
+
+rescue EOFError
+ abort "\n^D"
+rescue Interrupt
+ abort "\n^C"
+end
View
@@ -0,0 +1 @@
+config/*.yml
View
@@ -0,0 +1,7 @@
+source 'http://rubygems.org'
+
+gem 'xml-simple', :require => 'xmlsimple'
+gem 'roxml'
+gem 'i18n'
+gem 'auteur'
+gem 'settingslogic'
View
@@ -0,0 +1,46 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ addressable (2.2.6)
+ auteur (0.0.3)
+ json (>= 1.4.6)
+ rest-client (~> 1.6.3)
+ ruby-tmdb (~> 0.2.1)
+ rubytree (~> 0.8.1)
+ tvdb_party (~> 0.6.0)
+ deepopenstruct (0.1.2)
+ httparty (0.8.1)
+ multi_json
+ multi_xml
+ i18n (0.6.0)
+ json (1.6.1)
+ mime-types (1.16)
+ multi_json (1.0.3)
+ multi_xml (0.4.1)
+ nokogiri (1.5.0)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ roxml (3.1.6)
+ activesupport (>= 2.3.0)
+ nokogiri (>= 1.3.3)
+ ruby-tmdb (0.2.1)
+ addressable
+ deepopenstruct (>= 0.1.2)
+ json
+ rubytree (0.8.1)
+ settingslogic (2.0.8)
+ tvdb_party (0.6.2)
+ httparty (>= 0.6.1)
+ xml-simple (1.1.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ auteur
+ i18n
+ roxml
+ settingslogic
+ xml-simple
@@ -0,0 +1,14 @@
+defaults: &defaults
+ tvdb_key: secret
+ tmdb_key: secret
+ trakt_key: secret
+ nzbmatrix_key: secret
+
+development:
+ <<: *defaults
+
+test:
+ <<: *defaults
+
+production:
+ <<: *defaults
View
@@ -0,0 +1,28 @@
+require 'open-uri'
+
+class HashReader
+ def initialize(hash)
+ hash.each do |k,v|
+ self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
+ self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable
+ self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable
+ end
+ end
+end
+
+module TVRage
+
+ FEED_BASE = 'http://services.tvrage.com/feeds/'
+
+ class Show < HashReader
+ def self.search(name)
+ hash = XmlSimple.xml_in(open("#{FEED_BASE}search.php?show=#{URI.escape name}"))
+ return [] if hash == '0'
+ hash['show'].map { |show| TVRage::Show.new show }
+ end
+ end
+
+ class Episode < HashReader
+ end
+
+end
@@ -0,0 +1,145 @@
+require 'cgi'
+
+class NZBMatrix
+
+ EVERYTHING = '0'
+
+ MOVIES_ALL = 'movies-all'
+ MOVIES_DVD = '1'
+ MOVIES_DIVX_XVID = '2'
+ MOVIES_HD_X264 = '42'
+ MOVIES_HD_BLURAY = '50'
+ MOVIES_WMV_HD = '48'
+ MOVIES_SVCD_VCD = '3'
+ MOVIES_OTHER = '4'
+
+ TV_ALL = 'tv-all'
+ TV_DVD = '5'
+ TV_DIVX_XVID = '6'
+ TV_HD = '41'
+ TV_SPORT_ENT = '7'
+ TV_OTHER = '8'
+
+ DOCUMENTARIES_ALL = 'docu-all'
+ DOCUMENTARIES_STD = '9'
+ DOCUMENTARIES_HD = '53'
+
+ GAMES_ALL = 'games-all'
+ GAMES_PC = '10'
+ GAMES_PS2 = '11'
+ GAMES_PS3 = '43'
+ GAMES_PSP = '12'
+ GAMES_XBOX = '13'
+ GAMES_XBOX360 = '14'
+ GAMES_PS1 = '15'
+ GAMES_DREAMCAST = '16'
+ GAMES_WII = '44'
+ GAMES_WII_VC = '51'
+ GAMES_DS = '45'
+ GAMES_GAMECUBE = '46'
+ GAMES_OTHER = '17'
+
+ APPS_ALL = 'apps-all'
+ APPS_PC = '18'
+ APPS_MAC = '19'
+ APPS_PORTABLE = '51'
+ APPS_LINUX = '20'
+ APPS_OTHER = '21'
+
+ MUSIC_ALL = 'music-all'
+ MUSIC_MP3_ALBUMS = '22'
+ MUSIC_MP3_SINGLES = '47'
+ MUSIC_LOSSLESS = '23'
+
+ MUSIC_DVD = '24'
+ MUSIC_VIDEO = '25'
+ MUSIC_OTHER = '27'
+
+ ANIME_ALL = '28'
+
+ OTHER_ALL = 'other-all'
+ OTHER_AUDIO_BOOKS = '49'
+ OTHER_EMULATION = '33'
+ OTHER_PPC_PDA = '34'
+ OTHER_RADIO = '26'
+ OTHER_EBOOKS = '36'
+ OTHER_IMAGES = '37'
+ OTHER_MOBILE_PHONE = '38'
+ OTHER_EXTRA_PARS_FILLS = '39'
+ OTHER_OTHER = '40'
+
+
+ attr_accessor :user_name, :api_key, :max_results, :https
+
+ def initialize(str_user_name, str_api_key, use_https=:http)
+ @user_name = str_user_name
+ @api_key = str_api_key
+ @max_results = 5
+ @https = use_https == :https ? 'https' : 'http'
+ end
+
+ def search_print(str_category_id, str_search_terms)
+ search(str_category_id, str_search_terms).each do |res|
+ puts " NZB Id, Size : [#{res[:nzbid]}] #{(res[:size].to_f * 100.0 / 1024.0 / 1024.0) / 100} Mb"
+ puts " Usenet Group : #{res[:group]}"
+ puts " Name : #{res[:nzbname]}"
+ puts " Link : http://www.#{res[:link]}"
+ puts "NZBMatrix Date : #{res[:index_date]}"
+ puts " Usenet Date : #{res[:usenet_date]}"
+ puts " Category : #{res[:category]}"
+ puts " Hits : #{res[:hits]}"
+ puts " Comments : #{res[:comments]}"
+ puts " Has NFO? : #{res[:nfo]}"
+ puts
+ puts
+ end
+ end
+
+ def search(str_category_id, str_search_terms)
+ str_url = "#{@https}://nzbmatrix.com/api-nzb-search.php?search=#{CGI.escape(str_search_terms)}&catid=#{str_category_id}&num=#{@max_results}&username=#{@user_name}&apikey=#{@api_key}"
+ str = ""
+ open(str_url) do |i|
+ str = i.read
+ end
+ entries = str.split(/\n\|/m).map{ |i| CGI.unescapeHTML(i.gsub(/\n/, ' ').strip) }
+ entries = entries.map{ |i| i != '' ? i : nil }.compact
+ entries = entries.map{ |i| i.split(';').map{ |j| j.strip.split(':',2) }.map{ |k,l| [ k.strip.downcase.to_sym, l ] } }
+ entries = entries.map{ |i| Hash[*i.flatten] }
+ return entries
+ end
+
+ def details_print(str_nzb_id)
+ details(str_nzb_id).each{|a,b| puts sprintf("%20s : %s", a, b) }
+ end
+
+ def details(str_nzb_id)
+ str_url = "#{@https}://nzbmatrix.com/api-nzb-details.php?id=#{str_nzb_id}&username=#{@user_name}&apikey=#{@api_key}"
+ str = ""
+ open(str_url) do |i|
+ str = i.read
+ end
+ info = Hash[*CGI.unescapeHTML(str.gsub(/\n/m, ' ').strip).split(';').map{ |i| i.strip.split(':', 2) }.map{ |i| [ i[0].strip.downcase.to_sym, i[1] ] }.flatten]
+ info[:nzbfilename] = info[:nzbname].gsub(/[ ]+/, '_')+'.nzb'
+ return info
+ end
+
+ def download(str_nzb_id)
+ info = details(str_nzb_id)
+ str_url = "#{@https}://nzbmatrix.com/api-nzb-download.php?id=#{str_nzb_id}&username=#{@user_name}&apikey=#{@api_key}"
+ str = ""
+ str_file = info[:nzbfilename]
+ begin
+ File.open("/tmp/#{str_file}.gz", 'w') do |o|
+ open(str_url) do |i|
+ o.write i.read
+ end
+ end
+ system("gunzip", "/tmp/#{str_file}.gz")
+ system("mv", "/tmp/#{str_file}", ".")
+ return [ true, 'OK' ]
+ rescue Exception => e
+ return [ false, e ]
+ end
+ end
+
+end
@@ -0,0 +1,4 @@
+class Settings < Settingslogic
+ source "#{File.dirname(__FILE__) }/../config/settings.yml"
+ namespace 'defaults'
+end
Oops, something went wrong.

0 comments on commit 78f3ed0

Please sign in to comment.