This file is indexed.

/usr/share/tdiary/contrib/plugin/nicovideo.rb is in tdiary-contrib 5.0.8-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#
# nicovideo.rb - tDiary plugin for Nico Nico Video
#
# Copyright (C) 2012 TADA Tadashi <t@tdtds.jp>
# You can modify and/or distribute it under GPL.
#
# usage:
#    Link to the movie and show thumbnail, description...:
#    <%= nicovideo 'sm99999999' %>
#
#    Link to the movie with original label:
#    <%= nicovideo 'sm99999999', 'movie title' %>
#
#    Link to the movie with original label and link:
#    <%= nicovideo 'sm99999999', 'movie title', 'http://example.com/video' %>
#
#    Show Inline player:
#    <%= nicovideo_player 'sm99999999' %>
#
#    Show Inline player with size:
#    <%= nicovideo_player 'sm99999999', [400,300] %>
#
require 'net/http'
require 'timeout'

enable_js('nicovideo.js') unless base_url =~ /\Ahttps:/

def nicovideo_call_api( video_id )
	uri = "http://ext.nicovideo.jp/api/getthumbinfo/#{video_id}"
	proxy = @conf['proxy']
	proxy = 'http://' + proxy if proxy
	xml = Timeout.timeout( feed? ? 10 : 2 ) {
		px_host, px_port = (@conf['proxy'] || '').split( /:/ )
		px_port = 80 if px_host and !px_port
		Net::HTTP::Proxy( px_host, px_port ).get_response( URI::parse( uri ) ).body
	}
	status = xml.scan(%r|<nicovideo_thumb_response\s*status="(.*)">|).flatten.first
	if status == 'ok' then
		raw_api = xml.scan(%r|<thumb>(.*)</thumb>|m).flatten.first.scan(%r|<(.*?)>(.*)</.*?>|)
		api = {}
		raw_api.each do |key, value|
			api[key] = @conf.to_native( value )
		end
		api
	else
		raise ::Errno::ENOENT::new
	end
end

def nicovideo_inline( video_id, elem, label = nil, link = nil )
	i = {}
	i[:id] = video_id
	i[:url] = link || elem['watch_url']
	i[:thumb] = elem['thumbnail_url']
	i[:title] = label || elem['title']
	i[:desc] = elem['description']
	i[:comment] = elem['last_res_body']
	i[:date] = elem['first_retrieve']
	i[:length] = elem['length']
	i[:view] = elem['view_counter']
	i[:comment_num] = elem['comment_num']
	i[:mylist] = elem['mylist_counter']

	if feed? then
		result = nicovideo_feed( i )
	else
		result = nicovideo_html( i )
	end
	result.gsub( /^\t+/, '' )
end

def nicovideo_iframe( video_id )
	%Q|<iframe src="http://www.nicovideo.jp/thumb/#{video_id}" scrolling="no" style="border:1px solid #CCC;" frameborder="0"><a href="http://www.nicovideo.jp/watch/#{video_id}">#{label || 'link for nicovideo'}</a></iframe>\n|
end

def nicovideo_player(video_id, size = [640,360])
	if feed?
		nicovideo(video_id)
	else
		q = size ? "?w=#{h size[0]}&amp;h=#{h size[1]}" : ''
		%Q|<script type="application/javascript" src="https://embed.nicovideo.jp/watch/#{video_id}/script#{q}"></script>|
	end
end

def nicovideo( video_id, label = nil, link = nil )
	begin
		r = ''
		r << %Q|<div id="thumbnail-#{video_id}">|
		api = nicovideo_call_api( video_id )
		thumb = @conf.to_native( nicovideo_inline( video_id, api, label, link ), 'UTF-8' )
		r << thumb
		r << '</div>'
		if feed?
			r.gsub!( /<a(?:[ \t\n\r][^>]*)?>/, '' )
			r.gsub!( %r{</a[ \t\n\r]*>}, '' )
		else
			r << %Q|<div id="player-#{video_id}" style="display:none;background-color:#000;margin-left:2em;padding-bottom:4px;">|
			r << %Q|<a name="player-#{video_id}">|
			r << nicovideo_player(video_id, [640,360])
			r << %Q|</a>|
			r << %Q|<div class="nicovideo-player-close" style="margin:4px;padding:8px;">|
			r << %Q|<a href="#" onclick="return nicovideoThumbnail( '#{video_id}' )" style="background-color:black; color:white; margin:2px; padding:8px; border-color:white; border-radius:6px; border-width:2px; border-style:solid; text-decoration:none;">â–²CLOSE PLAYER</a>|
			r << %Q|&nbsp;<a href="#{api['watch_url']}" style="background-color:black; color:white; margin:2px; padding:8px; border-color:white; border-radius:6px; border-width:2px; border-style:solid; text-decoration:none;">SHOW ORIGINAL&gt;</a>|
			r << %Q|</div>|
			r << %Q|</div>|
		end
		r
	rescue ::Errno::ENOENT
		"<strong>Sorry, #{video_id} was deleted.</strong>"
	rescue Timeout::Error, NoMethodError, SecurityError, StandardError
		puts $!
		$@.each{|l| puts l}
		nicovideo_iframe( video_id )
	end
end