| http://cis.org:31500/
|
*/
-$config['cis_url'] = 'http://p2p-next-03.grid.pub.ro:31500/';
+$config['cis_url'] = 'http://localhost:31500/';
/*
|--------------------------------------------------------------------------
public function test()
{
- $this->load->model('videos_model');
-
- $videos = $this->videos_model->get_videos_summary(1, NULL, 0, 10,
- 'alphabetically', TRUE);
+ $this->load->helper('video');
- var_dump($videos);
+ var_dump(get_av_info('data/upload/test.ogv'));
}
/**
. $file_name . '" 2> /dev/null', 'r');
$tag = NULL;
+ $codec_type = NULL;
while ( ($r = fgets($h, 512)) !== FALSE)
{
if ($tag == 'FORMAT')
{
- // Duration
- if (preg_match('/^duration=/', $r))
- $duration = format_duration(floatval(_parse_value($r)));
-
// Size
if (preg_match('/^size=/', $r))
$size = intval(_parse_value ($r));
// DAR
if (preg_match('/^display_aspect_ratio=/', $r))
$dar = _parse_value($r);
+
+ // Codec Type
+ if (preg_match('/^codec_type=/', $r))
+ $codec_type = _parse_value($r);
+
+ // Duration
+ if (preg_match('/^duration=/', $r)
+ && strcmp($codec_type, 'video') == 0)
+ $duration = format_duration(floatval(_parse_value($r)));
}
}
}
// Eliminate formats with duplicate resolutions.
- if ($elim_dupl_res)
- {
- for ($i = 1; $i < count($transcode_configs); $i++)
- {
- if ($transcode_configs[$i]['v_resolution']
- === $transcode_configs[$i - 1]['v_resolution'])
- {
- unset($transcode_configs[$i - 1]);
- unset($db_formats[$i - 1]);
- $i--;
- }
- }
- }
+// if ($elim_dupl_res)
+// {
+// for ($i = 1; $i < count($transcode_configs); $i++)
+// {
+// if ($transcode_configs[$i]['v_resolution']
+// === $transcode_configs[$i - 1]['v_resolution'])
+// {
+// unset($transcode_configs[$i - 1]);
+// unset($db_formats[$i - 1]);
+// $i--;
+// }
+// }
+// }
return array('transcode_configs'=>$transcode_configs,
'db_formats'=>$db_formats);
# Create torrent file.
bt.create_torrent(transcode_config['output_file'])
- # The torrent file is created in the same directory with the
- # source file. Move it to the torrents directory.
- shutil.move(transcode_config['output_file'] + '.tstream', \
- config.TORRENTS_PATH)
-
output_file = transcode_config['output_file'] + '.tstream'
output_file = output_file[(output_file.rindex('/') + 1):]
+
+ # The torrent file is created in the same directory with the
+ # source file. Move it to the torrents directory.
+ #if not os.path.exists(
+ # os.path.join(output_file, config.TORRENTS_PATH)):
+ try:
+ shutil.move(transcode_config['output_file'] + '.tstream', \
+ config.TORRENTS_PATH)
+ except:
+ pass
# * SEED TORRENTS
Server.bit_torrent.start_torrent( \
import threading
from Queue import Queue
-from load_balancer.random_lb import RandomLoadBalancer
# Located in the parent directory; execute from that location or put it in PYTHONPATH
import logger
import config
# Create job threads.
lb_workers = []
for i in range(0, config.JOB_THREADS_COUNT):
- lb_worker = RandomLoadBalancer(i, Server.queue)
+ lb_worker = config.LOAD_BALANCER(i, Server.queue)
lb_worker.daemon = True
lb_worker.start()
lb_workers.append(lb_worker)
# CIS URLs
CIS_URLS = [ \
'http://p2p-next-01.grid.pub.ro:31500/', \
+ 'http://p2p-next-02.grid.pub.ro:31500/', \
'http://p2p-next-03.grid.pub.ro:31500/', \
'http://p2p-next-04.grid.pub.ro:31500/', \
'http://p2p-next-05.grid.pub.ro:31500/', \
'http://p2p-next-06.grid.pub.ro:31500/', \
'http://p2p-next-07.grid.pub.ro:31500/', \
'http://p2p-next-08.grid.pub.ro:31500/', \
+ 'http://p2p-next-09.grid.pub.ro:31500/', \
'http://p2p-next-10.grid.pub.ro:31500/' \
]
+import load_balancer.random_lb
+LOAD_BALANCER = load_balancer.random_lb.RandomLoadBalancer
+
import logger
LOG_LEVEL = logger.LOG_LEVEL_DEBUG
import threading
import urllib
+import config
import logger
class LoadBalancer(threading.Thread):
while True:
(request, data) = self.queue.get()
+ urls = config.CIS_URLS[:]
- cis = self.choose()
- logger.log_msg('Forwarding to %s' % cis, logger.LOG_LEVEL_DEBUG)
- urllib.urlopen(cis + request, data)
+ while len(urls) != 0:
+ cis = self.choose(urls)
+
+ # Request is forwarded to the chosen CIS.
+ try:
+ urllib.urlopen(cis + request, data)
+ except IOError:
+ logger.log_msg('Failed to forward request to %s' % cis, \
+ logger.LOG_LEVEL_ERROR)
+ continue
+
+ logger.log_msg('Request forwarded to %s' % cis, \
+ logger.LOG_LEVEL_INFO)
+ break
self.queue.task_done()
- def choose(self):
+ def choose(self, urls):
"""
Implement load balancing policy in this method for child classes which
- choses a CIS from config.CIS_URLS .
+ choses a CIS from urls parameter. The chosen URL should be deleted from
+ urls list.
"""
pass
\ No newline at end of file
import random
from base import LoadBalancer
-import config
class RandomLoadBalancer(LoadBalancer):
- def choose(self):
- return config.CIS_URLS[random.randint(0, len(config.CIS_URLS) - 1)]
\ No newline at end of file
+ def choose(self, urls):
+ index = random.randint(0, len(urls) - 1)
+ cis = urls[index]
+
+ del(urls[index])
+
+ return cis
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env python
+
+import web
+import sys
+
+urls = (
+ '/(.*)', 'Hello'
+)
+
+LOAD = sys.argv[2]
+print 'load is %s' % LOAD
+
+app = web.application(urls, globals())
+
+class Hello:
+ def GET(self, name):
+ if request == 'get_load':
+ resp = {"load": LOAD}
+ web.header('Content-Type', 'application/json')
+ return json.dumps(resp)
+
+ def POST(self, request):
+ print web.data()
+
+ return request
+
+if __name__ == "__main__":
+ app.run()
--- /dev/null
+<html>
+<head>
+ <title>403 Forbidden</title>
+</head>
+<body>
+
+<p>Directory access is forbidden.</p>
+
+</body>
+</html>
\ No newline at end of file