Created
March 28, 2015 13:28
-
-
Save venj/59c7fc0621c9940032a6 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
#!/usr/bin/env ruby | |
require 'zlib' | |
require 'open-uri' | |
require 'sqlite3' | |
class Torrent | |
# hash, name, genre, link, torrent | |
attr_accessor :name, :magnet, :link, :genre, :torrent | |
def initialize(line) | |
begin | |
parts = line.split("|") | |
@name = parts[1].strip | |
@magnet = "magnet:?xt=urn:btih:#{parts[0].strip}" | |
@genre = parts[2].strip | |
@link = parts[3].strip | |
@torrent = parts[4].strip | |
rescue Exception => e | |
print "Skipped: " | |
puts line | |
end | |
end | |
end | |
def parse_image(row) | |
regex = /\s?(\w+-\d+)\s?/i | |
bango = nil | |
name = row[0] | |
name.scan(regex) do |s| | |
bango = s[0] | |
end | |
image_link = nil | |
if bango | |
link = "http://www.javlibrary.com/cn/vl_searchbyid.php?keyword=#{bango}" | |
content = open(link).read | |
iregex = /img id="video_jacket_img" src="([^"]+)"/ | |
content.scan(iregex) do |s| | |
image_link = s[0] | |
puts "<tr><td><img src='#{image_link}'></td></tr>" | |
puts "<tr><td>#{row[0]}</td></tr>" | |
puts "<tr><td><a href='#{row[1]}'>Magnet</a></td></tr>" | |
end | |
end | |
end | |
def main | |
begin | |
db = SQLite3::Database.new "data.db" | |
db.execute "CREATE TABLE IF NOT EXISTS Torrents(id INTEGER PRIMARY KEY AUTOINCREMENT, | |
name TEXT, magnet TEXT, link TEXT, genre TEXT, torrent TEXT)" | |
rescue SQLite3::Exception => e | |
puts "Exception occurred" | |
puts e | |
end | |
keyword = ARGV[0] | |
keyword ||= "JAV" | |
puts %Q[ | |
<!DOCTYPE html> | |
<html> | |
<head><title>Torrents</title> | |
</head> | |
<body>] | |
puts "<table>" | |
db.execute "SELECT name, magnet FROM Torrents WHERE NAME LIKE '%#{keyword}%'" do |row| | |
parse_image row | |
end | |
puts "</table>" | |
puts %Q[ | |
</body> | |
</html>] | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment