cis: torrent files creation
authorCalin-Andrei Burloiu <calin.burloiu@gmail.com>
Tue, 6 Dec 2011 15:14:56 +0000 (17:14 +0200)
committerCalin-Andrei Burloiu <calin.burloiu@gmail.com>
Tue, 6 Dec 2011 15:14:56 +0000 (17:14 +0200)
cis/api/avhandling.py
cis/api/base.py
cis/api/file_transfer.py
cis/cisd.py
cis/config.py

index 8d04272..85cf908 100644 (file)
@@ -102,7 +102,6 @@ class FFmpegThumbExtractor(base.BaseThumbExtractor):
     """
 
     prog_bin = "ffmpeg"
-    info_prog_bin = "ffprobe"
 
     log_file = 'log/FFmpegThumbExtractor.log'
 
@@ -142,8 +141,17 @@ class FFmpegThumbExtractor(base.BaseThumbExtractor):
                     'FFmpeg created an empty file.')
 
     def get_video_duration(self):
-        args = self.info_prog_bin + ' -show_format "' \
-                + self.input_file + '"'
+        return FFmpegAVInfo.get_video_duration(self.input_file)
+
+
+class FFmpegAVInfo(base.BaseAVInfo):
+    
+    prog_bin = "ffprobe"
+
+    @staticmethod
+    def get_video_duration(input_file):
+        args = FFmpegAVInfo.prog_bin + ' -show_format "' \
+                + input_file + '"'
 
         # READ handler for process's output.
         p = subprocess.Popen(args, shell=True,
@@ -165,4 +173,3 @@ class FFmpegThumbExtractor(base.BaseThumbExtractor):
         if exit_code > 0:
             raise api_exceptions.ThumbExtractionException( \
                     'FFmpeg exited with code ' + str(exit_code) + '.')
-
index a57d96d..cff692f 100644 (file)
@@ -232,18 +232,15 @@ class BaseThumbExtractor:
 
         return n_thumbs_extracted
 
-    def get_video_duration(self):
-        """
-        Returns the number of seconds of a video (int/float).
-        """
-        pass
-
     def get_output_file_name(self, index):
         """ Returns the name required as output file name based on index. """
         output_file_name = self.dest_path + self.name \
                 + '_t' + ("%02d" % index) + '.jpg'
         return output_file_name
 
+    def get_video_duration(self):
+        pass
+
 
 class BaseFileTransferer:
     """
@@ -287,3 +284,12 @@ class BaseFileTransferer:
         Class's destructor calls this method.
         """
         pass
+
+
+class BaseAVInfo:
+    @staticmethod
+    def get_video_duration(input_file):
+        """
+        Returns the number of seconds of a video (int/float).
+        """
+        pass
index 5a6ff01..50c2fca 100644 (file)
@@ -70,4 +70,7 @@ class FTPFileTransferer(base.BaseFileTransferer):
 
     def close(self):
         if self.ftp is not None:
-            self.ftp.quit()
+            try:
+                self.ftp.quit()
+            except:
+                pass
index 84ea512..e1acefd 100755 (executable)
@@ -3,8 +3,28 @@
 import sys
 import config
 
+#
+# !! Imports required for create_torrent
+#
+from BaseLib.Core.API import *
+#
+#
+#
+
+def create_torrent(input_):
+    tdef = TorrentDef()
+    tdef.add_content(input_, config.AVINFO_CLASS.get_video_duration(input_))
+    tdef.set_tracker(config.BT_TRACKER)
+
+    tdef.set_piece_length(32768)
+
+    tdef.finalize()
+    tdef.save(input_ + ".tstream")
+
+    print 'READY!', config.BT_TRACKER, config.AVINFO_CLASS.get_video_duration(input_)
 
 if __name__ == '__main__':
+    pass
 #    transcoder = config.TRANSCODER_CLASS(sys.argv[1])
 #    transcoder.transcode('webm', "vorbis", "vp8", a_bitrate="128k", a_samplingrate=22050, a_channels=2, v_bitrate="256k", v_framerate=15, v_resolution="320x240", v_dar="4:3")
     
@@ -13,6 +33,9 @@ if __name__ == '__main__':
 #    #thumb_extractor.extract_random_thumb()
 #    print thumb_extractor.extract_summary_thumbs(5)
 
-    file_transfer = config.FILE_TRANSFERER_CLASS()
-    file_transfer.get(['vim_config.tar.gz'])
-    file_transfer.close()
+#    file_transfer = config.FILE_TRANSFERER_CLASS()
+#    file_transfer.get(['vim_config.tar.gz'])
+#    #file_transfer.put(['cisd.py'])
+#    file_transfer.close()
+
+    create_torrent(sys.argv[1])
index d71d4e3..e3b1cca 100644 (file)
@@ -4,14 +4,16 @@
 from api import avhandling
 from api import file_transfer
 
+# BitTorrent configurations.
+BT_TRACKER = "http://p2p-next-10.grid.pub.ro:6969/announce"
+
 # External programs API classes.
+AVINFO_CLASS = avhandling.FFmpegAVInfo
 TRANSCODER_CLASS = avhandling.FFmpegTranscoder
 THUMB_EXTRACTOR_CLASS = avhandling.FFmpegThumbExtractor
-BT_CLIENT_CLASS = None # TODO
 FILE_TRANSFERER_CLASS = file_transfer.FTPFileTransferer
 
 # External programs binary file. None means default.
 TRANSCODER_BIN = None
 THUMB_EXTRACTER_BIN = None
-BT_CLIENT_BIN = None
 FILE_TRANSFERER_BIN = None