ã½ã¼ã¹ã³ã¼ãå ¬é
ä»å¹´åãã«ãªãªã¼ã¹ãã¾ããRetroTubeã§ãããã½ã¼ã¹ã³ã¼ãå
¬éããã¨å®£è¨ãã¤ã¤ããå粧ç´ãããä½è£ãåããªãã¦ããã¾ã§ãºã«ãºã«ã¨ãã¦ãã¾ãã¾ããã
æ°ãä»ãã°ããï¼æâ¦ããã§ã¯ãããã¨ãããã¨ã§ãä¸å¿µçºèµ·ãã¦ãªãã¨ãçæ§ã®ãç®ã«è§¦ãã¦ãæ¥ãããããªãç¨åº¦ã«ã¾ã§æ´å½¢ãããã¨ãã§ãã¾ããã
ã§ãã®ã§ãæ¬æ¥ããæ°æ¥éã«æ¸¡ã£ã¦å
¬éãã¦ããããã¨æãã¾ããGPLã§å
¬éãã¾ãã
- RetroTubeã®ã·ã¹ãã ã¯ããããé¨åã¨ãªã³ã©ã¤ã³é¨åã®äºã¤ã«å¤§ããåããã¦ããã®ã§ãã¾ãã¯ãããé¨åããæ²è¼ãã¾ãã
- ãªã¹ãï¼ãï¼ã¯ãããããé³æ¥½ã»ã¢ãã¡ã»é¦ç»ã»æ´ç»ã®åã«ãã´ãªã«ã¤ãã¦ãYouTubeããä¸æ¬æ¤ç´¢ãã¦çµæãåºåããããã°ã©ã ã§ãã
- ãªã¹ãï¼ã¯ãä¸è¨æ¤ç´¢çµæããæ°çæ å ±ãåºåãããã®ã§ãã
ãã¨ãããããã¯è¶
éè¦ãªãç¥ããã«ãªã£ã¦ãã¾ãã®ã§ãããæ¥çµã½ããã¦ã¨ã¢ï¼æå·ï¼6/23çºå£²ï¼ãããçæéä¸é£è¼ã¨ããå½¢ã§ãRetroTubeéçºè¨ããå·çããã¦ããã ããã¨ã«ãªã£ã¦ãã¾ãã
ï¼åçã¯ï¼æå·ã®äºåã§ããCOBOLããã°ã©ãã«ããRubyããã°ã©ãã³ã°ææ¦è¨ãã¨ããã¾ãããããå®ã¯ãç§ã®ãã¨ã§ããï¼
åã«ã½ã¼ã¹ã³ã¼ãã®è§£èª¬ã«çã¾ãããéçºã®ãã£ããã¨ãªã£ãåºæ¥äºãããéçºä¸ã«èãã¦ããäºãå
¬éå¾ã®ä¸éããã®åå¿ãªã©ãæ§ã
ãªè§åº¦ãã楽ããã§ããã ããå
容ã«ãªã£ã¦ãã¾ãã®ã§ãæ¯é大å¢ã®æ¹ã«èªãã§ããã ãããã¨æã£ã¦ãã¾ãã
ãããããé¡ããã¾ãã
ããã§ã¯ä»¥ä¸ãããã½ã¼ã¹ã³ã¼ãåãæµãã¦ããã¾ãã
ããªã¹ãï¼ãsearch_music.rb
##################################### #ãRetroTubeãä¸æ¬æ¤ç´¢ããã°ã©ã ï¼é¦æ¥½ï¼ ##################################### require "youtube" require "kconv" require "fastercsv" #YouTubeAPIã¢ã¯ã»ã¹ç¨ã©ã¤ãã©ãªåæå youtube = YouTube.new '(DeveloperID)' #ååæ¤ç´¢æã®çµæãéé¿ï¼newdataãã©ã«ãããolddataãã©ã«ãã¸ï¼ File.rename("newdata/music.csv","olddata/music.old.csv") #ããããæ¤ç´¢å¦ç musicout = open("newdata/music.csv",'w') beforeartist = nil FasterCSV.foreach("source/source_music.csv") { |line| #ã¢ã¼ãã£ã¹ãåããã¼ãã¬ã¤ã¯ããæãã¿ã°æ¤ç´¢ï¼æ大ï¼ï¼ï¼ä»¶ï¼ãè¡ãã$getdataã«æ ¼ç´ãã if line[3] != beforeartist $getdata = Array.new i = 1 loop { begin videos = youtube.videos_by_tag(Kconv.toutf8(line[3]),i,100) if videos == [] break end videos.each { |video| targettitle = Kconv.tosjis(video.title) convtitle = targettitle.gsub(',',' ') $getdata.push([convtitle,video.id,video.thumbnail_url,video.url]) } rescue break end i += 1 if i > 3 break end } end #ã¢ã¼ãã£ã¹ãåã§ã¿ã°æ¤ç´¢ããçµæï¼$getdataã«æ ¼ç´ããã¦ããï¼ããã #ããã«æ²ã¿ã¤ãã«ãå«ããã®ãæ¤ç´¢ããçµæãåºå $getdata.each { |getline| compare = Kconv.toutf8(line[4]) pattern = Regexp.new(compare.upcase) compare2 = Kconv.toutf8(getline[0]) if pattern =~ compare2.upcase musicout.puts line[0] + ',' + line[1] + ',' + line[2] + ',' + getline[1] + ',' + getline[2] + ',' + getline[3] break end } beforeartist = line[3] } musicout.close
ããªã¹ãï¼ãsearch_anime.rb
##################################### #ãRetroTubeãä¸æ¬æ¤ç´¢ããã°ã©ã ï¼ã¢ãã¡ï¼ ##################################### require "kconv" require "net/http" require "fastercsv" #ååæ¤ç´¢æã®çµæãéé¿ï¼newdataãã©ã«ãããolddataãã©ã«ãã¸ï¼ File.rename("newdata/anime.csv","olddata/anime.old.csv") #ããããæ¤ç´¢å¦ç address = "www.youtube.com" path = "/api2_rest?method=youtube.videos.list_by_category_and_tag&dev_id=6BQYABg1UFM&category_id=1&page=1&per_page=20&tag=" newdataout = open("newdata/anime.csv",'w') FasterCSV.foreach("source/source_anime.csv") { |line| p line begin searchword_utf8 = line[4].kconv(Kconv::UTF8, Kconv::SJIS) searchpath = path + searchword_utf8 body = Net::HTTP.get( address , searchpath ) re = %r|<id>(.*?)</id>|u searchresult_id = body.scan(re) re = %r|<title>(.*?)</title>|u searchresult_title = body.scan(re) re = %r|<thumbnail_url>(.*?)</thumbnail_url>|u searchresult_thumbnail_url = body.scan(re) re = %r|<url>(.*?)</url>|u searchresult_url = body.scan(re) opflag = 0 edflag = 0 re_op = %r|op|u re_ed = %r|ed|u re_end = %r|end|u searchresult_id.zip(searchresult_title,searchresult_thumbnail_url,searchresult_url){|zip_id,zip_title,zip_thumbnail_url,zip_url| if opflag == 0 if zip_title[0].downcase =~ re_op newdataout.print line[0] + "," + line[1] + "," + line[2] + "," + zip_id[0] + "," + zip_thumbnail_url[0] + "," + zip_url[0] + ",OP" + "\n" opflag = 1 if zip_title[0].downcase =~ re_ed || zip_title[0].downcase =~ re_end edflag = 1 end end end if edflag == 0 if zip_title[0].downcase =~ re_ed || zip_title[0].downcase =~ re_end newdataout.print line[0] + "," + line[1] + "," + line[2] + "," + zip_id[0] + "," + zip_thumbnail_url[0] + "," + zip_url[0] + ",ED" + "\n" edflag = 1 end end if opflag == 1 && edflag == 1 break end } if opflag == 0 && edflag == 0 if searchresult_id != [] newdataout.print line[0] + "," + line[1] + "," + line[2] + "," + searchresult_id[0][0] + "," + searchresult_thumbnail_url[0][0] + "," + searchresult_url[0][0] + ",NA" + "\n" end end rescue p 'timeout err' end } newdataout.close
ããªã¹ãï¼ãsearch_movie_j.rb
##################################### #ãRetroTubeãä¸æ¬æ¤ç´¢ããã°ã©ã ï¼é¦ç»ï¼ ##################################### require "kconv" require "net/http" require "fastercsv" #ååæ¤ç´¢æã®çµæãéé¿ï¼newdataãã©ã«ãããolddataãã©ã«ãã¸ï¼ File.rename("newdata/movie_j.csv","olddata/movie_j.old.csv") #ããããæ¤ç´¢å¦ç address = "www.youtube.com" path = "/api2_rest?method=youtube.videos.list_by_category_and_tag&dev_id=6BQYABg1UFM&category_id=1&page=1&per_page=1&tag=" newdataout = open("newdata/movie_j.csv",'w') FasterCSV.foreach("source/source_movie.csv") { |line| begin re_japan = %r|æ¥æ¬|s if re_japan =~ line[6] p line[0] + " " + line[1] + " " + line[5] if line[5].split(//s).length > 10 searchword = line[5] else searchword = line[5] + " " + line[4] end searchword_utf8 = searchword.kconv(Kconv::UTF8, Kconv::SJIS) searchpath = path + searchword_utf8 convpath = searchpath.gsub(' ','%20') body = Net::HTTP.get( address , convpath ) re = %r|<id>(.*?)</id>|u result_id = body.scan(re) re = %r|<thumbnail_url>(.*?)</thumbnail_url>|u result_thumbnail_url = body.scan(re) re = %r|<url>(.*?)</url>|u result_url = body.scan(re) result_id.zip(result_thumbnail_url,result_url) { |zip_id,zip_thumbnail_url,zip_url| newdataout.print line[0] + ',"' + line[2].gsub('"','""') + '","' + line[3].gsub('"','""') + '","' + zip_id[0] + '","' + zip_thumbnail_url[0] + '","' + zip_url[0] + '"' + "\n" } end rescue p 'err' end } newdataout.close
ããªã¹ãï¼ãsearch_movie_a.rb
##################################### #ãRetroTubeãä¸æ¬æ¤ç´¢ããã°ã©ã ï¼æ´ç»ï¼ ##################################### require "kconv" require "net/http" require "fastercsv" #ååæ¤ç´¢æã®çµæãéé¿ï¼newdataãã©ã«ãããolddataãã©ã«ãã¸ï¼ File.rename("newdata/movie_a.csv","olddata/movie_a.old.csv") #ããããæ¤ç´¢å¦ç address = "www.youtube.com" path = "/api2_rest?method=youtube.videos.list_by_category_and_tag&dev_id=6BQYABg1UFM&category_id=1&page=1&per_page=1&tag=" newdataout = open("newdata/movie_a.csv",'w') FasterCSV.foreach("source/source_movie.csv") { |line| begin re_japan = %r|æ¥æ¬|s if re_japan =~ line[6] else p line[0] + " " + line[1] + " " + line[5] searchword = line[5] + " " + line[4] searchword_utf8 = searchword.kconv(Kconv::UTF8, Kconv::SJIS) searchpath = path + searchword_utf8 convpath = searchpath.gsub(' ','%20') body = Net::HTTP.get( address , convpath ) re = %r|<id>(.*?)</id>|u result_id = body.scan(re) re = %r|<thumbnail_url>(.*?)</thumbnail_url>|u result_thumbnail_url = body.scan(re) re = %r|<url>(.*?)</url>|u result_url = body.scan(re) result_id.zip(result_thumbnail_url,result_url) { |zip_id,zip_thumbnail_url,zip_url| newdataout.print line[0] + ',"' + line[2].gsub('"','""') + '","' + line[3].gsub('"','""') + '","' + zip_id[0] + '","' + zip_thumbnail_url[0] + '","' + zip_url[0] + '"' + "\n" } end rescue p 'err' end } newdataout.close
ããªã¹ãï¼ãcompare.rb
##################################### #ãRetroTubeãæ°çæ å ±åºåããã°ã©ã ##################################### require "kconv" require "fastercsv" #ååæ¤ç´¢æã®çµæãéé¿ï¼newdataãã©ã«ãããolddataãã©ã«ãã¸ï¼ File.rename("newdata/compare.csv","olddata/compare.old.csv") File.rename("newdata/rss.rdf","olddata/rss.old.rdf") #ååæ¤ç´¢çµæã¨ä»åæ¤ç´¢çµæãæ¯è¼ããå·®åãæ°çæ å ±ã¨ãã¦åºåï¼é¦æ¥½ï¼ compareout = open("newdata/compare.csv",'w') $olddata = Array.new FasterCSV.foreach("olddata/music.old.csv") { |line| $olddata.push(line) } FasterCSV.foreach("newdata/music.csv") { |line| $hitsw = 0 $olddata.each { |oldline| if oldline[1] == line[1] && oldline[2] == line[2] $hitsw = 1 break end } if $hitsw == 0 compareout.puts line[0] + ',' + line[1] + ',' + line[2] + ',' + line[3] + ',' + line[4] + ',' + line[5] + ',music' end } #ååæ¤ç´¢çµæã¨ä»åæ¤ç´¢çµæãæ¯è¼ããå·®åãæ°çæ å ±ã¨ãã¦åºåï¼ã¢ãã¡ï¼ $olddata = Array.new FasterCSV.foreach("olddata/anime.old.csv") { |line| $olddata.push(line) } FasterCSV.foreach("newdata/anime.csv") { |line| $hitsw = 0 $olddata.each { |oldline| if oldline[1] == line[1] && oldline[2] == line[2] && oldline[6] == line[6] $hitsw = 1 break end } if $hitsw == 0 if line[6] == "NA" compareout.puts line[0] + ',' + line[1] + ',' + line[2] + ',' + line[3] + ',' + line[4] + ',' + line[5] + ',anime' else compareout.puts line[0] + ',' + line[1] + ',' + line[2] + ' ' + line[6] + ',' + line[3] + ',' + line[4] + ',' + line[5] + ',anime' end end } #ååæ¤ç´¢çµæã¨ä»åæ¤ç´¢çµæãæ¯è¼ããå·®åãæ°çæ å ±ã¨ãã¦åºåï¼é¦ç»ï¼ $olddata = Array.new FasterCSV.foreach("olddata/movie_j.old.csv") { |line| $olddata.push(line) } FasterCSV.foreach("newdata/movie_j.csv") { |line| $hitsw = 0 $olddata.each { |oldline| if oldline[1] == line[1] && oldline[2] == line[2] $hitsw = 1 break end } if $hitsw == 0 compareout.puts line[0] + ',' + line[1] + ',' + line[2] + ',' + line[3] + ',' + line[4] + ',' + line[5] + ',movie_j' end } #ååæ¤ç´¢çµæã¨ä»åæ¤ç´¢çµæãæ¯è¼ããå·®åãæ°çæ å ±ã¨ãã¦åºåï¼æ´ç»ï¼ $olddata = Array.new FasterCSV.foreach("olddata/movie_a.old.csv") { |line| $olddata.push(line) } FasterCSV.foreach("newdata/movie_a.csv") { |line| $hitsw = 0 $olddata.each { |oldline| if oldline[1] == line[1] && oldline[2] == line[2] $hitsw = 1 break end } if $hitsw == 0 compareout.puts line[0] + ',' + line[1] + ',' + line[2] + ',' + line[3] + ',' + line[4] + ',' + line[5] + ',movie_a' end } compareout.close #æ°çæ å ±(compare.csv)ããRSSåºå rssout = open("newdata/rss.rdf",'w') rssout.puts '<?xml version="1.0" encoding="utf-8" ?> <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="ja"> <channel rdf:about="http://www.retro-tube.com/rss.rdf"> <title>RetroTube</title> <link>http://www.retro-tube.com/</link> <description>RetroTube</description> <items> <rdf:Seq>' FasterCSV.foreach("newdata/compare.csv") { |rssline| rssout.puts ' <rdf:li rdf:resource="http://www.retro-tube.com/detail.cgi?movieid=' + Kconv.toutf8(rssline[3]) + '&category=' + rssline[6] + '"/>' } rssout.puts ' </rdf:Seq> </items> </channel>' FasterCSV.foreach("newdata/compare.csv") { |rssline| rssout.puts ' <item rdf:about="http://www.retro-tube.com/detail.cgi?movieid=' + Kconv.toutf8(rssline[3]) + '&category=' + rssline[6] + '">' case rssline[6] when "music" categoryname = Kconv.toutf8('é¦æ¥½') when "anime" categoryname = Kconv.toutf8('ã¢ãã¡') when "movie_j" categoryname = Kconv.toutf8('é¦ç»') when "movie_a" categoryname = Kconv.toutf8('æ´ç»') end rssout.puts ' <title>[' + categoryname + '] ' + Kconv.toutf8(rssline[2].gsub('&','&')) + ' - ' + Kconv.toutf8(rssline[1].gsub('&','&')) + ' (' + rssline[0] +')</title>' rssout.puts ' <link>http://www.retro-tube.com/detail.cgi?movieid=' + Kconv.toutf8(rssline[3]) + '&category=' + rssline[6] + '</link>' rssout.puts ' </item>' } rssout.print '</rdf:RDF>' rssout.close