From: gn64_jp Date: Fri, 12 Apr 2013 00:51:35 +0000 (+0900) Subject: stop using trunk or dist directory in rec10 project. X-Git-Url: http://git.osdn.net/view?p=rec10%2Frec10-git.git;a=commitdiff_plain;h=0d75d6d668b483567fa7cf86c3107ee41d06e831 stop using trunk or dist directory in rec10 project. --- diff --git a/Makefile.base b/Makefile.base new file mode 100755 index 0000000..32fd5eb --- /dev/null +++ b/Makefile.base @@ -0,0 +1,21 @@ +MAJOR = 0 +MINOR = 9 +REVISION = 10 +VER = $(MAJOR).$(MINOR).$(REVISION) + + +all: + cd tstools;make all + cd rectool;Makefile.PL + cd tunerec;make all +clean: + cd tstools;make clean +install: + cd rec10;make install + cd tstools;make install + cd tunerec;make install +uninstall: + cd tstools;make uninstall + cd rec10;make uninstall + cd tunerec;make uninstall + diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..028100b --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash +SELF_DIR=`dirname $0` +cd ${SELF_DIR} +cd rec10 +bash install.sh +cd ../ +mv Makefile.base Makefile diff --git a/jTsSplitter/jtssplitter/Chlist.java b/jTsSplitter/jtssplitter/Chlist.java new file mode 100644 index 0000000..14fb612 --- /dev/null +++ b/jTsSplitter/jtssplitter/Chlist.java @@ -0,0 +1,43 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2012 Yukikaze + */ + +package jtssplitter; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author yukikaze + */ +public class Chlist { + public void writeCHList(String tspath,String listpath,int min,int max){ + FileWriter fw = null; + try { + Tsfile tsf = new Tsfile(); + Integer[] programnum = tsf.getProgramNum_byte(tspath); + String str = ""; + for (int i = 0; i < programnum.length; i++) { + if (!(min >0 && min>programnum[i])){ + if (!(max >0 && max [Option ch number]"); + System.out.println("Option ch number is used in CS splitting.\n"); + for (int i = 0; i < args.length; i++) { + System.out.println(((Integer)i).toString()+":"+args[i]); + } + if (args.length > 1) { + if (args[0].trim().toUpperCase().equals("-ch".toUpperCase())){ + Chlist chl=new Chlist(); + chl.writeCHList(args[1], args[2],-1,-1); + System.exit(0); + }else if (args[0].trim().toUpperCase().equals("-bs".toUpperCase())){ + Chlist chl=new Chlist(); + chl.writeCHList(args[1], args[2],-1,290); + System.exit(0); + }else if (args[0].trim().toUpperCase().equals("-cs".toUpperCase())){ + Chlist chl=new Chlist(); + chl.writeCHList(args[1], args[2],-1,-1); + System.exit(0); + } + + inf = args[0]; + outf = args[1]; + if (args.length > 2) { + ch = Integer.parseInt(args[2].trim(), 10); + } + } + //inf = ""; + //outf = ""; + Tsfile t1 = new Tsfile(); + File f=new File(inf); + if (f.length()>1000*1000){ + t1.splitTS_byte(inf, outf, ch); + } + System.exit(0); + } +} diff --git a/jTsSplitter/jtssplitter/Mpeg2TSPacket.java b/jTsSplitter/jtssplitter/Mpeg2TSPacket.java new file mode 100644 index 0000000..0142cc6 --- /dev/null +++ b/jTsSplitter/jtssplitter/Mpeg2TSPacket.java @@ -0,0 +1,666 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2012 Yukikaze + */ +package jtssplitter; + +import java.util.ArrayList; +import java.util.Arrays; +import jtssplitter.data.PATData; +import jtssplitter.data.PMTData; +import jtssplitter.data.Descriptor; +import jtssplitter.data.EITData; +import java.io.ByteArrayOutputStream; + +/** + * + * @author gn64_jp + */ +public class Mpeg2TSPacket { + //TSのヘッダーを格納する + + public String header; + public String payload; + public String adaptation; + public byte[] header_byte; + public byte[] payload_byte; + public byte[] adaptation_byte; + public byte[] bPAT_payload = null; + //private ArrayList date=new ArrayList(); + //date.add(new TsDate("Starter")) + public int type;// + private int starter;//0-7 + private int transporterror;//本TSパケットの誤りを示す 1bit 8 + private int payloadstart;//セクションの先頭バイトが入っているかどうか1bit 9 + private int transport_priority;//1bit 10 + private int PID = -1;//tsパケットの種類 13bit 11-23 + private int transport_scrambled;//2bit 00is " not scrambled" 24-25 + private int adaptation_field;//2bit 26-27 01:adaptation fieldなしでおk 10は絶対いる 11はペイロードはアダプテーションに続く00は予約 + private int continuity_counter;//連続性(PIDごとの通し番号) 4bit 28-31 + //ここからアダプテーションフィールド(最後まで) + private int adaptation_length;//8bit 32-39 + private int discontinuity;//1bit + private int random_access;//1bit ランダムアクセスの開始場所となる + private int ES_priority;//1bit プライオリティ + private int five_flag;//5bit + private ArrayList pat_list_now = new ArrayList();//[0]:番組番号 [1]:PMT PID + private ArrayList pat_list_all = new ArrayList(); + private ArrayList pmt_list = new ArrayList();//[0]番組番号 [1]テーブルID + private int pointer_field;//8bit adaptation fieldの次? + private String payload_s; + //ここからオプションフィールド + //PCR42 OPCR42 + //ここまでオプションフィールド + private int staffing_byte;// + + public Mpeg2TSPacket() { + } + + public int getPIDFirst_byte(byte[] ts) { + calc cal = new calc(); + byte[] b = new byte[2]; + b[0] = ts[1]; + b[1] = ts[2]; + return cal.byte2int(b, 3, 13); + //return cal.byte2int(ts,11,13); + } + + public void readTS_byte(byte[] ts) { + /** + * 188バイトのtsから読み出したbyteを与える + */ + calc cal = new calc(); + String tsbyte = byte2String2(ts); + boolean begin_payload_unit = cal.byte2int(ts, 9, 1) == 1; + //header = tsbyte.substring(0, 31); + payload = tsbyte.substring(32); + //starter = TSString2Int(tsbyte, 0, 8); + //transporterror = TSString2Int(tsbyte, 8, 1); + //payloadstart = TSString2Int(tsbyte, 9, 1); + //transport_priority = TSString2Int(tsbyte, 10, 1); + //PID = TSString2Int(tsbyte, 11, 13); + PID = cal.byte2int(ts, 11, 13); + adaptation_field = cal.byte2int(ts, 26, 2); + //continuity_counter = TSString2Int(tsbyte, 28, 4); + payload = ""; + if (PID != 8191) { + if (adaptation_field == 1) { + if (begin_payload_unit) { + pointer_field = cal.byte2int(ts, 32, 8); + if ((ts.length - 5 - pointer_field) < (5 + pointer_field)) { + payload_byte = null; + } else { + payload_byte = cal.byte2subbyte(ts, 5 + pointer_field, ts.length - 5 - pointer_field); + } + } else { + payload_byte = cal.byte2subbyte(ts, 4, ts.length - 4); + } + } else if (adaptation_field == 3) { + adaptation_length = cal.byte2int(ts, 32, 8); + if ((adaptation_length < 184) & ((ts.length * 8 - adaptation_length * 8) > 48)) { + adaptation_length = adaptation_length * 8; + } + adaptation_byte = cal.byte2subbyte(ts, 4, 1 + adaptation_length / 8); + if (begin_payload_unit) { + pointer_field = cal.byte2int(ts, 40 + adaptation_length, 8); + if ((ts.length - 6 - (adaptation_length / 8) - pointer_field) < (6 + (adaptation_length / 8) + pointer_field)) { + payload_byte = null; + } else { + payload_byte = cal.byte2subbyte(ts, 6 + (adaptation_length / 8) + pointer_field, ts.length - 6 - (adaptation_length / 8) - pointer_field); + } + } else { + payload_byte = cal.byte2subbyte(ts, 5 + adaptation_length / 8, ts.length - 5 - adaptation_length / 8); + } + } else { + payload_byte = null; + } + } + if (payload_byte != null) { + if ((PID == 0) && (begin_payload_unit)) { + //cal.showPAT(tsbyte); + if (isPAT(payload_byte)){ + pat_list_now = readPAT_byte(payload_byte); + if (pat_list_now.size()>0){ + pat_list_all=pat_list_now; + } + //pat_list_all.addAll(pat_list_now); + } + } + for (int i = 0; i < pat_list_now.size(); i++) { + if ((PID == pat_list_now.get(i).PID) && (PID != 0)) { + pmt_list.addAll(readPMT_byte(payload_byte, pat_list_now.get(i).Program_TABLE)); + } + } + } + tsbyte = ""; + } + + private ArrayList readPAT_byte(byte[] payload_temp) { + /* + * payloadの文字列を入力して[intテーブル,int PID]のArrayListを返す。 + */ + int tableid; + int sectionlength; + calc cal = new calc(); + ArrayList program_number = new ArrayList(); + tableid = cal.byte2int(payload_temp, 0, 8); + sectionlength = cal.byte2int(payload_temp, 12, 12);//-40-32; + int patnum = sectionlength * 8 - 72; + patnum = patnum / 32; + for (int i = 0; i < patnum; i++) { + if (payload_temp.length * 8 > 64 + 32 * i + 96) { + if (cal.byte2int(payload_temp, 64 + 32 * i + 16, 3) == 7) { + PATData patd = new PATData(); + patd.Program_TABLE = cal.byte2int(payload_temp, 64 + 32 * i, 16); + patd.PID = cal.byte2int(payload_temp, 32 * i + 64 + 19, 13); + program_number.add(patd); + } + } + } + return program_number; + } + private ArrayList readPMT_byte(byte[] payload_temp, int PAT_TABLE) { + ArrayList pmt_t = new ArrayList(); + calc cal = new calc(); + int tableid = cal.byte2int(payload_temp, 0, 8); + int section_length = cal.byte2int(payload_temp, 12, 12); + int pcr_pid = cal.byte2int(payload_temp, 67, 13); + int program_info_length = cal.byte2int(payload_temp, 84, 12); + boolean end = false; + int cur_point = 96 + program_info_length * 8; + if ((cur_point > section_length * 8 - 1) || (cur_point > payload_temp.length * 8 - 11)) { + end = true; + } + while (end != true) { + if (cal.byte2int(payload_temp, cur_point + 8, 3) == 7 && cal.byte2int(payload_temp, cur_point + 24, 4) == 15 && payload_temp.length * 8 > cur_point + 40) { + int pmt_stream_type = cal.byte2int(payload_temp, cur_point, 8); + int elementary_PID = cal.byte2int(payload_temp, cur_point + 11, 13); + //System.out.println(Integer.toString(cur_point)+" : "+Integer.toString(section_length*8)); + int es_length = cal.byte2int(payload_temp, cur_point + 28, 12); + /*if (pmt_stream_type==0x02){ + Descriptor des=new Descriptor(); + Object a=des.getDescriptors(payload_temp.substring(cur_point + 40,cur_point + 40+es_length*8)); + }else if(pmt_stream_type==0x0f){ + Descriptor des=new Descriptor(); + Object a=des.getDescriptors(payload_temp.substring(cur_point + 40,cur_point + 40+es_length*8)); + }*/ + + + PMTData pmtd = new PMTData(); + if ((pmt_stream_type == 0x02) || (pmt_stream_type == 0x0f)||(pmt_stream_type == 0x06)) { + pmtd.Stream_Type = pmt_stream_type; + pmtd.Program_Table = PAT_TABLE; + pmtd.Elementary_PID = elementary_PID; + pmtd.PCR_PID = pcr_pid; + pmt_t.add(pmtd); + } + cur_point = cur_point + 40 + es_length * 8; + //System.out.println(Integer.toString(cur_point)+" : "+Integer.toString(section_length*8)); + if ((cur_point > section_length * 8 - 1) || (cur_point > payload_temp.length * 8 - 11)) { + end = true; + } + if (payload_temp.length * 8 < cur_point + 40){ + end = true; + } + } else { + end = true; + } + } + return pmt_t; + } + + public ArrayList readEIT(byte[] ts) { + String payload_temp = getPayload(ts); + int tableid = TSString2Int(payload_temp, 0, 8); + int section_length = TSString2Int(payload_temp, 12, 12); + int program_number = TSString2Int(payload_temp, 24, 16); + boolean current_next_indicator = (TSString2Int(payload_temp, 47, 1) == 1); + int section_number = TSString2Int(payload_temp, 48, 8); + int curpoint = 112; + ArrayList ret = new ArrayList(); + while (curpoint < 24 + section_length * 8 - 32) { + EITData eitd = new EITData(); + eitd.current_newt_indicator = current_next_indicator; + eitd.event_id = TSString2Int(payload_temp, curpoint, 16); + eitd.program_number = program_number; + eitd.section_number = section_number; + int des_len = TSString2Int(payload_temp, curpoint + 84, 12); + Descriptor des = new Descriptor(); + eitd.descriptors = des.getDescriptors(payload_temp.substring(curpoint + 96, curpoint + 84 + des_len * 8)); + ret.add(eitd); + curpoint = curpoint + 84 + des_len * 8; + } + return ret; + } + + private int TSString2Int(String s, int begin, int length) { + String st = s.substring(begin, begin + length); + int i = Integer.parseInt(st, 2); + return i; + } + + public byte[] splitPAT_byte(byte[] ts, int p_table) { + /** + * + * p_tableで指定された番組テーブルのみを取り出すPATを作る。 + */ + byte[] tbb = new byte[ts.length - 4]; + System.arraycopy(ts, 4, tbb, 0, tbb.length); + if (bPAT_payload != null) { + if (Arrays.equals(tbb, bPAT_payload)) { + byte[] retb = new byte[188]; + System.arraycopy(ts, 0, retb, 0, 4); + System.arraycopy(bPAT_payload, 0, retb, 4, 184); + return retb; + } + } + calc cal = new calc(); + header_byte = cal.byte2subbyte(ts, 0, 4); + byte[] pointer_byte = cal.byte2subbyte(ts, 4, 1); + payload_byte = cal.byte2subbyte(ts, 4, ts.length - 4); + starter = cal.byte2int(ts, 0, 8); + boolean begin_payload_unit = cal.byte2int(ts, 9, 1) == 1; + transporterror = cal.byte2int(ts, 8, 1); + payloadstart = cal.byte2int(ts, 9, 1); + transport_priority = cal.byte2int(ts, 10, 1); + PID = cal.byte2int(ts, 11, 13); + adaptation_field = cal.byte2int(ts, 26, 2); + continuity_counter = cal.byte2int(ts, 28, 4); + if (adaptation_field == 1) { + if (begin_payload_unit) { + pointer_field = cal.byte2int(ts, 32, 8); + if ((ts.length - 5 - pointer_field) < (5 + pointer_field)) { + payload_byte = null; + } else { + payload_byte = cal.byte2subbyte(ts, 5 + pointer_field, ts.length - 5 - pointer_field); + } + } else { + payload_byte = cal.byte2subbyte(ts, 4, ts.length - 4); + } + } else if (adaptation_field == 3) { + adaptation_length = cal.byte2int(ts, 32, 8); + if ((adaptation_length < 184) & ((ts.length * 8 - adaptation_length * 8) > 48)) { + adaptation_length = adaptation_length * 8; + } + adaptation_byte = cal.byte2subbyte(ts, 4, 1 + adaptation_length / 8); + if (begin_payload_unit) { + pointer_field = cal.byte2int(ts, 40 + adaptation_length, 8); + if ((ts.length - 6 - (adaptation_length / 8) - pointer_field) < (6 + (adaptation_length / 8) + pointer_field)) { + payload_byte = null; + } else { + payload_byte = cal.byte2subbyte(ts, 6 + (adaptation_length / 8) + pointer_field, ts.length - 6 - (adaptation_length / 8) - pointer_field); + } + } else { + payload_byte = cal.byte2subbyte(ts, 5 + adaptation_length / 8, ts.length - 5 - adaptation_length / 8); + } + } else { + payload_byte = null; + } + if ((PID == 0) && (begin_payload_unit) && (payload_byte != null)) { + byte[] new_pointer=new byte[1]; + new_pointer[0]=0; + if (isPAT(payload_byte)){ + //showPAT(ts); + payload_byte = makePAT_byte(new_pointer, payload_byte, p_table); + if (payload_byte.length>0){ + bPAT_payload = payload_byte; + } + } + } + if ((payload_byte != null)&& (begin_payload_unit)) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(ts.length); + baos.write(header_byte, 0, header_byte.length); + baos.write(pointer_byte, 0, pointer_byte.length); + baos.write(payload_byte, 0, payload_byte.length); + for (int ir = 0; ir < 188-baos.size(); ir++) { + baos.write(0xFF); + } + + //showPAT(baos.toByteArray()); + return baos.toByteArray(); + } else { + return null; + } + } + + private byte[] makePAT_byte(byte[] pointer_field, byte[] payload_temp, int Table) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(payload_temp.length); + int sectionlength; + calc cal = new calc(); + sectionlength = cal.byte2int(payload_temp, 12, 12); //-40-32; + int patnum = sectionlength * 8 - 72; + baos.write(payload_temp, 0, 1); + int new_section_length = (2 * 32 + 32 + 40) / 8; + baos.write(cal.joinByte((byte) cal.byte2int(payload_temp, 8, 4), (byte) (new_section_length & 0xF00), 4)); + baos.write((byte) (new_section_length & 0xFF)); + baos.write(payload_temp, 3, 5); + patnum = patnum / 32; + int nowt = 8; + boolean alreadyadd=false; + for (int i = 0; i < patnum; i++) { + int[] pat = new int[2]; + pat[0] = cal.byte2int(payload_temp, 64 + 32 * i, 16); + pat[1] = cal.byte2int(payload_temp, 32 * i + 64 + 19, 13); + if (pat[0] == 0) { + baos.write(payload_temp, 8 + 4 * i, 4); + nowt = nowt + 4; + } else if ((pat[0] == Table)&&(alreadyadd==false)) { + baos.write(payload_temp, 8 + 4 * i, 4); + nowt = nowt + 4; + alreadyadd=true; + } + } + ByteArrayOutputStream baoscrc = new ByteArrayOutputStream(nowt + 1); + baoscrc.write(pointer_field[0]); + baoscrc.write(baos.toByteArray(), 0, baos.size()); + byte[] crc = cal.getCRC32_byte(baoscrc.toByteArray(), 1); + //byte[] crc = getCRC32_byte(baoscrc.toByteArray(), 1); + baos.write(crc, 0, crc.length); + int ill3 = payload_temp.length - baos.size(); + for (int ir = 0; ir < ill3; ir++) { + baos.write(0xFF); + } + return baos.toByteArray(); + } + public boolean isPAT(byte[] byte_tmp){ + calc cal=new calc(); + if ((cal.byte2int(byte_tmp,0,8)==0)&&(cal.byte2int(byte_tmp,9,3)==3)&&(cal.byte2int(byte_tmp, 40, 2)==3)){ + return true; + }else{ + return false; + } + } + public boolean isPMT(byte[] byte_tmp){ + calc cal=new calc(); + if ((cal.byte2int(byte_tmp,9,3)==3)&&(cal.byte2int(byte_tmp, 40, 2)==3)&&(cal.byte2int(byte_tmp,64,3)==3)&&(cal.byte2int(byte_tmp,80,4)==15)){ + return true; + }else{ + return false; + } + } + private String getCRC32(String s) { + return getCRC32(String2Byte(s), 1); + } + + private String getCRC32(byte[] data, int offset) { + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 + int[] g = {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; + int[] shift_reg = new int[32]; + long crc = 0; + byte crc32[] = new byte[4]; + + // Initialize shift register's to '1' + java.util.Arrays.fill(shift_reg, 1); + + // Calculate nr of data bits, summa of bits + int nr_bits = (data.length - offset) * 8; + + for (int bit_count = 0, bit_in_byte = 0, data_bit; bit_count < nr_bits; bit_count++) { + // Fetch bit from bitstream + data_bit = (data[offset] & 0x80 >>> (bit_in_byte++)) != 0 ? 1 : 0; + + if ((bit_in_byte &= 7) == 0) { + offset++; + } + + // Perform the shift and modula 2 addition + data_bit ^= shift_reg[31]; + + for (int i = 31; i > 0; i--) { + shift_reg[i] = g[i] == 1 ? (shift_reg[i - 1] ^ data_bit) : shift_reg[i - 1]; + } + + shift_reg[0] = data_bit; + } + + for (int i = 0; i < 32; i++) { + crc = ((crc << 1) | (shift_reg[31 - i])); + } + + for (int i = 0; i < 4; i++) { + crc32[i] = (byte) (0xFF & (crc >>> ((3 - i) * 8))); + } + String s = Long2String(crc, 32); + return s; + } + + private byte[] getCRC32_byte(byte[] data, int offset) { + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 + int[] g = {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; + int[] shift_reg = new int[32]; + long crc = 0; + byte crc32[] = new byte[4]; + + // Initialize shift register's to '1' + java.util.Arrays.fill(shift_reg, 1); + + // Calculate nr of data bits, summa of bits + int nr_bits = (data.length - offset) * 8; + + for (int bit_count = 0, bit_in_byte = 0, data_bit; bit_count < nr_bits; bit_count++) { + // Fetch bit from bitstream + data_bit = (data[offset] & 0x80 >>> (bit_in_byte++)) != 0 ? 1 : 0; + + if ((bit_in_byte &= 7) == 0) { + offset++; + } + + // Perform the shift and modula 2 addition + data_bit ^= shift_reg[31]; + + for (int i = 31; i > 0; i--) { + shift_reg[i] = g[i] == 1 ? (shift_reg[i - 1] ^ data_bit) : shift_reg[i - 1]; + } + + shift_reg[0] = data_bit; + } + + for (int i = 0; i < 32; i++) { + crc = ((crc << 1) | (shift_reg[31 - i])); + } + + for (int i = 0; i < 4; i++) { + crc32[i] = (byte) (0xFF & (crc >>> ((3 - i) * 8))); + } + return crc32; + } + + private String addzero(int num) { + switch (num) { + case 0: + return ""; + case 1: + return "0"; + case 2: + return "00"; + case 3: + return "000"; + case 4: + return "0000"; + case 5: + return "00000"; + case 6: + return "000000"; + case 7: + return "0000000"; + case 8: + return "00000000"; + default: + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < num; i++) { + sb.append("0"); + } + return sb.toString(); + } + } + + private String byte2String2(byte[] b) { + int bl = b.length; + bl = bl - bl % 8; + bl = bl / 8; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < bl; i++) { + long retl = 0; + for (int j = 0; j < 8; j++) { + retl = retl << 8; + int ri = b[i * 8 + j] & 0xFF; + retl = retl + ri; + } + sb.append(Long2String(retl, 64)); + } + int bl2 = b.length % 8; + bl2 = (bl2 - bl2 % 4) / 4; + for (int i = 0; i < bl2; i++) { + int reti = 0; + for (int j = 0; j < 4; j++) { + reti = reti << 8; + reti = reti + (b[bl * 8 + 4 * i + j] & 0xFF); + } + sb.append(Int2String(reti, 32)); + } + for (int i = 0; i < (b.length % 8) % 4; i++) { + sb.append(Int2String(b[bl * 8 + bl2 * 4 + i] & 0xFF, 8)); + } + return sb.toString(); + } + + private String Int2String(int num, int length) { + String ret = Integer.toBinaryString(num); + if (ret.length() < length) { + int it = length - ret.length(); + for (int i = 0; i < it; i++) { + ret = "0" + ret; + } + } + return ret; + } + + private String Long2String(long num, int length) { + String ret = Long.toBinaryString(num); + if (ret.length() < length) { + int it = length - ret.length(); + for (int i = 0; i < it; i++) { + ret = "0" + ret; + } + } + return ret; + } + + private byte[] String2Byte(String ts) { + //StringBuffer sb=new StringBuffer(ts); + int len = ts.length() - ts.length() % 8; + len = len / 8; + byte[] ret = new byte[len]; + for (int i = 0; i < len; i++) { + String tet = ts.substring(i * 8, i * 8 + 8); + int itt = TSString2Int(tet, 0, 8); + ret[i] = (byte) itt; + } + return ret; + } + + public ArrayList getPAT() { + return pat_list_all; + } + + public void setPAT(ArrayList pat) { + pat_list_now = pat; + pat_list_all = pat; + } + + public ArrayList getPMT() { + return pmt_list; + } + + public void setPMT(ArrayList pmt) { + pmt_list = pmt; + } + + public int getPID() { + return PID; + } + + public String getPayload(byte[] ts) { + /** + * 188バイトのtsから読み出したbyteを与える + */ + String tsbyte = byte2String2(ts); + //header = tsbyte.substring(0, 31); + String ret_payload = ""; + //starter = TSString2Int(tsbyte, 0, 8); + //transporterror = TSString2Int(tsbyte, 8, 1); + //payloadstart = TSString2Int(tsbyte, 9, 1); + //transport_priority = TSString2Int(tsbyte, 10, 1); + int pid = TSString2Int(tsbyte, 11, 13); + int af = TSString2Int(tsbyte, 26, 2); + //continuity_counter = TSString2Int(tsbyte, 28, 4); + if (pid != 8191) { + if (af == 1) { + ret_payload = tsbyte.substring(40); + } else if (af == 3) { + int al = TSString2Int(tsbyte, 32, 8); + if ((al < 184) & ((tsbyte.length() - al * 8) > 48)) { + al = al * 8; + } + ret_payload = tsbyte.substring(48 + al); + } + } + return ret_payload; + } + + public byte[] getPayload_byte(byte[] ts) { + /** + * 188バイトのtsから読み出したbyteを与える + */ + calc cal = new calc(); + String tsbyte = byte2String2(ts); + //header = tsbyte.substring(0, 31); + byte[] retb = null; + //starter = TSString2Int(tsbyte, 0, 8); + //transporterror = TSString2Int(tsbyte, 8, 1); + //payloadstart = TSString2Int(tsbyte, 9, 1); + //transport_priority = TSString2Int(tsbyte, 10, 1); + int pid = cal.byte2int(ts, 11, 13); + int af = cal.byte2int(ts, 26, 2); + //continuity_counter = TSString2Int(tsbyte, 28, 4); + if (pid != 8191) { + if (af == 1) { + retb = cal.byte2subbyte(ts, 5, ts.length - 5); + } else if (af == 3) { + int al = cal.byte2int(ts, 32, 8); + if ((al < 184) & ((ts.length * 8 - al * 8) > 48)) { + al = al * 8; + } + retb = cal.byte2subbyte(ts, 6 + al / 8, ts.length - 6 - al / 8); + } + } + return retb; + } + + public ArrayList readPMTglobal_byte(byte[] ts, int TABLE_NUM) { + byte[] payloadt = getPayload_byte(ts); + return readPMT_byte(payloadt, TABLE_NUM); + } + + public void showPAT(byte[] ts){ + calc c=new calc(); + showPAT(c.byte2String2(ts)); + } + public void showPAT(String ts) { + System.out.println("先頭:" + ts.substring(0, 8)); + System.out.println("" + ts.substring(8, 11)); + System.out.println("PID:" + ts.substring(11, 24)); + System.out.println("" + ts.substring(24, 32)); + System.out.println("Adap_Len:" + ts.substring(32, 40)); + System.out.println("TableID:" + ts.substring(40, 48)); + System.out.println("" + ts.substring(48, 52)); + System.out.println("len : " + ts.substring(52, 64) + "//" + Integer.toString(Integer.parseInt(ts.substring(52, 64), 2))); + System.out.println("TS ID:" + ts.substring(64, 80)); + System.out.println("11:" + ts.substring(80, 82)); + System.out.println("" + ts.substring(82, 104)); + for (int i = 0; i < 10; i++) { + System.out.println(Integer.toString(i) + " : BroadNum:" + ts.substring(104 + 32 * i, 120 + 32 * i)+" (0x"+Integer.toHexString(Integer.parseInt(ts.substring(104 + 32 * i, 120 + 32 * i), 2))+") 111:"+ ts.substring(120 + 32 * i, 123 + 32 * i)+" Net/PMT PID :"+ ts.substring(123 + 32 * i, 136 + 32 * i)+" (0x"+Integer.toHexString(Integer.parseInt(ts.substring(123 + 32 * i, 136 + 32 * i), 2))+")"); + } + System.out.println("Length:" + Integer.toString(ts.length())); + } +} diff --git a/jTsSplitter/jtssplitter/Tsfile.java b/jTsSplitter/jtssplitter/Tsfile.java new file mode 100644 index 0000000..587243b --- /dev/null +++ b/jTsSplitter/jtssplitter/Tsfile.java @@ -0,0 +1,370 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2012 Yukikaze + */ + +package jtssplitter; +import java.util.ArrayList; +import java.io.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.Arrays; +import jtssplitter.data.PATData; +import jtssplitter.data.PIDs; +import jtssplitter.data.PMTData; +/** + * + * @author Administrator + */ +public class Tsfile { + public void splitTS_byte(String origpath,String destpath,int csch){ + int[] pids=null; + int p_table=0; + if (csch>0){ + p_table=csch; + }else{ + p_table=getFirstP_Table_byte(origpath); + } + PIDs pidss=getTablePID_byte(origpath,p_table); + p_table=pidss.Program_Table; + pids=pidss.PIDs; + int pmt_pid=pidss.PMT_PID; + System.out.println("番組の同定終了"); + System.out.println("Program Table : "+Integer.toString(p_table)); + byte[] tb=new byte[188]; + try { + FileInputStream in = new FileInputStream(origpath); + FileOutputStream fos=new FileOutputStream(destpath); + BufferedInputStream bis=new BufferedInputStream(in,128*188); + BufferedOutputStream bos=new BufferedOutputStream(fos); + byte[] wbyte=null; + boolean end=false; + int ik=0; + boolean readend=false; + Mpeg2TSPacket m2tpp; + m2tpp=new Mpeg2TSPacket(); + while (readend==false){ + byte[] tstt=new byte[3]; + bis.mark(188*2); + bis.read(tstt); + bis.reset(); + wbyte=null; + Mpeg2TSPacket m2tp; + m2tp=new Mpeg2TSPacket(); + //int ii=m2tpp.getPIDFirst(tstt); + int ii=m2tpp.getPIDFirst_byte(tstt); + //if (ii!=i2){ + // System.out.println("not match"); + //} + boolean alreadyreaded=false; + for (int k=0;k187)){ + Mpeg2TSPacket m2tp2=new Mpeg2TSPacket(); + m2tp2.readTS_byte(tb); + ArrayList pats=new ArrayList(); + pats=m2tp2.getPAT(); + boolean containp_table=false; + for (int iii=0;iii 0){ + containp_table=true; + } + } + if (!containp_table){ + for (int iii=0;iii0){ + System.out.println("Program Tableの変更を検知"+Integer.toString(p_table)+" to "+Integer.toString(pats.get(iii).Program_TABLE)); + p_table=pats.get(iii).Program_TABLE; + for (int it=0;it187)){ + wbyte=tb; + ArrayList pmtss; + try{ + pmtss=m2tpp.readPMTglobal_byte(tb, pmt_pid); + }catch(Exception e){ + pmtss=new ArrayList(); + } + if (pmtss.size()>0){ + int[] new_pids=new int[pmtss.size()+3]; + new_pids[pmtss.size()]=0; + new_pids[pmtss.size()+1]=pmt_pid; + new_pids[pmtss.size()+2]=pmtss.get(0).PCR_PID; + for (int i=0;i187)){ + ArrayList eitss=m2tpp.readEIT(tb); + */ + }else if (readti>187){ + wbyte=tb; + + }else { + readend=true; + } + k=pids.length; + } + } + ik++; + } + if (alreadyreaded==false){ + bis.skip(188); + } + if (wbyte!=null){ + bos.write(wbyte); + } + } + bis.close(); + bos.flush(); + bos.close(); + in.close(); + fos.close(); + + } catch (IOException ex) { + Logger.getLogger(Tsfile.class.getName()).log(Level.SEVERE, null, ex); + } + } + private PIDs getTablePID_byte(String fpath,int p_table){ + /** + * PIDを取得し、これと思われる必要なPIDを抜き出す。 + * @return プログラム番号(return[0])とPIDのリスト(return[1-]) + */ + FileInputStream in = null; + PIDs pids=new PIDs(); + int[] reti=null; + try { + ArrayList ret=new ArrayList(); + byte[] tb = new byte[188]; + int[] ib = new int[188]; + ArrayList pat = new ArrayList(); + ArrayList pmt = new ArrayList(); + String[] sb = new String[188]; + in = new FileInputStream(fpath); + int imax=1000; + for (int i = 0; i < imax ; i++) { + if (in.read(tb)==-1){ + in.close(); + System.out.println("Program Table and PMT not found."); + System.exit(1); + } + String last8; + Mpeg2TSPacket m2tp; + m2tp = new Mpeg2TSPacket(); + m2tp.setPAT(pat); + m2tp.setPMT(pmt); + m2tp.readTS_byte(tb); + pat = m2tp.getPAT(); + for (int i2=0;i2 pmtt=m2tp.getPMT(); + for (int i2=0;i2 retti = new ArrayList(); + byte[] tb = new byte[188]; + ArrayList pat = new ArrayList(); + ArrayList pat_ok = new ArrayList(); + ArrayList pmt = new ArrayList(); + try { + in = new FileInputStream(fpath); + int imax = 7000; + int mmax = 20000; + for (int i = 0; i < imax; i++) { + if (in.read(tb) == -1) { + in.close(); + System.out.println("Program Table not found."); + System.exit(1); + } + String last8; + Mpeg2TSPacket m2tp; + m2tp = new Mpeg2TSPacket(); + m2tp.setPAT(pat); + m2tp.setPMT(pmt); + m2tp.readTS_byte(tb); + pat = m2tp.getPAT(); + pmt = m2tp.getPMT(); + ArrayList pmtt=m2tp.getPMT(); + for (int i2=0;i2imax-10 && pat_ok.size()==0 && i pat = new ArrayList(); + ArrayList pmt = new ArrayList(); + String[] sb = new String[188]; + in = new FileInputStream(fpath); + //int[] PIDCount = new int[8200]; + int imax=1000; + calc cal=new calc(); + for (int i = 0; i < imax ; i++) { + in.read(tb); + String last8; + Mpeg2TSPacket m2tp; + m2tp = new Mpeg2TSPacket(); + m2tp.setPAT(pat); + m2tp.setPMT(pmt); + m2tp.readTS_byte(tb); + pat = m2tp.getPAT(); + pmt = m2tp.getPMT(); + if ((i==imax-1)&&(pmt.size()==0)){ + imax=imax+500; + } + } + + for (int i=0;i0){ + patdd=pat.get(i); + i=pat.size(); + } + } + } catch (IOException ex) { + Logger.getLogger(Tsfile.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + in.close(); + } catch (IOException ex) { + Logger.getLogger(Tsfile.class.getName()).log(Level.SEVERE, null, ex); + } + } + return patdd.Program_TABLE; + } +} \ No newline at end of file diff --git a/jTsSplitter/jtssplitter/calc.java b/jTsSplitter/jtssplitter/calc.java new file mode 100644 index 0000000..a25cd02 --- /dev/null +++ b/jTsSplitter/jtssplitter/calc.java @@ -0,0 +1,283 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2012 Yukikaze + */ + +package jtssplitter; + +/** + * + * @author yukikaze + */ +public class calc { + public String Int2String(int num, int length) { + String ret = Integer.toBinaryString(num); + if (ret.length() < length) { + int it = length - ret.length(); + for (int i = 0; i < it; i++) { + ret = "0" + ret; + } + } + return ret; + } + public String Long2String(long num, int length) { + String ret = Long.toBinaryString(num); + if (ret.length() < length) { + int it = length - ret.length(); + for (int i = 0; i < it; i++) { + ret = "0" + ret; + } + } + return ret; + } + public byte[] String2Byte(String ts) { + //StringBuffer sb=new StringBuffer(ts); + int len = ts.length() - ts.length() % 8; + len = len / 8; + byte[] ret = new byte[len]; + for (int i = 0; i < len; i++) { + String tet = ts.substring(i * 8, i * 8 + 8); + int itt = TSString2Int(tet, 0, 8); + ret[i] = (byte) itt; + } + return ret; + } + public byte joinByte(byte b1,byte b2,int b2length){ + byte ret=(byte)(b1<<(b2length)&0xFF+b2&0xFF); + return ret; + } + public byte joinByte(byte b1,byte b2,int b2len,byte b3,int b3len){ + byte ret=joinByte(b1,b2,b2len); + ret=joinByte(ret, b3, b3len); + return ret; + } + public String byte2String(byte[] b) { + StringBuffer sb=new StringBuffer(8*b.length); + for (int i = 0; i < b.length; i++) { + StringBuffer sb2=new StringBuffer(8); + sb2.append(Integer.toBinaryString(b[i] & 0xFF)); + if ((sb2.length() < 8) & (sb2.length() > 0)) { + sb2.insert(0,addzero(8-sb2.length())); + } + sb.append(sb2); + } + return sb.toString(); + } + public String byte2String2(byte[] b){ + int bl=b.length; + bl=bl-bl%8; + bl=bl/8; + StringBuffer sb=new StringBuffer(); + for (int i=0;i>k; + } + }else if (i==bb-a){ + int k=0; + if ((startbit+length)%8==0){ + k=8; + }else{ + k=8-(startbit+length)%8; + } + ret=ret+((b[a+i]&0xFF)>>k); + }else{ + ret=ret+((b[a+i]&0xFF)<<((bb-a-i-1)*8+((startbit+length)%8))); + } + if (b.length-1-a==i){ + i=bb-a+1; + } + } + return ret; + } + public long byte2long(byte[] b,int startbit,int length){ + int a=startbit-startbit%8; + a=a/8; + int bb=startbit+length-(startbit+length)%8; + bb=bb/8; + long ret=0; + for (int i=0;i>k; + } + }else if (i==bb-a){ + int k=0; + if ((startbit+length)%8==0){ + k=8; + }else{ + k=8-(startbit+length)%8; + } + ret=ret+((b[a+i]&0xFF)>>k); + }else{ + ret=ret+((b[a+i]&0xFF)<<((bb-a-i-1)*8+((startbit+length)%8))); + } + } + return ret; + } + public void showPAT(String ts) { + System.out.println("先頭:" + ts.substring(0, 8)); + System.out.println("" + ts.substring(8, 11)); + System.out.println("PID:" + ts.substring(11, 24)); + System.out.println("" + ts.substring(24, 32)); + System.out.println("Adap_Len:" + ts.substring(32, 40)); + System.out.println("TableID:" + ts.substring(40, 48)); + System.out.println("" + ts.substring(48, 52)); + System.out.println("len : " + ts.substring(52, 64) + "//" + Integer.toString(Integer.parseInt(ts.substring(52, 64), 2))); + System.out.println("TS ID:" + ts.substring(64, 80)); + System.out.println("11:" + ts.substring(80, 82)); + System.out.println("" + ts.substring(82, 104)); + for (int i = 0; i < 10; i++) { + System.out.println(Integer.toString(i) + " : " + ts.substring(104 + 32 * i, 136 + 32 * i)); + } + System.out.println("Length:" + Integer.toString(ts.length())); + } + public byte[] getCRC32_byte(byte[] data, int offset) { + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 + int[] g = {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; + int[] shift_reg = new int[32]; + long crc = 0; + byte crc32[] = new byte[4]; + + // Initialize shift register's to '1' + java.util.Arrays.fill(shift_reg, 1); + + // Calculate nr of data bits, summa of bits + int nr_bits = (data.length - offset) * 8; + + for (int bit_count = 0, bit_in_byte = 0, data_bit; bit_count < nr_bits; bit_count++) { + // Fetch bit from bitstream + data_bit = (data[offset] & 0x80 >>> (bit_in_byte++)) != 0 ? 1 : 0; + + if ((bit_in_byte &= 7) == 0) { + offset++; + } + + // Perform the shift and modula 2 addition + data_bit ^= shift_reg[31]; + + for (int i = 31; i > 0; i--) { + shift_reg[i] = g[i] == 1 ? (shift_reg[i - 1] ^ data_bit) : shift_reg[i - 1]; + } + + shift_reg[0] = data_bit; + } + + for (int i = 0; i < 32; i++) { + crc = ((crc << 1) | (shift_reg[31 - i])); + } + + for (int i = 0; i < 4; i++) { + crc32[i] = (byte) (0xFF & (crc >>> ((3 - i) * 8))); + } + return crc32; + } +} diff --git a/jTsSplitter/jtssplitter/data/Audio_stream_descriptor.java b/jTsSplitter/jtssplitter/data/Audio_stream_descriptor.java new file mode 100644 index 0000000..afd48f4 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/Audio_stream_descriptor.java @@ -0,0 +1,36 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; + +/** + * + * @author yukikaze + */ +public class Audio_stream_descriptor { + private int descriptor_tag;//0-7 + private int descriptor_length;//8-15 + private boolean multiple_frame_rate_flag;//16 + private String frame_rate_code;//17-20 + /** + * frame rate + * 0001 : 24000/1001 + * 0010 : 24 + * 0011 : 25 + * 0100 : 30000/1001 + * 0101 : 30 + * 0110 : 50 + * 0111 : 60000/1001 + * 1000 : 60 + * + **/ + private jtssplitter.calc cal=new jtssplitter.calc(); + public void analyze(String s){ + multiple_frame_rate_flag=cal.TSString2Int(s,16,1)==1; + frame_rate_code=cal.Int2String(cal.TSString2Int(s, 17, 4),4); + s=""; + //descriptor_tag= + } +} diff --git a/jTsSplitter/jtssplitter/data/Descriptor.java b/jTsSplitter/jtssplitter/data/Descriptor.java new file mode 100644 index 0000000..2280981 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/Descriptor.java @@ -0,0 +1,101 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ +package jtssplitter.data; + +import java.util.ArrayList; +import jtssplitter.calc; +import jtssplitter.data.descriptor.ARIB_Audio_Component_Descriptor; +import jtssplitter.data.descriptor.ARIB_Video_Compornent_Descriptor; + +/** + * + * @author yukikaze + */ +public class Descriptor { + + private calc cal = new calc(); + + public String analyze(String s) { + StringBuffer sb=new StringBuffer(); + int curp = 0; + while (s.length() > curp + 16) { + String adds = ""; + int tag = cal.TSString2Int(s, curp + 0, 8); + int len = cal.TSString2Int(s, curp + 8, 8) * 8; + String des_s = s.substring(curp + 16, curp + 16 + len); + curp = curp + len + 16; + switch (tag) { + case 0xc8://ビデオコントロール記述子 + switch (cal.TSString2Int(des_s, 3, 4)) { + case 0: + adds = "Video:1080p"; + break; + case 1: + adds = "Video:1080i"; + break; + case 2: + adds = "Video:720p"; + break; + case 3: + adds = "Video:480p"; + break; + case 4: + adds = "Video:480i"; + break; + case 5: + adds = "Video:240p"; + break; + case 6: + adds = "Video:120p"; + break; + case 7: + adds = "Video:2160p"; + break; + } + break; + case 0xc4://音声コンポーネント記述子 + switch (cal.TSString2Int(des_s, 8, 8)) { + case 0x01: + adds = "Video:120p"; + break; + + } + break; + } + if (adds.length() > 0) { + sb.append(adds); + } + } + return sb.toString(); + } + public ArrayList getDescriptors(String s){ + jtssplitter.calc cal=new calc(); + return getDescriptors(cal.String2Byte(s)); + } + public ArrayList getDescriptors(byte[] b){ + int curp = 0; + ArrayList ad=new ArrayList(); + while (b.length > curp + 2) { + int tag = b[curp]&0xFF; + int len = b[curp+1]&0xFF; + byte[] btag=new byte[len]; + System.arraycopy(b,curp+2,btag,0,len); + curp = curp + len + 2; + switch (tag) { + case 0xc8://ビデオコントロール記述子 + jtssplitter.data.descriptor.ARIB_Video_Compornent_Descriptor avcd=new jtssplitter.data.descriptor.ARIB_Video_Compornent_Descriptor(); + avcd.analyzeDescriptor(0xc8, btag); + ad.add(avcd); + break; + case 0xc4://音声コンポーネント記述子 + ARIB_Audio_Component_Descriptor aacd=new ARIB_Audio_Component_Descriptor(); + aacd.analyzeDescriptor(0xC4, btag); + ad.add(aacd); + break; + } + } + return ad; + } +} diff --git a/jTsSplitter/jtssplitter/data/DescriptorData.java b/jTsSplitter/jtssplitter/data/DescriptorData.java new file mode 100644 index 0000000..9603ea9 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/DescriptorData.java @@ -0,0 +1,45 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; + +/** + * 記述子の内容を保持 + * @author yukikaze + */ +public class DescriptorData{ + public DescriptorData(){ + + } + public DescriptorData(int descriptor_tag,int value){ + Descriptor_tag=descriptor_tag; + Value=value; + } + /** + * 記述子タグ + * 0x08:動画タグ:: + * -value:: + * -0:1080p + * -1:1080i + * -2:720p + * -3:480p + * -4:480i + * -5:240p + * -6:120p + * -7:2160p + * 0xC4:音声タグ:: + * -value:: + * -1:1/0(シングルモノラル) + * -2:1/0+1/0(デュアルモノラル) + * -3:2/0 + * -4:2/1 + * -7:3/1 + * -8:3/2 + * -9:3/2+LFE (5.1chサラウンド) + * + */ + public int Descriptor_tag; + public int Value; +} diff --git a/jTsSplitter/jtssplitter/data/EITData.java b/jTsSplitter/jtssplitter/data/EITData.java new file mode 100644 index 0000000..14b9730 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/EITData.java @@ -0,0 +1,18 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; +import java.util.ArrayList; +/** + * + * @author yukikaze + */ +public class EITData { + public int program_number; + public boolean current_newt_indicator; + public int section_number; + public int event_id; + public ArrayList descriptors; +} diff --git a/jTsSplitter/jtssplitter/data/PATData.java b/jTsSplitter/jtssplitter/data/PATData.java new file mode 100644 index 0000000..3106096 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/PATData.java @@ -0,0 +1,23 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; + +/** + * PATの一番組についてのデータ + * @author Yukikaze + */ +public class PATData { + /** + * PAT内のプログラム番号 + * BS/CS放送ではチャンネル名になっていることが多い + */ + public int Program_TABLE; + /** + * プログラム番号に対応したPMTが含まれるPID + */ + public int PID; + boolean containVideo=false; +} diff --git a/jTsSplitter/jtssplitter/data/PIDs.java b/jTsSplitter/jtssplitter/data/PIDs.java new file mode 100644 index 0000000..026c74e --- /dev/null +++ b/jTsSplitter/jtssplitter/data/PIDs.java @@ -0,0 +1,17 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; + +/** + * + * @author Administrator + */ +public class PIDs { + public int Program_Table; + public int[] PIDs; + public int PMT_PID; + public int PCR_PID; +} diff --git a/jTsSplitter/jtssplitter/data/PMTData.java b/jTsSplitter/jtssplitter/data/PMTData.java new file mode 100644 index 0000000..37d7466 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/PMTData.java @@ -0,0 +1,24 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; + +/** + * PMTのデータ。 + * @author Yukikaze + */ +public class PMTData { + /** + * プログラムの番号 + * CS、BSだとチャンネル番号になる。 + */ + public int Program_Table; + /** + * Streamのタイプを決定する + */ + public int Stream_Type; + public int PCR_PID; + public int Elementary_PID; +} diff --git a/jTsSplitter/jtssplitter/data/Video_stream_descriptor.java b/jTsSplitter/jtssplitter/data/Video_stream_descriptor.java new file mode 100644 index 0000000..9ef7246 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/Video_stream_descriptor.java @@ -0,0 +1,40 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data; +import jtssplitter.calc; +/** + * ビデオ記述子 + * 定義はISO/IEC 13818-1:2000(E) Table 2-40による + * @author yukikaze + */ + +public class Video_stream_descriptor { + private int descriptor_tag;//0-7 + private int descriptor_length;//8-15 + private boolean multiple_frame_rate_flag;//16 + private String frame_rate_code;//17-20 + /** + * frame rate + * 0001 : 24000/1001 + * 0010 : 24 + * 0011 : 25 + * 0100 : 30000/1001 + * 0101 : 30 + * 0110 : 50 + * 0111 : 60000/1001 + * 1000 : 60 + * + **/ + private jtssplitter.calc cal=new jtssplitter.calc(); + public void analyze(String s){ + descriptor_tag=cal.TSString2Int(s,0,8); + multiple_frame_rate_flag=cal.TSString2Int(s,16,1)==1; + frame_rate_code=cal.Int2String(cal.TSString2Int(s, 17, 4),4); + s=""; + //descriptor_tag= + } + +} diff --git a/jTsSplitter/jtssplitter/data/descriptor/ARIB_Audio_Component_Descriptor.java b/jTsSplitter/jtssplitter/data/descriptor/ARIB_Audio_Component_Descriptor.java new file mode 100644 index 0000000..8b87c86 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/descriptor/ARIB_Audio_Component_Descriptor.java @@ -0,0 +1,153 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data.descriptor; + +import java.io.UnsupportedEncodingException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author yukikaze + */ +public class ARIB_Audio_Component_Descriptor extends jtssplitter.data.descriptor.abstract_Descriptor{ + private int Descriptor; + private int compornent_type; + private int compornent_tag; + private int stream_type; + private boolean ES_multi_lingual_flag; + private boolean main_component_flag; + private int quality_indicator; + private int sampling_rate; + private int ISO_639_language_code; + private int ISO_639_language_code_2; + private String text; + @Override + public int getDescriptorTag() { + return Descriptor; + } + + @Override + public void analyzeDescriptor(byte[] descriptor) { + Descriptor=descriptor[0]&0xFF; + compornent_type=descriptor[3]&0xFF; + compornent_tag=descriptor[4]&0xFF; + stream_type=descriptor[5]&0xFF; + ES_multi_lingual_flag=(((descriptor[7]&0x80)>>7)==1); + main_component_flag=(((descriptor[7]&0x40)>>6)==1); + quality_indicator=(descriptor[7]&0x30>>4); + sampling_rate=(descriptor[7]&0xE>>1); + ISO_639_language_code=(((descriptor[8]&0xFF)<<16)+((descriptor[9]&0xFF)<<8)+(descriptor[10]&0xFF)); + if (ES_multi_lingual_flag){ + ISO_639_language_code_2=(((descriptor[11]&0xFF)<<16)+((descriptor[12]&0xFF)<<8)+(descriptor[13]&0xFF)); + try { + text = new String(descriptor, 14, descriptor.length - 14, "EUC-JP"); + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(ARIB_Audio_Component_Descriptor.class.getName()).log(Level.SEVERE, null, ex); + } + }else{ + try { + text = new String(descriptor, 11, descriptor.length - 11, "EUC-JP"); + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(ARIB_Audio_Component_Descriptor.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } + + @Override + public void analyzeDescriptor(int DescriptorTag, byte[] descriptor) { + + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * 音声のコンポーネント種別を示す。 + * @return the compornent_type + * -1:1/0(シングルモノラル) + * -2:1/0+1/0(デュアルモノラル) + * -3:2/0 + * -4:2/1 + * -7:3/1 + * -8:3/2 + * -9:3/2+LFE (5.1chサラウンド) + */ + public int getCompornent_type() { + return compornent_type; + } + + /** + * @return the compornent_tag + */ + public int getCompornent_tag() { + return compornent_tag; + } + + /** + * @return the stream_type + */ + public int getStream_type() { + return stream_type; + } + + /** + * @return the ES_multi_lingual_flag + */ + public boolean isES_multi_lingual_flag() { + return ES_multi_lingual_flag; + } + + /** + * @return the main_component_flag + */ + public boolean isMain_component_flag() { + return main_component_flag; + } + + /** + * @return the quality_indicator + */ + public int getQuality_indicator() { + return quality_indicator; + } + + /** + * サンプリング周波数を示す。 + * @return the sampling_rate + * 1-16kHz + * 2-22.05kHz + * 3-24kHz + * 5-32kHz + * 6-44.1kHz + * 7-48kHz + */ + public int getSampling_rate() { + return sampling_rate; + } + + /** + * @return the ISO_639_language_code + */ + public int getISO_639_language_code() { + return ISO_639_language_code; + } + + /** + * @return the ISO_639_language_code_2 + */ + public int getISO_639_language_code_2() { + return ISO_639_language_code_2; + } + + /** + * @return the text + */ + public String getText() { + return text; + } + + +} diff --git a/jTsSplitter/jtssplitter/data/descriptor/ARIB_Video_Compornent_Descriptor.java b/jTsSplitter/jtssplitter/data/descriptor/ARIB_Video_Compornent_Descriptor.java new file mode 100644 index 0000000..2324902 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/descriptor/ARIB_Video_Compornent_Descriptor.java @@ -0,0 +1,71 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data.descriptor; + +import jtssplitter.data.descriptor.abstract_Descriptor; +/** + * + * @author yukikaze + */ +public class ARIB_Video_Compornent_Descriptor extends jtssplitter.data.descriptor.abstract_Descriptor{ + private int Descriptor; + private boolean still_picture_flag; + private boolean sequence_end_code_flag; + private int video_encode_format; + + /** + * @return the still_picture_flag + */ + public boolean isStill_picture_flag() { + return still_picture_flag; + } + + /** + * 動画フォーマットが直後から変更されるかどうか + * @return the sequence_end_code_flag + */ + public boolean isSequence_end_code_flag() { + return sequence_end_code_flag; + } + + /** + * 動画のフォーマットを示す。 + * @return the video_encode_format + * 0-1080p + * 1-1080i + * 2-720p + * 3-480p + * 4-480i + * 5-240p + * 6-120p + * 7-2160p + */ + public int getVideo_encode_format() { + return video_encode_format; + } + + @Override + public void analyzeDescriptor(int DescriptorTag, byte[] descriptor) { + Descriptor=DescriptorTag; + still_picture_flag=((descriptor[0]&0x80)>>7==1); + sequence_end_code_flag=((descriptor[0]&0x40)>>6==1); + video_encode_format=(descriptor[0]&0x3C)>>2; + } + + @Override + public int getDescriptorTag() { + return Descriptor; + } + + @Override + public void analyzeDescriptor(byte[] descriptor) { + Descriptor=descriptor[0]&0xFF; + still_picture_flag=((descriptor[2]&0x80)>>7==1); + sequence_end_code_flag=((descriptor[2]&0x40)>>6==1); + video_encode_format=(descriptor[2]&0x3C)>>2; + } + +} diff --git a/jTsSplitter/jtssplitter/data/descriptor/abstract_Descriptor.java b/jTsSplitter/jtssplitter/data/descriptor/abstract_Descriptor.java new file mode 100644 index 0000000..7b2c9d6 --- /dev/null +++ b/jTsSplitter/jtssplitter/data/descriptor/abstract_Descriptor.java @@ -0,0 +1,34 @@ +/* + * jTsSplitter - java based mpeg2ts splitter. + * Copyright (C) 2009-2010 Yukikaze + */ + +package jtssplitter.data.descriptor; + +/** + * 記述子記述のための抽象メソッド + * @author yukikaze + */ +abstract public class abstract_Descriptor { + /** + *記述子タグを得る。 + * @return + */ + abstract public int getDescriptorTag(); + /** + * 記述子を記述したbyte列を与え、解析する。 + * @param descriptor + * 記述子本体 + */ + abstract public void analyzeDescriptor(byte[] descriptor); + /** + * 記述子の一部を指定した状態で解析させる。 + * @param DescriptorTag + * 記述子のタグを指定する。 + * @param TagLength + * タグの長さ + * @param descriptor + * 記述子本体 + */ + abstract public void analyzeDescriptor(int DescriptorTag,byte[] descriptor); +} diff --git a/jTsSplitter/license-ja.txt b/jTsSplitter/license-ja.txt new file mode 100644 index 0000000..b489776 --- /dev/null +++ b/jTsSplitter/license-ja.txt @@ -0,0 +1,462 @@ +GNU 劣等一般公衆利用許諾書 (GNU Lesser General Public License)¶ + +バージョン3、2007å¹´6月29日 +日本語訳、2007å¹´9月5日 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +(訳: 本ライセンス文書を、一字一句忠実に複製、頒布することは許可する。しかし変更は認めない。) + +This is an unofficial translation of the GNU Lesser General Public License into Japanese. It was not published by the Free Software Foundation, and does not legally state the distribution terms for software that uses the GNU LGPL--only the original English text of the GNU LGPL does that. However, we hope that this translation will help Japanese speakers understand the GNU LGPL better. + +(訳: 以下はGNU Lesser General Public Licenseの非公式な日本語訳です。これはフリーソフトウェア財団 (Free Software Foundation)によって正式に発表されたものではなく、GNU LGPLが適用されたソフトウェアの頒布条件を法的に有効な形で述べたものではありません。頒布条件としては、GNU LGPLの英語版テキストで指定されているもののみが有効です。しかしながら、私たちはこの翻訳が、日本語を使用する人々にとってGNU LGPLをより良く理解する助けとなることを望んでいます。) + +翻訳は八田真行 が行った。原文はhttp://www.gnu.org/licenses/lgpl-3.0.html である。誤訳の指摘や訳の改善案を歓迎する。なお、日本語訳の利用条件は原文に準ずる。 + +このバージョンのGNU 劣等一般利用許諾書では、GNU 一般公衆利用許諾書(GNU General Public License)バージョン3が規定する利用条件を取り込んだ上で、以下に列挙する追加的許可で補足するものとする。 +0. 追加された定義¶ + +本文中で使われている通り、「本許諾書」はGNU 劣等一般公衆利用許諾書バージョン3を指す。「GNU GPL」は、GNU 一般公衆利用許諾書バージョン3を指す。 + +『ライブラリ』(The Library)とは、本許諾書の下で管理された『保護された作品』のうち、以下で定義する『アプリケーション』や『結合された作品』以外のものを指す。 + +『アプリケーション』(Application)とは、『ライブラリ』が提供するインターフェースを利用するが、『ライブラリ』を基にはしていない作品すべてのことである。『ライブラリ』によって定義されたクラスの下位クラスを定義するのは、『ライブラリ』が提供するインターフェースの利用の一形態と見なされる。 + +『結合された作品』(Combined Work)とは、『アプリケーション』と『ライブラリ』を結合ないしリンクすることによって作成された作品のことである。また、それによって『結合された作品』が作られた特定のバージョンの『ライブラリ』は、『リンクされたバージョン』(Linked Version)と呼ばれる。 + +『結合された作品』に対する『最小限の対応するソース』 (Minimal Corresponding Source)とは、『結合された作品』に対する(訳注: GPLv3における)『対応するソース』のことを意味する。ただし、『結合された作品』に含まれる部分のうち、それのみを分離して考えた場合、『アプリケーション』を基にしているが、『リンクされたバージョン』は基にしていない部分のソースコードのすべては除外される。 + +『結合された作品』に『対応するアプリケーションコード』 (Corresponding Application Code)とは、『アプリケーション』のオブジェクトコードかソースコードを意味する。『対応するアプリケーションコード』には、『アプリケーション』から『結合された作品』を再生成するために必要なデータやユーティリティ・プログラムすべてが含まれるが、『結合された作品』の『システムライブラリ』は除く。 +1. GNU GPL第3項への例外¶ + +あなたは本許諾書の第3項および第4項に従い、『保護された作品』を伝達することができる。その際、GNU GPL第3項の第2段落に束縛される必要はない。 +2. 改変されたバージョンの伝達¶ + +『ライブラリ』のコピーを改変し、かつあなたの改変点において、ある機能が (その機能が呼び出される際に引数として渡されるものを除いて)その機能を利用する『アプリケーション』から提供される関数やデータを参照する場合、以下のどちらかに従えば、あなたは改変されたバージョンのコピーを伝達することができる: + + * a) 本許諾書に従って伝達する。ただし、『アプリケーション』が関数やデータを提供しない場合でも、その機能が依然として動作し、機能の目的のうち意味あるものとして残った部分はすべて実行するよう誠実な配慮を尽くさなければならない。あるいは、 + * b) GNU GPLに従って伝達する。この場合、本ライセンス文書によってそのコピーに適用可能な追加的許可は一切認められない。 + +3. ライブラリのヘッダファイルに由来するコードや各種データを取り込んだオブジェクトコード¶ + +オブジェクトコード形式の『アプリケーション』は、『ライブラリ』の一部であるヘッダファイルに含まれるコードや各種データを取り込むことができる。あなたは、そのようなオブジェクトコードを、あなたが選択したいかなる条項の下でも複製、伝達して構わない。ただし、取り込まれたコード等が数値的パラメータや、データ構造のレイアウトやアクセサー、小さなマクロ、インライン関数やテンプレート(長さにして10行以下)ではない場合、あなたは以下の両方を行わなければならない。 + + * a) オブジェクトコードのコピーそれぞれにおいて、『ライブラリ』がその中で利用されており、『ライブラリ』とその利用は本許諾書によって保護されている旨を目立つように告知する。 + * b) オブジェクトコードに、GNU GPLと本許諾書のコピーを添付する。 + +4. 結合された作品¶ + +あなたは、『結合された作品』に含まれる『ライブラリ』部分の改変を事実上禁止したり、そのような改変をデバッグするためのリバースエンジニアリングを禁止したりしない限り、『結合された作品』をあなたが選択したいかなる条件の下でも複製、伝達して構わない。ただしその場合、以下をすべて行う必要がある: + + * a) 『ライブラリ』が『結合された作品』中で利用されており、また『ライブラリ』とその利用は本許諾書によって保護されるということを、『結合された作品』のコピーそれぞれにおいて目立つように告知する。 + * b) 『結合された作品』に、GNU GPLと本ライセンス文書のコピーを添付する。 + * c) 実行中に『コピーライト』告知を表示する『結合された作品』の場合、そういった告知文中に 『ライブラリ』の著作権告知と、ユーザに対してGNU GPLと本ライセンス文書のコピーがどこにあるかを示す参照先情報を含める。 + * d) 以下のどれか一つを行う: + o 0) 本許諾書の条項に従い、『最小限の対応するソース』を伝達する。また、『対応するアプリケーションコード』を、『対応するソース』の伝達に関して GNU GPL第6項が指定しているのと同様のやり方で、ユーザが『アプリケーション』を『ライブラリ』の改変されたバージョンと再結合または再リンクして改変された『結合された作品』を作成するのに適した形式、かつそういった再結合や再リンクを許可する条項の下で伝達する。 + o 1) 『ライブラリ』をリンクするのに適した共有ライブラリメカニズムを利用する。適したメカニズムとは、(a)実行時すでにユーザのコンピュータシステムに存在する『ライブラリ』のコピーを利用し、(b) 『リンクされたバージョン』とインターフェースに互換性がある『ライブラリ』の改変されたバージョンと共に適切に機能するものである。 + * e) 『インストール用情報』を提供する。ただしこれはGNU GPL第6項に従いそのような情報を提供することが義務付けられている場合に限られ、またそのような情報が、『リンクされたバージョン』の改変されたバージョンと『アプリケーション』を再結合ないし再リンクすることによって作成された『結合された作品』の改変されたバージョンをインストール、実行するのに必要とされる限りにおいてのみである(あなたが小項4dの0を選択する場合、『インストール用情報』は『最小限の対応するソース』と『対応するアプリケーションコード』と共に供しなければならない。あなたが小項4dの1を選択する場合、あなたは『インストール用情報』をGNU GPL第6項が『対応するソース』の伝達に関して指定するのと同様のやり方で提供しなければならない)。 + +5. 結合されたライブラリ¶ + +あなたは、『ライブラリ』を基にした作品であるライブラリ機能を、『アプリケーション』ではなく、かつ本許諾書で保護されていない他のライブラリ機能と一緒に、単一のライブラリ内で並置し、そのような結合されたライブラリをあなたが選んだ条項に従って伝達することができる。ただしその場合、以下の両方を行わなければならない。 + + * a) 結合されたライブラリに、他のいかなるライブラリ機能とも結合されておらず、本許諾書の条項に従って伝達される、元のままの『ライブラリ』を基にした作品のコピーを添付する。 + * b) その一部が『ライブラリ』を元にした作品である結合されたライブラリに、対応する結合されていない形式の同じ作品がどこで見つかるかを説明した目立つ告知を載せる。 + +6. GNU 劣等一般公衆利用許諾書の改訂されたバージョン¶ + +フリーソフトウェア財団は、改訂された、あるいは新しいバージョンのGNU 劣等一般公衆利用許諾書を折りに触れて発行することができる。そのような新バージョンは、その精神においては現在のバージョンと似たものになるだろうが、細部については新たに生じた問題や懸念を解決すべく異なるものになるだろう。 + +それぞれのバージョンには、見分けがつくようなバージョン番号が振られている。あなたが受領した『ライブラリ』において、ある特定のバージョン番号が振られたGNU 劣等一般公衆利用許諾書「かそれ以降のバージョンのいずれか (or any later version)」が適用されると指定されていた場合、あなたは指定された番号のバージョンか、それ以降にフリーソフトウェア財団によって発行されたバージョンのいずれかのバージョンのどちらの利用条件に従うかを選ぶことができる。あなたが受領した『ライブラリ』が特定のバージョン番号の GNU 劣等一般公衆利用許諾書を指定していなかった場合には、あなたはフリーソフトウェア財団がそれまでに発行したGNU 劣等一般公衆利用許諾書のバージョンの中からどれを選択しても構わない。 + +(訳注: 日本語訳のバージョンは日付で管理している。冒頭を見よ。) + +あなたが受領した『ライブラリ』において、GNU 劣等一般公衆利用許諾書の将来のバージョンのうちどれが適用されうるかは代理人が決定できる、と指定されていた場合、その代理人が、あるバージョンを受諾すると述べた公的な声明は、あなたに対し、その『ライブラリ』に関してそのバージョンのGNU LGPLを選ぶことを永続的かつ正式に許可するのと等しい。 + + + + + + +利用条件 (TERMS AND CONDITIONS)¶ +0. 定義¶ + +「本許諾書」(The License)とは、GNU 一般公衆利用許諾書のバージョン3を指す。 + +「『コピーライト』」(Copyright)とは、いわゆる著作権のみならず、半導体マスクのようなその他の作品に適用される、著作権に類似した法的権利をも意味する。 + +(訳注: この規定により、本許諾書は著作権法で保護されたいわゆる「著作物」よりも広い範囲をカバーすることになる。よってこの訳のライセンス本文中においては、work(s)に「著作物」ではなく「作品」という訳語を宛てることにした。) + +「『プログラム』」(The Program)とは、本許諾書の下でライセンスされた、『コピーライト』が主張可能な作品すべてを意味する。個々のライセンシーは「あなた」として表現される。ライセンシーは個人でも組織でも構わない。 + +ある作品の「改変」(modify)とは、その作品の全体ないし一部を、『コピーライト』の許可を必要とするようなやり方で複製ないし翻案することを意味する。ただし、完全に同一なコピーを作成する場合は除く。改変の結果出来た作品は、以前の作品の「改変されたバージョン」(modified version)、または、以前の作品を「基にした」(based on)作品と呼ばれる。 + +「『保護された作品』」(covered work)とは、改変されていない『プログラム』か、『プログラム』を基にした作品のいずれかを指す。 + +ある作品の「普及」(propagate)とは、コンピュータ上で実行すること、または私的なコピーを改変することを除き、適用可能な『コピーライト』法規の下で許可無く行うと、権利侵害として、直接的、あるいは間接的にあなたが責任を問われる何らかの行為を意味する。普及には、複製、頒布 (改変の有無を問わない)、公衆への利用可能化が含まれ、またいくつかの国々では他の活動も含まれる可能性がある。 + +ある作品の「伝達」(convey)とは、第三者がコピーを作成ないし受領するのを可能とする普及行為すべてを意味する。ただし、コンピュータネットワーク越しにユーザとやりとりするだけで、コピーの転送は伴わない場合は、伝達ではない。 + +対話的なユーザインターフェースが「『適切な法的告知』」(Appropriate Legal Notices)を表示するという場合、そのインターフェースは (1)適切な『コピーライト』告知を表示し、(2)ユーザに対して、その作品には何の保証もない(別途保証が提供されている場合は除く)ということ、ライセンシーはその作品を本許諾書の下で伝達できるということ、そして本許諾書のコピーを見るにはどうしたらよいかということを便利かつ顕著に視認できるような機能を含むものとする。もしインターフェースが、メニューのようなユーザコマンドやオプションの一覧を表示するならば、その一覧中には上記の基準を満たすようなアイテムが目立つように含まれていなければならない。 +1. ソースコード¶ + +ある作品の「ソースコード」(source code)とは、その作品に改変を加えるに当たって好ましいと考えられる形式のことである。「オブジェクトコード」 (object code)とは、作品がとりうるソースコード以外の形式すべてを意味する。 + +「標準インターフェース」(Standard Interface)とは、標準化団体として認知された組織によって定義された公式な標準か、ある特定のプログラミング言語向けに指定されたインターフェースの場合には、その言語を利用する開発者の間で広く使われているインターフェースのことを指す。 + +実行可能な作品の「『システムライブラリ』」(System Libraries)とは、 (a)「主要コンポーネント」(Major Component) の頒布物に通常含まれるが、その主要コンポーネントの一部ではなく、かつ(b)作品をその「主要コンポーネント」といっしょに利用することを可能にする、あるいは公衆にとってソースコード形式で利用可能な実装がひとつは存在する標準インターフェースを提供するためにのみ機能するものすべてを意味する。ただし、全体としての作品そのものは除く。ここでいう「主要コンポーネント」とは、実行可能な作品がその上で実行されるある特定のオペレーティングシステム (そういったものが必要ならば)の主要で不可欠な一部分(カーネルやウィンドウシステムなど)、あるいはその作品を作成するのに使われるコンパイラ、実行するのに使われるオブジェクトコードインタプリタなどを意味する。 + +オブジェクトコード形式の作品に「『対応するソース』」(Corresponding Source)とは、その作品を生成、インストール、(実行可能な作品に関しては)オブジェクトコードを実行、または作品を改変する上で必要とされるソースコードのすべてを意味する。この場合、そうした活動をコントロールするためのスクリプトは『対応するソース』に含まれるが、その作品にとっての『システムライブラリ』や、先ほど列挙した活動を行う上で改変されることなく利用されるものの作品の一部ではない、汎用のツールや一般的に利用可能なフリープログラムは除外される。例えば『対応するソース』には、その作品のソースファイルと連携するインターフェース定義ファイルに加え、共有ライブラリや動的にリンクされた下位プログラムと作品のその他の部分との間での親密なデータのやりとりやコントロールフローなどのために、その作品が設計上明確に必要とする、そうした共有ライブラリや下位プログラムのソースコードなどが含まれる。 + +『対応するソース』には、ユーザが『対応するソース』の他の部分から自動的に再生成できるものを含む必要はない。 + +ソースコード形式の作品にとっての『対応するソース』とは、その作品そのものである。 +2. 基本的な許可¶ + +本許諾書の下で認められるすべての権利は、『プログラム』に主張される『コピーライト』の条項に基づき授与されるものであり、ここで述べられた条件が満たされている限り覆すことはできない。本許諾書は、改変されていない『プログラム』をあなたが無制限に実行することを許可し、明示的に確約する。『保護された作品』を実行することから得られた出力結果は、その出力内容が『保護された作品』を構成する場合のみ本許諾書で保護される。本許諾書は、あなたが有するフェアユースまたはその同等物の権利を、『コピーライト』法規によって提供される通りに承認する。 + +その他の状況においてあなたのライセンスが有効である限り、『保護された作品』の、伝達を伴わない作成、実行、および普及は無条件に行うことができる。他者にあなた専用の改変を行わせる、あるいは他者にあなたがそういった作品を実行するための機能を提供させるということが唯一の目的であれば、『保護された作品』を他者に伝達することができる。ただしその場合、あなたが『コピーライト』を支配していない部分すべての伝達に関しては、本許諾書の条項に従わなければならない。従って、あなたのために『保護された作品』を作成または実行する者は、専らあなたのためだけに、あなたの監督と支配の下で、あなたとの関係の範囲外ではあなたが『コピーライト』を有する一部分のいかなるコピーをも作成することを禁止するという条件の下で行わなければならないということになる。 + +上記以外のあらゆる状況下においては、伝達は以下で述べる条件の下でのみ許可される。再許諾は認められない。下記第10項により、再許諾は必要ないからである。 +3. ユーザの法的権利を、技術的保護手段の回避を禁ずる法律から守る¶ + +『保護された作品』は、 1996å¹´12月20日に採択されたWIPO著作権条約第11項の下での義務を満たす適用可能な法のいずれか、あるいはそれに類似の法が、回避の禁止または制限の対象として規定する、「効果的な技術的手段」 (effective technological measure)の一部として見なされてはならない。 + +(訳注: WIPO著作権条約については、http://www.cric.or.jp/db/article/wch.html 等を参照せよ。) + +あなたが『保護された作品』を伝達する場合、『保護された作品』に関して本許諾書の下で権利を行使することにより、技術的手段の回避に影響が出る範囲において、そのような手段の回避を禁じるいかなる法的権力をも放棄することになる。また、あなたはその作品のユーザに対して、技術的手段の回避を禁じるためにあなたや第三者の法的権利を強制するための手段として、その作品の動作や改変を制限するいかなる意図も否認することになる。 +4. 一字一句忠実なコピーの伝達¶ + +あなたは、自分が受領した『プログラム』のソースコードと一字一句同じコピーであれば、いかなる媒体でも伝達することができる。ただしその場合、あなたはそれぞれのコピーにおいて、目立つように、かつ適切な形で、ふさわしい『コピーライト』告知を掲載しなければならない。すなわち、本許諾書と、下記第7項に従い追加された非許可的条項のすべてがそのコードに適用される旨の告知を掲載し、あらゆる保証が存在しない旨の告知をすべてそのまま保全し、かつ『プログラム』の受領者すべてに、『プログラム』といっしょにこの許諾書のコピーを与えなければならない。 + +あなたは、自分が伝達するコピーのそれぞれに関していかなる価格を付けても良いし、無料で伝達しても構わない。また、報酬を取ってサポートや保証保護 (warranty protection)を提供しても良い。 +5. 改変されたバージョンのソースの伝達¶ + +あなたは、『プログラム』を基にした作品、あるいはそうした作品を『プログラム』から作成するための改変点を、上記第4項の規定に従ってソースコード形式で伝達することができる。ただしその場合、あなたは以下に示す条件のすべてを満たさなければならない: + + * a) 作品には、あなたが作品を改変したということと、改変に関連した日時を記述した告知を目立つように載せなければならない。 + * b) 作品には、それが本許諾書と、下記第7項に従って追加された条件すべての下で公開されていることを記述した告知を目立つように載せなければな らない。この条件は、上記第4項における「告知をすべてそのまま保全」するための条項を改変する。 + * c) 作品の全部分を、総体として、コピーを所有するに至った人全員に、本許諾書の下でライセンスしなければならない。そこで、本許諾書は、本許諾書第7項に基づく適用可能な追加的条項のすべてとともに、作品全体に、すなわちその全部分に、それらがどのようにパッケージされているかに関わらず適用されることになる。本許諾書は、これ以外のやり方には作品をライセンスする許可を与えないが、あなたが本許諾書以外で別途許可を得ていた場合には、それによって得られた許可まで無効とするものではない。 + * d) 改変された作品が対話的なユーザインターフェースを有する場合、それらのインターフェースは『適切な法的告知』を表示しなければならない。ただし、『プログラム』に元々『適切な法的告知』を表示しない対話的なインターフェースがある場合、あなたの作品で表示するようにする必要はない。 + +一巻の記憶装置の中か頒布媒体上で、『保護された作品』と、本来『保護された作品』の拡張ではなく、『保護された作品』とより大規模なプログラムを形成するような形で結合されているわけでもないその他の分離かつ独立した作品とをまとめた編集物は、編集作業とそれに由来する『コピーライト』が、個々の作品が許可する範囲を越えて編集物のユーザの作品へのアクセスや法的権利を制限するのに使われない限り、「集積物」(aggregate)と呼ばれる。単に『保護された作品』を集積物に含めるだけでは、その集積物の他の部分にまで本許諾書が適用されるということにはならない。 +6. ソース以外の形式における伝達¶ + +あなたは、オブジェクトコード形式の『保護された著作物』を、上記第4項および第5項の規定に従って伝達することができる。ただしその場合、あなたは機械読み取り可能な『対応するソース』も本許諾書の条件に従って、以下のいずれかの方法で伝達しなければならない。 + + * a) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、『対応するソース』を、ソフトウェア のやりとりで一般的に使われる耐久性のある物理的媒体に固定していっしょに頒布する。 + * b) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、最低でも3年間、あるいはあなたがその製品モデルに補修用部品やカスタマーサポートを提供する限り有効な、書面 による申し出を添付する。その申し出には、(1) オブジェクトコードを所有する者すべてに対して、その製品に含まれるソフトウェアのうち本許諾書で保護されるものすべてに『対応するソース』のコピーを、ソフトウェアのやりとりで一般的に使われる耐久性のある物理的媒体で頒布する旨を記載する。その際、物理的にこのソースの伝達を行うのにかかる正当なコスト以上の価格を要求してはならない。あるいは、(2) 『対応するソース』を無料でネットワークサーバから複製するためのアクセスを提供する旨を記載する。 + * c) オブジェクトコードの個々のコピーを、対応するソースを提供するという書面による申し出のコピーといっしょに伝達する。この選択肢は特別な場合、かつ非商業的な場合のみに、そしてあなたがオブジェクトコードを上記小項 6bに合致した申し出といっしょに受領した場合にのみに認められる。 + * d) オブジェクトコードを、指定の場所から複製するためのアクセスを提供することによって伝達し、『対応するソース』に対しても同じ場所を通じて同じ方法で複製するための同等のアクセスを提供する。伝達は無料でも手数料を課しても構わないが、『対応するソース』に対して追加的な課金を行ってはならない。受領者に対して、『対応するソース』をオブジェクトコードといっしょに複製することを義務づける必要はない。オブジェクトコードの複製元がネットワークサーバの場合、対応するソースは同等の複製機能をサポートする異なったサーバ(あなたか第三者が運営)上にあっても良い。その場合、オブジェクトコードの傍らに、『対応するソース』はどこで見つけられるかを明確に指示しておかなければならない。どのサーバが『対応するソース』をホストするかに関わらず、あなたは『対応するソース』がこれらの条 項を満たすために必要なかぎり利用可能であることを保証する責任がある。 + * e) オブジェクトコードをピア・ツー・ピア伝送を使って伝達する。ただしこの場合、あなたは上記小項6dに従い、その作品のオブジェクトコードと 『対応するソース』がどこで一般公衆に無料で提供されるのかということを他のピアに知らせておかなければならない。 + +オブジェクトコードの分離した一部であり、そのソースコードが『対応するソース』から『システムライブラリ』として除外されているものは、オブジェクトコード作品を伝達する場合に含める必要はない。 + +「ユーザ製品」(User Product)とは、(1)「コンシューマ製品」(consumer product)、すなわち、個人、子供、あるいは家庭用に通常使用される有形個人資産すべてか、あるいは(2)居住所における導入を目的に設計ないし販売されるものすべてを指す。ある物品がコンシューマ製品であるかを決定する際疑義がある場合には、極力範囲を広げる方向で決定されるべきである。ここで、ある特定のユーザによって受領されたある特定の製品にとっての「通常使用」 (nomally used)とは、その種の製品において典型的な、あるいは一般的な利用のことであり、その特定のユーザが置かれた状況や、その特定のユーザがその製品を実際にどう使っているか、どう使うことを予期しているか、あるいは予期されているかとは関係ない。その製品に相当な商業的、産業的または非コンシューマ的な利用法があったとしても、そうした利用がその製品の唯一重要な利用形態を代表するものでない限り、その製品はコンシューマ製品である。 + +ユーザ製品の「『インストール用情報』」(Installation Information)とは、ユーザ製品内の『保護された作品』に関して、『対応するソース』の改変されたバージョンから得られる『保護された作品』の改変されたバージョンを、インストール、実行するために必要な手法、手順、認証キーやその他の情報すべてを意味する。この情報は、改変されたオブジェクトコードの継続的な動作が、改変が為されたということによってのみ拒否されたり妨害されることが決してないことを保証するのに十分なものでなければならない。 + +本節の下において、作品をユーザ製品の内で、またはユーザ製品と共に、あるいは特にユーザ製品での利用を念頭においてオブジェクトコードで伝達し、またその伝達がユーザ製品の受領者への所有と利用の権利の永遠ないし有期の移転の一部として起こる場合(移転がどのように行われるかは問わない)、この条項の下で『対応するソース』は『インストール用情報』と共に提供されなければならない。しかしこの条件は、あなたと第三者のいずれもが改変されたオブジェクトコードをユーザ製品にインストールする能力を有していない際には適用されない(例えば、作品がROMにインストールされている場合)。 + +『インストール用情報』を提供する条件には、受領者によって改変ないしインストールされた作品、あるいはそうした作品が改変ないしインストールされたユーザ製品に対し、サービスや保証、アップデートを提供しつづけるという条件は含まれない。改変自体がネットワークの運用に実質的かつ有害な影響をもたらし、ネットワークを介したコミュニケーションのプロトコルや規則に違反する場合には、ネットワークアクセスを拒否しても構わない。 + +伝達される『対応するソース』や提供される『インストール用情報』が本節を満たすためには、それらが公に文書化された形式で(かつ公衆に対してソースコード形式で利用可能な実装とともに)提供されなければならない。この場合、これらの圧縮展開や読み込み、複製に特別なパスワードやキーを必要としてならない。 +7. 追加的条項¶ + +「追加的許可」(Additional permissions)とは、本許諾書が課す条件に一つかそれ以上の例外を設けることにより、本許諾書の条項を補足する条項のことである。『プログラム』全体に適用可能な追加的許可は、適用可能な法の下でそれらが有効である限り、あたかもそれらが本許諾書に含まれているかのように扱われなければならない。追加的許可が『プログラム』の一部にのみ適用される場合、その部分に関してはそういった追加的許可の下で別途利用可能だが、『プログラム』全体としては追加的許可に関わりなく本許諾書によってのみ管理される。 + +あなたが『保護された作品』のコピーを伝達する場合、あなたは追加的許可をそのコピー、あるいはその一部から削除することを選択できる (追加的許可は、あなたが作品をある種の形で改変する際には、そうした許可自身の削除を要求するような形で書かれてもよい)。あなたは、あなたによって『保護された作品』に追加され、あなたが適切な『コピーライト』許可を有するか、与えることができる限り、その一部分に追加的許可を設定することができる。 + +本許諾書の他の条件に関わらず、あなたが『保護された作品』に追加した一部分について(その部分の『コピーライト』保有者らによって正式に許可されていれば)、本許諾書の条項を、以下に示す条項で補足することができる: + + * a) 本許諾書第15項および第16項の条項とは異なった形で保証の否認や責任の限定を主張する。あるいは、 + * b) 追加した一部分において、明示的で妥当な法的告知や作者特定の保全、またはそれを含む作品において『適切な法的告知』の表示を要求する。あるいは、 + * c) 追加した一部分の出自を不当に表示することを禁じるか、あるいはそのような一部分の改変されたバージョンはオリジナルのバージョンとは異なっ ているということを適切な方法で印づけることを要求する。あるいは、 + * d) その一部分のライセンサーや作者の名前を、宣伝目的で利用することを制限する。あるいは、 + * e) 商品名や商標、サービスマークの利用に関して、商標法に従い権利を授与することを拒否する。あるいは、 + * f) その一部分(あるいはその改変されたバージョン)を伝達する者に、受領 者への責任に関して契約上の引き受けがあり、そうした責任が直接的にそういったライセンサーや作者にまで課せられる場合、その一部分のライセンサーや作者の免責を要求する。 + +他の非許可的な追加的条項は下記第10項が意味するところの「さらなる権利制限」(further restrictions)とみなされる。あなたが受領した『プログラム』、あるいはその一部に、それが本許諾書とともにさらなる権利制限である条項によっても管理されていると述べた告知が含まれている場合には、あなたはそういった条項を削除して構わない。あるライセンス文書にさらなる権利制限がふくまれているが、しかし本許諾書の下での再許諾や伝達を許可しているならば、あなたはそのライセンス文書の条項によって管理されている一部分を『保護された作品』に追加することができる。ただしその場合、さらなる権利制限はそのような再許諾や伝達では無効としなければならない。 + +あなたが本節に従って『保護された著作物』に条項を追加した場合、あなたは関係するソースファイル中に、それらのファイルに適用される追加的条項に関する声明、あるいは適用可能な条項を見つけることができる場所を示す告知を掲載しなければならない。 + +追加的条項は、それが許可的であろうと非許可的であろうと、別途書面化されたライセンスという形式で述べられてもよいし、本許諾書への例外として述べられてもよい。上記の要件はどちらの場合でも適用される。 +8. 終了¶ + +あなたは『保護された作品』を、本許諾書の下で明示的に提供されている場合を除いて、普及、または改変してはならない。それ以外に『保護された作品』を普及、または改変しようとする試みはすべて無効であり、本許諾書の下であなたに認められた権利(下記第11項の第3段落に従い授与されたパテントライセンスすべてを含む)を自動的に終了させることになる。 + +しかしながら、あなたが本許諾書への違反をすべて中止するならば、あなたがある特定の『コピーライト』保有者から得たライセンスは、(a)その『コピーライト』保有者が明白かつ決定的にあなたへのライセンスを終了させるか、あるいはさせないまでは暫定的に、(b)その『コピーライト』保有者が、あなたに対し違反について、何らかの正当な手段によりライセンス停止後60日以内に通知することができなかった場合には永続的に、回復される。 + +加えて、あなたがある特定の『コピーライト』保有者から得たライセンスは、その『コピーライト』保有者があなたに対して違反を何らかの正当な手段で通知し、それより前にその『コピーライト』保有者から、(当該作品に限らずその『コピーライト』保有者の作品のいずれかに関して)本許諾書に関する違反の通知を受領したことがなく、さらにあなたがその通知を受領してから30日以内に違反を正した場合、永続的に回復される。 + +本節に従いあなたの権利が終了した場合でも、本許諾書に従ってあなたからコピーや権利を受領した当事者が得た許諾は終了しない。あなたの権利が終了され、永続的に回復されなかった場合には、あなたは同じライセンス対象に関し下記第10項に従って新たにライセンスを受領する資格を失うものとする。 +9. コピーの所有に必要とされない受諾¶ + +あなたは、『プログラム』のコピーを受領あるいは実行するために本許諾書を受諾する必要はない。コピーを受領するためにピア・ツー・ピア伝送を使った結果としてのみ発生する『保護された作品』の付随的な普及も、同様に受諾を必要としない。しかしながら、他の場合においては、本許諾書以外にあなたに対して『保護された作品』の普及や改変をする許可を認めるものはない。これらの行為は、本許諾書を受諾しない限り『コピーライト』を侵害することになる。そこで、『保護された作品』を改変あるいは普及することにより、あなたはそうした行為を行うために本許諾書を受諾したということを示したことになる。 +10. 下流の受領者への自動的許諾¶ + +あなたが『保護された作品』を伝達するたびに、受領者は自動的にオリジナルのライセンサーから、本許諾書に従いその作品を実行、改変、普及するライセンスを得る。なお、あなたには第三者が本許諾書に従うことを強制する責任はない。 + +「主体取引」(entity transaction)とは、ある組織そのもの、ないしその組織の実質的に全ての資産の支配権が移転するか、あるいは組織の細分化や合併が行われるような取引を指す。もし主体取引の結果として『保護された作品』の普及が起こった場合、作品のコピーを受領したそれぞれの取引当事者は、利害関係のある当事者の先任者から、その先任者が前段落に従って有する、あるいは与えることができる、その作品に関するライセンスもまたすべて受領する。加えて個々の取引当事者は、利害関係のある先任者から、その先任者が有しているか、適正な努力によって得ることが可能な限りにおいて、その作品の『対応するソース』の所有権も得る権利を有する。 + +あなたは本許諾書の下で授与された、あるいは確約された権利の行使に対して、本許諾書が規定する以上のさらなる権利制限を課してはならない。たとえば、あなたはライセンス料、ロイヤルティや他の料金を、本許諾書の下で認められている権利の行使に関して課してはならない。また、あなたは『プログラム』やその一部の作成、利用、販売、販売の申し出、取り込みによって何らかのパテントクレームが侵害されたとして、訴訟(訴訟における反対請求ないし反訴を含む)を開始してはならない。 +11. 特許¶ + +「貢献者」(contributor)とは、本許諾書の下で『プログラム』、あるいは『プログラム』が基にした作品を利用することを正式に許可した『コピーライト』保有者のことを指す。従って、そのようにしてライセンスされた作品は、貢献者による「貢献者バージョン」(contributor version)と呼ばれる。 + +ある貢献者の「必須パテントクレーム」(essential patent claims)とは、すでに取得しているか、あるいは今後取得する見込みがあるため、その貢献者が現在所有ないし支配していると言える特許のうち、貢献者バージョンに対して、本許諾書で許可されているような作成や利用、販売といった何らかの形の行為を行うことによって侵害される可能性があるパテントクレームのすべてを意味する。ただし、貢献者バージョンをさらに改変した結果としてのみ侵害されるようなクレームは含まれない。この定義において、「支配」には本許諾書が課す条件と整合的なやり方で特許の再許諾を認める権利も含まれる。 + +個々の貢献者はあなたに対して、その貢献者の必須パテントクレームに関し、あなたがその貢献者バージョンの内容を作成、利用、販売、販売の申し出、取り込み、その他実行、改変、普及するために必要な、非排他的で全世界的に有効、かつロイヤルティフリーのパテントライセンスを授与する。 + +以下の3段落において「『パテントライセンス』」とは、ある特許を実施しないという明示的な協定やコミットメントのすべてを指す(例えば、ある特許の実施に対する明示的な許可や、特許侵害訴訟を提起しないという誓約など)。そのような『パテントライセンス』をある当事者に「授与」するとは、その当事者と特許を実施しないという協定やコミットメントを結ぶことを意味する。 + +もしあなたが、『保護された作品』の伝達を、それがある『パテントライセンス』に依存しており、よってその作品の『対応するソース』は、すべての人にとって、公衆が利用可能なネットワークサーバや他の容易にアクセス可能な手段を通じ、無料かつ本許諾書に従って複製可能ではないということを知りながら行うならば、あなたは (1)『対応するソース』も同様に利用可能にするか、 (2)この特定の作品に関して『パテントライセンス』から得られる便益を自ら剥奪するか、あるいは(3)下流の受領者に対しても、本許諾書の条項と整合的な形で、『パテントライセンス』が拡大されるように計らうかのいずれかを行わなければならない。ここで「『パテントライセンス』に依存するのを知りながら」というのは、あなたが『保護された作品』をある国で伝達すること、あるいはあなたの受領者が『保護された著作物』をある国で利用することが、『パテントライセンス』を授与されない限り、その国において、あなたにとってそれが有効だと信じるだけの理由がある一つかそれ以上の同定可能な特許を侵害するということを実際に知っているということである。 + +ある一対一の取引や協定に基づき、あるいは関連して、あなたが『保護された作品』の伝達、または伝達によって引き起こされる普及を行い、その際『保護された作品』を受領した一部の当事者に対して、『保護された作品』の特定のコピーの利用、普及、改変、または伝達を正式に許可するような『パテントライセンス』を授与するならば、あなたが授与した『パテントライセンス』は『保護された作品』やそれを基にした作品のすべての受領者にまで自動的に拡大されることになる。 + +ある『パテントライセンス』が「差別的」(discriminatory)であるとは、本許諾書の下で明確に認められた一つかそれ以上の権利を、『パテントライセンス』がカバーする範囲内に含まなかったり、そうした権利の行使を禁じたり、あるいは権利を行使しないことを条件として課すようなものである場合を指す。あなたを一方の当事者とし、ソフトウェアの頒布を生業とする第三者との間で、あなたは第三者に対し、作品を伝達する活動の程度に基づいて支払いを行う一方、第三者は、あなたから『保護された作品』を受領したすべての当事者に対して「差別的」な『パテントライセンス』を、(a)あなたが伝達した『保護された作品』のコピー(またはそうしたコピーから作成されたコピー)に対して、または(b)『保護された作品』を含む特定製品や編集物を、主要な、あるいは関連した対象として授与する、というような協定を結んでいる場合、あなたは『保護された作品』を伝達してはならない。ただし、あなたがそのような協定を締結したり、『パテントライセンス』を授与されたのが2007å¹´3月28日より以前である場合は本節の例外とする。 + +本許諾書に含まれる一切の記述は、適用可能な特許法の下であなたが利用可能な暗黙のライセンス、その他侵害への防御手段を排除したり制限したりするように解釈されてはならない。 +12. 他者の自由を明け渡してはならない¶ + +何らかの条件(裁判所の指令や協定など)があなたに課せられ、それが本許諾書の条件と矛盾したとしても、あなたが本許諾書の条件を免れることにはならない。あなたが、『保護された作品』を、本許諾書が課す義務と他の関連した義務の両方を同時に満たすような形で伝達できないのであれば、結果としてあなたがそれを伝達することは全く不可能ということになる。例えばあなたが、自分が『プログラム』を伝達した人々がさらに伝達を行う場合には、彼らからロイヤルティを徴収する、というような義務を負う条項に同意していた場合、あなたがそういった条項と本許諾書の両方を満たすには、『プログラム』の伝達を完全に止めてしまうしかないだろう。 +13. GNU Affero 一般公衆利用許諾書との利用¶ + +本許諾書に含まれる他の条件に関わらず、あなたには、『保護された作品』を GNU Affero 一般公衆利用許諾書バージョン3の下で許諾された作品とリンクまたは結合して単一の結合物とし、その結果物を伝達する許可が与えられる。本許諾書の条項は『保護された作品』である部分に関してはそのまま適用されるが、結合物それ自体としては、GNU Affero 一般公衆利用許諾書の第13項が規定する、ネットワークを介したやりとりに関する特殊な条件も適用されることになる。 + +(訳注: 訳出時点では、GNU Affero GPLは改定作業が依然続いており、確定バージョンはリリースされていない。 http://gplv3.fsf.org/agplv3-dd2-guide.htmlを参照せよ。) +14. 本許諾書の改訂されたバージョン¶ + +フリーソフトウェア財団は、改訂された、あるいは新しいバージョンの GNU 一般公衆利用許諾書を折りに触れて発行することができる。そのような新バージョンは、その精神においては現在のバージョンと似たものになるだろうが、細部については新たな問題や懸念を解決すべく異なるものになるだろう。 + +それぞれのバージョンには、見分けがつくようなバージョン番号が振られている。『プログラム』に、ある特定のバージョン番号が振られた GNU 一般公衆利用許諾書「かそれ以降のバージョンのいずれか(or any later version)」が適用されると指定されていた場合、あなたは指定された番号のバージョンか、それ以降にフリーソフトウェア財団によって発行されたいずれかのバージョンのどちらの利用条件に従うかを選ぶことができる。『プログラム』が本許諾書のバージョン番号を指定していなかった場合には、あなたはフリーソフトウェア財団がそれまでに発行したバージョンの中からどれを選択しても構わない。 + +(訳注: 日本語訳のバージョンは日付で管理している。冒頭を見よ。) + +『プログラム』において、GNU 一般公衆利用許諾書の将来のバージョンのうちどれが適用されうるかは代理人が決定できる、と指定されていた場合、その代理人が、あるバージョンを受諾すると述べた公的な声明は、あなたに対し、その『プログラム』に関してそのバージョンのGNU GPLを選ぶことを永続的かつ正式に許可するのと等しい。 + +本許諾書の今後のバージョンでは、あなたに追加的な、または従来とは異なった形での許可を与えるかもしれない。しかしながら、作者や『コピーライト』保有者に対し、あなたが以降のバージョンに従うことを選んだ結果として、追加的な義務が課せられることはない。 +15. 保証の否認¶ + +『プログラム』には、適用可能な法で許可されている範囲において何の保証もない。書面で述べられていない限り、『コピーライト』保有者やその他の当事者は『プログラム』を「あるがまま(as is)」で、明示的、暗示的を問わず、いかなる種類の保証もなく提供する。この保証には、商用可能性や特定目的への適合性の暗黙的保証が含まれるが、これらに限定されない。『プログラム』の質や性能に関するリスクはすべてあなたに帰属する。『プログラム』に問題があると判明した場合、あなたは必要なすべての対応、補修、修正にかかる費用を負うものとする。 +16. 責任の限定¶ + +適用可能な法において義務づけられるか、書面による同意がない限り、『コピーライト』保有者あるいはその他『プログラム』を上記で許可された通りに改変あるいは伝達する当事者は、たとえそうした保有者や他の当事者が損害が発生する可能性について事前に通知されていたとしても、あなたに対して損害賠償責任を有することはない。ここでいう損害には、『プログラム』の利用あるいは利用できないことから発生した一般的、特殊的、偶然的、必然的な損害のすべてが含まれる(データの消失やデータの不正確な解釈、あなたや第三者によって被った、あるいは『プログラム』が他のプログラムといっしょにうまく動作しなかったために引き起こされた損害などが含まれるが、これらに限定されない)。 +17. 第15項と第16項の解釈について¶ + +上記のような保証の否認や責任の限定が、特定国内においてそういった条項が指定する通りの法的効力を持ち得ない場合、再審裁判所は、『プログラム』に関連したすべての民事責任の絶対的棄権に最も近く肉薄する国内法を適用すべきである。ただし、報酬の見返りとして責任の保証や引き受けが『プログラム』のコピーに付随する場合は除く。 + + + + +GNU 一般公衆利用許諾書 (GNU General Public License)¶ + +バージョン3、2007å¹´6月29日 +日本語訳、2007å¹´9月5日 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +(訳: 本ライセンス文書を、一字一句忠実に複製、頒布することは許可する。しかし変更は認めない。) + +This is an unofficial translation of the GNU General Public License into Japanese. It was not published by the Free Software Foundation, and does not legally state the distribution terms for software that uses the GNU GPL--only the original English text of the GNU GPL does that. However, we hope that this translation will help Japanese speakers understand the GNU GPL better. + +(訳: 以下はGNU General Public Licenseの非公式な日本語訳です。これはフリーソフトウェア財団 (Free Software Foundation)によって正式に発表されたものではなく、GNU GPLが適用されたソフトウェアの頒布条件を法的に有効な形で述べたものではありません。頒布条件としては、GNU GPLの英語版テキストで指定されているもののみが有効です。しかしながら、私たちはこの翻訳が、日本語を使用する人々にとってGNU GPLをより良く理解する助けとなることを望んでいます。) + +翻訳は八田真行 が行った。原文はhttp://www.gnu.org/licenses/gpl-3.0.html である。誤訳の指摘や訳の改善案を歓迎する。なお、日本語訳の利用条件は原文に準ずる。 +はじめに¶ + +GNU 一般公衆利用許諾書は、ソフトウェアやその他の種類の著作物のための、フリーかつコピーレフトを主張するライセンスです。 + +ソフトウェアやその他の実用的著作物向けのライセンスの大半は、あなたから著作物を共有したり変更したりする自由を奪い去るよう設計されています。それらとは対照的に、GNU 一般公衆利用許諾書は、あなたに対してあるプログラムの全てのバージョンを共有、変更する自由を保証すること、すなわち、そのソフトウェアがそのユーザすべてにとってフリーでありつづけることを保証することを目的としています。私たちフリーソフトウェア財団(Free Software Foundation)は、GNU 一般公衆利用許諾書を私たちのソフトウェアの大半に適用しています。その作者が私たちと同様の方法で公開するならば、他のいかなる著作物にも適用することが可能です。もちろん、あなたのプログラムにも適用することができます。 + +私たちがフリーソフトウェアについて語るとき、私たちは自由について言及しているのであって、価格は問題にしていません。私たちが用意した一般公衆利用許諾書の数々は、フリーソフトウェアのコピーを頒布する(そして希望によっては頒布に際して手数料を要求する)自由をあなたに保証すべく設計されています。すなわち、ソースコードを受領するか、望めばそれを手に入れられるということ、ソフトウェアを変更し、その一部を新たなフリープログラムで利用することができるということ、そしてこうしたことが可能であることをあなたが知っているということが保証されるのです。 + +(訳注: GNU GPL以外の一般公衆利用許諾書として、GNU AGPLとGNU LGPLが用意されている。) + +あなたの権利を守るため、私たちは誰か他人が上記のようなあなたの権利を否定したり、権利を放棄するように求めることを防ぐ必要があります。そこで、あなたがソフトウェアのコピーを頒布したり改変したりする場合、あなたにはある種の責任が発生します。それは、他人の自由を尊重するという責任です。 + +たとえば、本許諾書が適用されたプログラムのコピーをあなたが頒布する場合、それが無料であろうと手数料を取る場合であろうと、あなたは受領者たちに、あなた自身が受け取ったのと同じ自由を渡さなければなりません。あなたは、彼らもまた、ソースコードを受領するか後に得られることを保証しなければなりません。そしてあなたは、彼らに本許諾書の条項を示し、彼らの権利について彼らに知らしめなければなりません。 + +GNU GPLを利用する開発者は、あなたの権利を2段階の手順を踏んで守ります。その手順とは、(1) ソフトウェアに著作権を主張し、(2) あなたに本許諾書を提示して、ソフトウェアを複製、頒布、または改変する法的な許可を与える、というものです。 + +開発者や作者を守るため、GPLでは、このフリーソフトウェアには何の保証もないということを明確に説明しています。ユーザと開発者両方の便宜のため、 GPLでは改変されたバージョンには変更された旨を印づけるよう要求しており、改変されたバージョンの問題が、誤って以前のバージョンの作者に帰せられることがないようにしています。 + +一部の機器は、それらに収録されたソフトウェアを改変した上で再びインストールしたり、実行したりするために必要なアクセスを、製造者には拒否しないにもかわらずユーザに対しては拒否するよう設計されています。これは、ユーザが自らの有するソフトウェアを変更する自由を守るというGPLの目的とは、根本的に相容れません。このような技術の濫用は、往々にして個人使用向けの製品の分野で見られるものですが、まさにこのような分野こそ、こうした慣行が最も容認しがたいものとなるのです。そこで私たちは、このバージョンのGPLを、そうした製品においてこの種の慣行を禁止するように設計しました。もし同種の問題が他の領域にまで相当程度広がってきた場合には、私たちはユーザの自由を守るためのに必要とされるだけ、GPLの将来のバージョンにおいてこの規定をそうした領域にも拡大すべく準備を整えています。 + +最後に、すべてのプログラムはソフトウェア特許によって絶え間なく脅かされています。およそ国家は、特許が汎用コンピュータにおけるソフトウェアの開発と利用を制限することを認めるべきではありません。しかし、そういったことを認めてしまっている地域においては、私たちは、特許がフリーなプログラムに適用され、実質的にプログラムがプロプライエタリにされてしまうという特別な脅威を避けたいと思います。こうした事態を防ぐために、GPLでは、プログラムを非フリーとするために特許を使うことはできないということを保証します。 + +(訳注: 本許諾書で「プロプライエタリ (proprietary)」とは、ソフトウェアの利用や再頒布、改変が禁止されているか、許可を得ることが必要とされているか、あるいは厳しい制限が課せられていて自由にそうすることが事実上できなくなっている状態のことを指す。詳しくはhttp://www.gnu.org/philosophy/categories.ja.html#ProprietarySoftware をを参照せよ。) + +複製、頒布、改変に関する正確な利用条件は以下で述べていきます。 +利用条件 (TERMS AND CONDITIONS)¶ +0. 定義¶ + +「本許諾書」(The License)とは、GNU 一般公衆利用許諾書のバージョン3を指す。 + +「『コピーライト』」(Copyright)とは、いわゆる著作権のみならず、半導体マスクのようなその他の作品に適用される、著作権に類似した法的権利をも意味する。 + +(訳注: この規定により、本許諾書は著作権法で保護されたいわゆる「著作物」よりも広い範囲をカバーすることになる。よってこの訳のライセンス本文中においては、work(s)に「著作物」ではなく「作品」という訳語を宛てることにした。) + +「『プログラム』」(The Program)とは、本許諾書の下でライセンスされた、『コピーライト』が主張可能な作品すべてを意味する。個々のライセンシーは「あなた」として表現される。ライセンシーは個人でも組織でも構わない。 + +ある作品の「改変」(modify)とは、その作品の全体ないし一部を、『コピーライト』の許可を必要とするようなやり方で複製ないし翻案することを意味する。ただし、完全に同一なコピーを作成する場合は除く。改変の結果出来た作品は、以前の作品の「改変されたバージョン」(modified version)、または、以前の作品を「基にした」(based on)作品と呼ばれる。 + +「『保護された作品』」(covered work)とは、改変されていない『プログラム』か、『プログラム』を基にした作品のいずれかを指す。 + +ある作品の「普及」(propagate)とは、コンピュータ上で実行すること、または私的なコピーを改変することを除き、適用可能な『コピーライト』法規の下で許可無く行うと、権利侵害として、直接的、あるいは間接的にあなたが責任を問われる何らかの行為を意味する。普及には、複製、頒布 (改変の有無を問わない)、公衆への利用可能化が含まれ、またいくつかの国々では他の活動も含まれる可能性がある。 + +ある作品の「伝達」(convey)とは、第三者がコピーを作成ないし受領するのを可能とする普及行為すべてを意味する。ただし、コンピュータネットワーク越しにユーザとやりとりするだけで、コピーの転送は伴わない場合は、伝達ではない。 + +対話的なユーザインターフェースが「『適切な法的告知』」(Appropriate Legal Notices)を表示するという場合、そのインターフェースは (1)適切な『コピーライト』告知を表示し、(2)ユーザに対して、その作品には何の保証もない(別途保証が提供されている場合は除く)ということ、ライセンシーはその作品を本許諾書の下で伝達できるということ、そして本許諾書のコピーを見るにはどうしたらよいかということを便利かつ顕著に視認できるような機能を含むものとする。もしインターフェースが、メニューのようなユーザコマンドやオプションの一覧を表示するならば、その一覧中には上記の基準を満たすようなアイテムが目立つように含まれていなければならない。 +1. ソースコード¶ + +ある作品の「ソースコード」(source code)とは、その作品に改変を加えるに当たって好ましいと考えられる形式のことである。「オブジェクトコード」 (object code)とは、作品がとりうるソースコード以外の形式すべてを意味する。 + +「標準インターフェース」(Standard Interface)とは、標準化団体として認知された組織によって定義された公式な標準か、ある特定のプログラミング言語向けに指定されたインターフェースの場合には、その言語を利用する開発者の間で広く使われているインターフェースのことを指す。 + +実行可能な作品の「『システムライブラリ』」(System Libraries)とは、 (a)「主要コンポーネント」(Major Component) の頒布物に通常含まれるが、その主要コンポーネントの一部ではなく、かつ(b)作品をその「主要コンポーネント」といっしょに利用することを可能にする、あるいは公衆にとってソースコード形式で利用可能な実装がひとつは存在する標準インターフェースを提供するためにのみ機能するものすべてを意味する。ただし、全体としての作品そのものは除く。ここでいう「主要コンポーネント」とは、実行可能な作品がその上で実行されるある特定のオペレーティングシステム (そういったものが必要ならば)の主要で不可欠な一部分(カーネルやウィンドウシステムなど)、あるいはその作品を作成するのに使われるコンパイラ、実行するのに使われるオブジェクトコードインタプリタなどを意味する。 + +オブジェクトコード形式の作品に「『対応するソース』」(Corresponding Source)とは、その作品を生成、インストール、(実行可能な作品に関しては)オブジェクトコードを実行、または作品を改変する上で必要とされるソースコードのすべてを意味する。この場合、そうした活動をコントロールするためのスクリプトは『対応するソース』に含まれるが、その作品にとっての『システムライブラリ』や、先ほど列挙した活動を行う上で改変されることなく利用されるものの作品の一部ではない、汎用のツールや一般的に利用可能なフリープログラムは除外される。例えば『対応するソース』には、その作品のソースファイルと連携するインターフェース定義ファイルに加え、共有ライブラリや動的にリンクされた下位プログラムと作品のその他の部分との間での親密なデータのやりとりやコントロールフローなどのために、その作品が設計上明確に必要とする、そうした共有ライブラリや下位プログラムのソースコードなどが含まれる。 + +『対応するソース』には、ユーザが『対応するソース』の他の部分から自動的に再生成できるものを含む必要はない。 + +ソースコード形式の作品にとっての『対応するソース』とは、その作品そのものである。 +2. 基本的な許可¶ + +本許諾書の下で認められるすべての権利は、『プログラム』に主張される『コピーライト』の条項に基づき授与されるものであり、ここで述べられた条件が満たされている限り覆すことはできない。本許諾書は、改変されていない『プログラム』をあなたが無制限に実行することを許可し、明示的に確約する。『保護された作品』を実行することから得られた出力結果は、その出力内容が『保護された作品』を構成する場合のみ本許諾書で保護される。本許諾書は、あなたが有するフェアユースまたはその同等物の権利を、『コピーライト』法規によって提供される通りに承認する。 + +その他の状況においてあなたのライセンスが有効である限り、『保護された作品』の、伝達を伴わない作成、実行、および普及は無条件に行うことができる。他者にあなた専用の改変を行わせる、あるいは他者にあなたがそういった作品を実行するための機能を提供させるということが唯一の目的であれば、『保護された作品』を他者に伝達することができる。ただしその場合、あなたが『コピーライト』を支配していない部分すべての伝達に関しては、本許諾書の条項に従わなければならない。従って、あなたのために『保護された作品』を作成または実行する者は、専らあなたのためだけに、あなたの監督と支配の下で、あなたとの関係の範囲外ではあなたが『コピーライト』を有する一部分のいかなるコピーをも作成することを禁止するという条件の下で行わなければならないということになる。 + +上記以外のあらゆる状況下においては、伝達は以下で述べる条件の下でのみ許可される。再許諾は認められない。下記第10項により、再許諾は必要ないからである。 +3. ユーザの法的権利を、技術的保護手段の回避を禁ずる法律から守る¶ + +『保護された作品』は、 1996å¹´12月20日に採択されたWIPO著作権条約第11項の下での義務を満たす適用可能な法のいずれか、あるいはそれに類似の法が、回避の禁止または制限の対象として規定する、「効果的な技術的手段」 (effective technological measure)の一部として見なされてはならない。 + +(訳注: WIPO著作権条約については、http://www.cric.or.jp/db/article/wch.html 等を参照せよ。) + +あなたが『保護された作品』を伝達する場合、『保護された作品』に関して本許諾書の下で権利を行使することにより、技術的手段の回避に影響が出る範囲において、そのような手段の回避を禁じるいかなる法的権力をも放棄することになる。また、あなたはその作品のユーザに対して、技術的手段の回避を禁じるためにあなたや第三者の法的権利を強制するための手段として、その作品の動作や改変を制限するいかなる意図も否認することになる。 +4. 一字一句忠実なコピーの伝達¶ + +あなたは、自分が受領した『プログラム』のソースコードと一字一句同じコピーであれば、いかなる媒体でも伝達することができる。ただしその場合、あなたはそれぞれのコピーにおいて、目立つように、かつ適切な形で、ふさわしい『コピーライト』告知を掲載しなければならない。すなわち、本許諾書と、下記第7項に従い追加された非許可的条項のすべてがそのコードに適用される旨の告知を掲載し、あらゆる保証が存在しない旨の告知をすべてそのまま保全し、かつ『プログラム』の受領者すべてに、『プログラム』といっしょにこの許諾書のコピーを与えなければならない。 + +あなたは、自分が伝達するコピーのそれぞれに関していかなる価格を付けても良いし、無料で伝達しても構わない。また、報酬を取ってサポートや保証保護 (warranty protection)を提供しても良い。 +5. 改変されたバージョンのソースの伝達¶ + +あなたは、『プログラム』を基にした作品、あるいはそうした作品を『プログラム』から作成するための改変点を、上記第4項の規定に従ってソースコード形式で伝達することができる。ただしその場合、あなたは以下に示す条件のすべてを満たさなければならない: + + * a) 作品には、あなたが作品を改変したということと、改変に関連した日時を記述した告知を目立つように載せなければならない。 + * b) 作品には、それが本許諾書と、下記第7項に従って追加された条件すべての下で公開されていることを記述した告知を目立つように載せなければな らない。この条件は、上記第4項における「告知をすべてそのまま保全」するための条項を改変する。 + * c) 作品の全部分を、総体として、コピーを所有するに至った人全員に、本許諾書の下でライセンスしなければならない。そこで、本許諾書は、本許諾書第7項に基づく適用可能な追加的条項のすべてとともに、作品全体に、すなわちその全部分に、それらがどのようにパッケージされているかに関わらず適用されることになる。本許諾書は、これ以外のやり方には作品をライセンスする許可を与えないが、あなたが本許諾書以外で別途許可を得ていた場合には、それによって得られた許可まで無効とするものではない。 + * d) 改変された作品が対話的なユーザインターフェースを有する場合、それらのインターフェースは『適切な法的告知』を表示しなければならない。ただし、『プログラム』に元々『適切な法的告知』を表示しない対話的なインターフェースがある場合、あなたの作品で表示するようにする必要はない。 + +一巻の記憶装置の中か頒布媒体上で、『保護された作品』と、本来『保護された作品』の拡張ではなく、『保護された作品』とより大規模なプログラムを形成するような形で結合されているわけでもないその他の分離かつ独立した作品とをまとめた編集物は、編集作業とそれに由来する『コピーライト』が、個々の作品が許可する範囲を越えて編集物のユーザの作品へのアクセスや法的権利を制限するのに使われない限り、「集積物」(aggregate)と呼ばれる。単に『保護された作品』を集積物に含めるだけでは、その集積物の他の部分にまで本許諾書が適用されるということにはならない。 +6. ソース以外の形式における伝達¶ + +あなたは、オブジェクトコード形式の『保護された著作物』を、上記第4項および第5項の規定に従って伝達することができる。ただしその場合、あなたは機械読み取り可能な『対応するソース』も本許諾書の条件に従って、以下のいずれかの方法で伝達しなければならない。 + + * a) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、『対応するソース』を、ソフトウェア のやりとりで一般的に使われる耐久性のある物理的媒体に固定していっしょに頒布する。 + * b) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、最低でも3年間、あるいはあなたがその製品モデルに補修用部品やカスタマーサポートを提供する限り有効な、書面 による申し出を添付する。その申し出には、(1) オブジェクトコードを所有する者すべてに対して、その製品に含まれるソフトウェアのうち本許諾書で保護されるものすべてに『対応するソース』のコピーを、ソフトウェアのやりとりで一般的に使われる耐久性のある物理的媒体で頒布する旨を記載する。その際、物理的にこのソースの伝達を行うのにかかる正当なコスト以上の価格を要求してはならない。あるいは、(2) 『対応するソース』を無料でネットワークサーバから複製するためのアクセスを提供する旨を記載する。 + * c) オブジェクトコードの個々のコピーを、対応するソースを提供するという書面による申し出のコピーといっしょに伝達する。この選択肢は特別な場合、かつ非商業的な場合のみに、そしてあなたがオブジェクトコードを上記小項 6bに合致した申し出といっしょに受領した場合にのみに認められる。 + * d) オブジェクトコードを、指定の場所から複製するためのアクセスを提供することによって伝達し、『対応するソース』に対しても同じ場所を通じて同じ方法で複製するための同等のアクセスを提供する。伝達は無料でも手数料を課しても構わないが、『対応するソース』に対して追加的な課金を行ってはならない。受領者に対して、『対応するソース』をオブジェクトコードといっしょに複製することを義務づける必要はない。オブジェクトコードの複製元がネットワークサーバの場合、対応するソースは同等の複製機能をサポートする異なったサーバ(あなたか第三者が運営)上にあっても良い。その場合、オブジェクトコードの傍らに、『対応するソース』はどこで見つけられるかを明確に指示しておかなければならない。どのサーバが『対応するソース』をホストするかに関わらず、あなたは『対応するソース』がこれらの条 項を満たすために必要なかぎり利用可能であることを保証する責任がある。 + * e) オブジェクトコードをピア・ツー・ピア伝送を使って伝達する。ただしこの場合、あなたは上記小項6dに従い、その作品のオブジェクトコードと 『対応するソース』がどこで一般公衆に無料で提供されるのかということを他のピアに知らせておかなければならない。 + +オブジェクトコードの分離した一部であり、そのソースコードが『対応するソース』から『システムライブラリ』として除外されているものは、オブジェクトコード作品を伝達する場合に含める必要はない。 + +「ユーザ製品」(User Product)とは、(1)「コンシューマ製品」(consumer product)、すなわち、個人、子供、あるいは家庭用に通常使用される有形個人資産すべてか、あるいは(2)居住所における導入を目的に設計ないし販売されるものすべてを指す。ある物品がコンシューマ製品であるかを決定する際疑義がある場合には、極力範囲を広げる方向で決定されるべきである。ここで、ある特定のユーザによって受領されたある特定の製品にとっての「通常使用」 (nomally used)とは、その種の製品において典型的な、あるいは一般的な利用のことであり、その特定のユーザが置かれた状況や、その特定のユーザがその製品を実際にどう使っているか、どう使うことを予期しているか、あるいは予期されているかとは関係ない。その製品に相当な商業的、産業的または非コンシューマ的な利用法があったとしても、そうした利用がその製品の唯一重要な利用形態を代表するものでない限り、その製品はコンシューマ製品である。 + +ユーザ製品の「『インストール用情報』」(Installation Information)とは、ユーザ製品内の『保護された作品』に関して、『対応するソース』の改変されたバージョンから得られる『保護された作品』の改変されたバージョンを、インストール、実行するために必要な手法、手順、認証キーやその他の情報すべてを意味する。この情報は、改変されたオブジェクトコードの継続的な動作が、改変が為されたということによってのみ拒否されたり妨害されることが決してないことを保証するのに十分なものでなければならない。 + +本節の下において、作品をユーザ製品の内で、またはユーザ製品と共に、あるいは特にユーザ製品での利用を念頭においてオブジェクトコードで伝達し、またその伝達がユーザ製品の受領者への所有と利用の権利の永遠ないし有期の移転の一部として起こる場合(移転がどのように行われるかは問わない)、この条項の下で『対応するソース』は『インストール用情報』と共に提供されなければならない。しかしこの条件は、あなたと第三者のいずれもが改変されたオブジェクトコードをユーザ製品にインストールする能力を有していない際には適用されない(例えば、作品がROMにインストールされている場合)。 + +『インストール用情報』を提供する条件には、受領者によって改変ないしインストールされた作品、あるいはそうした作品が改変ないしインストールされたユーザ製品に対し、サービスや保証、アップデートを提供しつづけるという条件は含まれない。改変自体がネットワークの運用に実質的かつ有害な影響をもたらし、ネットワークを介したコミュニケーションのプロトコルや規則に違反する場合には、ネットワークアクセスを拒否しても構わない。 + +伝達される『対応するソース』や提供される『インストール用情報』が本節を満たすためには、それらが公に文書化された形式で(かつ公衆に対してソースコード形式で利用可能な実装とともに)提供されなければならない。この場合、これらの圧縮展開や読み込み、複製に特別なパスワードやキーを必要としてならない。 +7. 追加的条項¶ + +「追加的許可」(Additional permissions)とは、本許諾書が課す条件に一つかそれ以上の例外を設けることにより、本許諾書の条項を補足する条項のことである。『プログラム』全体に適用可能な追加的許可は、適用可能な法の下でそれらが有効である限り、あたかもそれらが本許諾書に含まれているかのように扱われなければならない。追加的許可が『プログラム』の一部にのみ適用される場合、その部分に関してはそういった追加的許可の下で別途利用可能だが、『プログラム』全体としては追加的許可に関わりなく本許諾書によってのみ管理される。 + +あなたが『保護された作品』のコピーを伝達する場合、あなたは追加的許可をそのコピー、あるいはその一部から削除することを選択できる (追加的許可は、あなたが作品をある種の形で改変する際には、そうした許可自身の削除を要求するような形で書かれてもよい)。あなたは、あなたによって『保護された作品』に追加され、あなたが適切な『コピーライト』許可を有するか、与えることができる限り、その一部分に追加的許可を設定することができる。 + +本許諾書の他の条件に関わらず、あなたが『保護された作品』に追加した一部分について(その部分の『コピーライト』保有者らによって正式に許可されていれば)、本許諾書の条項を、以下に示す条項で補足することができる: + + * a) 本許諾書第15項および第16項の条項とは異なった形で保証の否認や責任の限定を主張する。あるいは、 + * b) 追加した一部分において、明示的で妥当な法的告知や作者特定の保全、またはそれを含む作品において『適切な法的告知』の表示を要求する。あるいは、 + * c) 追加した一部分の出自を不当に表示することを禁じるか、あるいはそのような一部分の改変されたバージョンはオリジナルのバージョンとは異なっ ているということを適切な方法で印づけることを要求する。あるいは、 + * d) その一部分のライセンサーや作者の名前を、宣伝目的で利用することを制限する。あるいは、 + * e) 商品名や商標、サービスマークの利用に関して、商標法に従い権利を授与することを拒否する。あるいは、 + * f) その一部分(あるいはその改変されたバージョン)を伝達する者に、受領 者への責任に関して契約上の引き受けがあり、そうした責任が直接的にそういったライセンサーや作者にまで課せられる場合、その一部分のライセンサーや作者の免責を要求する。 + +他の非許可的な追加的条項は下記第10項が意味するところの「さらなる権利制限」(further restrictions)とみなされる。あなたが受領した『プログラム』、あるいはその一部に、それが本許諾書とともにさらなる権利制限である条項によっても管理されていると述べた告知が含まれている場合には、あなたはそういった条項を削除して構わない。あるライセンス文書にさらなる権利制限がふくまれているが、しかし本許諾書の下での再許諾や伝達を許可しているならば、あなたはそのライセンス文書の条項によって管理されている一部分を『保護された作品』に追加することができる。ただしその場合、さらなる権利制限はそのような再許諾や伝達では無効としなければならない。 + +あなたが本節に従って『保護された著作物』に条項を追加した場合、あなたは関係するソースファイル中に、それらのファイルに適用される追加的条項に関する声明、あるいは適用可能な条項を見つけることができる場所を示す告知を掲載しなければならない。 + +追加的条項は、それが許可的であろうと非許可的であろうと、別途書面化されたライセンスという形式で述べられてもよいし、本許諾書への例外として述べられてもよい。上記の要件はどちらの場合でも適用される。 +8. 終了¶ + +あなたは『保護された作品』を、本許諾書の下で明示的に提供されている場合を除いて、普及、または改変してはならない。それ以外に『保護された作品』を普及、または改変しようとする試みはすべて無効であり、本許諾書の下であなたに認められた権利(下記第11項の第3段落に従い授与されたパテントライセンスすべてを含む)を自動的に終了させることになる。 + +しかしながら、あなたが本許諾書への違反をすべて中止するならば、あなたがある特定の『コピーライト』保有者から得たライセンスは、(a)その『コピーライト』保有者が明白かつ決定的にあなたへのライセンスを終了させるか、あるいはさせないまでは暫定的に、(b)その『コピーライト』保有者が、あなたに対し違反について、何らかの正当な手段によりライセンス停止後60日以内に通知することができなかった場合には永続的に、回復される。 + +加えて、あなたがある特定の『コピーライト』保有者から得たライセンスは、その『コピーライト』保有者があなたに対して違反を何らかの正当な手段で通知し、それより前にその『コピーライト』保有者から、(当該作品に限らずその『コピーライト』保有者の作品のいずれかに関して)本許諾書に関する違反の通知を受領したことがなく、さらにあなたがその通知を受領してから30日以内に違反を正した場合、永続的に回復される。 + +本節に従いあなたの権利が終了した場合でも、本許諾書に従ってあなたからコピーや権利を受領した当事者が得た許諾は終了しない。あなたの権利が終了され、永続的に回復されなかった場合には、あなたは同じライセンス対象に関し下記第10項に従って新たにライセンスを受領する資格を失うものとする。 +9. コピーの所有に必要とされない受諾¶ + +あなたは、『プログラム』のコピーを受領あるいは実行するために本許諾書を受諾する必要はない。コピーを受領するためにピア・ツー・ピア伝送を使った結果としてのみ発生する『保護された作品』の付随的な普及も、同様に受諾を必要としない。しかしながら、他の場合においては、本許諾書以外にあなたに対して『保護された作品』の普及や改変をする許可を認めるものはない。これらの行為は、本許諾書を受諾しない限り『コピーライト』を侵害することになる。そこで、『保護された作品』を改変あるいは普及することにより、あなたはそうした行為を行うために本許諾書を受諾したということを示したことになる。 +10. 下流の受領者への自動的許諾¶ + +あなたが『保護された作品』を伝達するたびに、受領者は自動的にオリジナルのライセンサーから、本許諾書に従いその作品を実行、改変、普及するライセンスを得る。なお、あなたには第三者が本許諾書に従うことを強制する責任はない。 + +「主体取引」(entity transaction)とは、ある組織そのもの、ないしその組織の実質的に全ての資産の支配権が移転するか、あるいは組織の細分化や合併が行われるような取引を指す。もし主体取引の結果として『保護された作品』の普及が起こった場合、作品のコピーを受領したそれぞれの取引当事者は、利害関係のある当事者の先任者から、その先任者が前段落に従って有する、あるいは与えることができる、その作品に関するライセンスもまたすべて受領する。加えて個々の取引当事者は、利害関係のある先任者から、その先任者が有しているか、適正な努力によって得ることが可能な限りにおいて、その作品の『対応するソース』の所有権も得る権利を有する。 + +あなたは本許諾書の下で授与された、あるいは確約された権利の行使に対して、本許諾書が規定する以上のさらなる権利制限を課してはならない。たとえば、あなたはライセンス料、ロイヤルティや他の料金を、本許諾書の下で認められている権利の行使に関して課してはならない。また、あなたは『プログラム』やその一部の作成、利用、販売、販売の申し出、取り込みによって何らかのパテントクレームが侵害されたとして、訴訟(訴訟における反対請求ないし反訴を含む)を開始してはならない。 +11. 特許¶ + +「貢献者」(contributor)とは、本許諾書の下で『プログラム』、あるいは『プログラム』が基にした作品を利用することを正式に許可した『コピーライト』保有者のことを指す。従って、そのようにしてライセンスされた作品は、貢献者による「貢献者バージョン」(contributor version)と呼ばれる。 + +ある貢献者の「必須パテントクレーム」(essential patent claims)とは、すでに取得しているか、あるいは今後取得する見込みがあるため、その貢献者が現在所有ないし支配していると言える特許のうち、貢献者バージョンに対して、本許諾書で許可されているような作成や利用、販売といった何らかの形の行為を行うことによって侵害される可能性があるパテントクレームのすべてを意味する。ただし、貢献者バージョンをさらに改変した結果としてのみ侵害されるようなクレームは含まれない。この定義において、「支配」には本許諾書が課す条件と整合的なやり方で特許の再許諾を認める権利も含まれる。 + +個々の貢献者はあなたに対して、その貢献者の必須パテントクレームに関し、あなたがその貢献者バージョンの内容を作成、利用、販売、販売の申し出、取り込み、その他実行、改変、普及するために必要な、非排他的で全世界的に有効、かつロイヤルティフリーのパテントライセンスを授与する。 + +以下の3段落において「『パテントライセンス』」とは、ある特許を実施しないという明示的な協定やコミットメントのすべてを指す(例えば、ある特許の実施に対する明示的な許可や、特許侵害訴訟を提起しないという誓約など)。そのような『パテントライセンス』をある当事者に「授与」するとは、その当事者と特許を実施しないという協定やコミットメントを結ぶことを意味する。 + +もしあなたが、『保護された作品』の伝達を、それがある『パテントライセンス』に依存しており、よってその作品の『対応するソース』は、すべての人にとって、公衆が利用可能なネットワークサーバや他の容易にアクセス可能な手段を通じ、無料かつ本許諾書に従って複製可能ではないということを知りながら行うならば、あなたは (1)『対応するソース』も同様に利用可能にするか、 (2)この特定の作品に関して『パテントライセンス』から得られる便益を自ら剥奪するか、あるいは(3)下流の受領者に対しても、本許諾書の条項と整合的な形で、『パテントライセンス』が拡大されるように計らうかのいずれかを行わなければならない。ここで「『パテントライセンス』に依存するのを知りながら」というのは、あなたが『保護された作品』をある国で伝達すること、あるいはあなたの受領者が『保護された著作物』をある国で利用することが、『パテントライセンス』を授与されない限り、その国において、あなたにとってそれが有効だと信じるだけの理由がある一つかそれ以上の同定可能な特許を侵害するということを実際に知っているということである。 + +ある一対一の取引や協定に基づき、あるいは関連して、あなたが『保護された作品』の伝達、または伝達によって引き起こされる普及を行い、その際『保護された作品』を受領した一部の当事者に対して、『保護された作品』の特定のコピーの利用、普及、改変、または伝達を正式に許可するような『パテントライセンス』を授与するならば、あなたが授与した『パテントライセンス』は『保護された作品』やそれを基にした作品のすべての受領者にまで自動的に拡大されることになる。 + +ある『パテントライセンス』が「差別的」(discriminatory)であるとは、本許諾書の下で明確に認められた一つかそれ以上の権利を、『パテントライセンス』がカバーする範囲内に含まなかったり、そうした権利の行使を禁じたり、あるいは権利を行使しないことを条件として課すようなものである場合を指す。あなたを一方の当事者とし、ソフトウェアの頒布を生業とする第三者との間で、あなたは第三者に対し、作品を伝達する活動の程度に基づいて支払いを行う一方、第三者は、あなたから『保護された作品』を受領したすべての当事者に対して「差別的」な『パテントライセンス』を、(a)あなたが伝達した『保護された作品』のコピー(またはそうしたコピーから作成されたコピー)に対して、または(b)『保護された作品』を含む特定製品や編集物を、主要な、あるいは関連した対象として授与する、というような協定を結んでいる場合、あなたは『保護された作品』を伝達してはならない。ただし、あなたがそのような協定を締結したり、『パテントライセンス』を授与されたのが2007å¹´3月28日より以前である場合は本節の例外とする。 + +本許諾書に含まれる一切の記述は、適用可能な特許法の下であなたが利用可能な暗黙のライセンス、その他侵害への防御手段を排除したり制限したりするように解釈されてはならない。 +12. 他者の自由を明け渡してはならない¶ + +何らかの条件(裁判所の指令や協定など)があなたに課せられ、それが本許諾書の条件と矛盾したとしても、あなたが本許諾書の条件を免れることにはならない。あなたが、『保護された作品』を、本許諾書が課す義務と他の関連した義務の両方を同時に満たすような形で伝達できないのであれば、結果としてあなたがそれを伝達することは全く不可能ということになる。例えばあなたが、自分が『プログラム』を伝達した人々がさらに伝達を行う場合には、彼らからロイヤルティを徴収する、というような義務を負う条項に同意していた場合、あなたがそういった条項と本許諾書の両方を満たすには、『プログラム』の伝達を完全に止めてしまうしかないだろう。 +13. GNU Affero 一般公衆利用許諾書との利用¶ + +本許諾書に含まれる他の条件に関わらず、あなたには、『保護された作品』を GNU Affero 一般公衆利用許諾書バージョン3の下で許諾された作品とリンクまたは結合して単一の結合物とし、その結果物を伝達する許可が与えられる。本許諾書の条項は『保護された作品』である部分に関してはそのまま適用されるが、結合物それ自体としては、GNU Affero 一般公衆利用許諾書の第13項が規定する、ネットワークを介したやりとりに関する特殊な条件も適用されることになる。 + +(訳注: 訳出時点では、GNU Affero GPLは改定作業が依然続いており、確定バージョンはリリースされていない。 http://gplv3.fsf.org/agplv3-dd2-guide.htmlを参照せよ。) +14. 本許諾書の改訂されたバージョン¶ + +フリーソフトウェア財団は、改訂された、あるいは新しいバージョンの GNU 一般公衆利用許諾書を折りに触れて発行することができる。そのような新バージョンは、その精神においては現在のバージョンと似たものになるだろうが、細部については新たな問題や懸念を解決すべく異なるものになるだろう。 + +それぞれのバージョンには、見分けがつくようなバージョン番号が振られている。『プログラム』に、ある特定のバージョン番号が振られた GNU 一般公衆利用許諾書「かそれ以降のバージョンのいずれか(or any later version)」が適用されると指定されていた場合、あなたは指定された番号のバージョンか、それ以降にフリーソフトウェア財団によって発行されたいずれかのバージョンのどちらの利用条件に従うかを選ぶことができる。『プログラム』が本許諾書のバージョン番号を指定していなかった場合には、あなたはフリーソフトウェア財団がそれまでに発行したバージョンの中からどれを選択しても構わない。 + +(訳注: 日本語訳のバージョンは日付で管理している。冒頭を見よ。) + +『プログラム』において、GNU 一般公衆利用許諾書の将来のバージョンのうちどれが適用されうるかは代理人が決定できる、と指定されていた場合、その代理人が、あるバージョンを受諾すると述べた公的な声明は、あなたに対し、その『プログラム』に関してそのバージョンのGNU GPLを選ぶことを永続的かつ正式に許可するのと等しい。 + +本許諾書の今後のバージョンでは、あなたに追加的な、または従来とは異なった形での許可を与えるかもしれない。しかしながら、作者や『コピーライト』保有者に対し、あなたが以降のバージョンに従うことを選んだ結果として、追加的な義務が課せられることはない。 +15. 保証の否認¶ + +『プログラム』には、適用可能な法で許可されている範囲において何の保証もない。書面で述べられていない限り、『コピーライト』保有者やその他の当事者は『プログラム』を「あるがまま(as is)」で、明示的、暗示的を問わず、いかなる種類の保証もなく提供する。この保証には、商用可能性や特定目的への適合性の暗黙的保証が含まれるが、これらに限定されない。『プログラム』の質や性能に関するリスクはすべてあなたに帰属する。『プログラム』に問題があると判明した場合、あなたは必要なすべての対応、補修、修正にかかる費用を負うものとする。 +16. 責任の限定¶ + +適用可能な法において義務づけられるか、書面による同意がない限り、『コピーライト』保有者あるいはその他『プログラム』を上記で許可された通りに改変あるいは伝達する当事者は、たとえそうした保有者や他の当事者が損害が発生する可能性について事前に通知されていたとしても、あなたに対して損害賠償責任を有することはない。ここでいう損害には、『プログラム』の利用あるいは利用できないことから発生した一般的、特殊的、偶然的、必然的な損害のすべてが含まれる(データの消失やデータの不正確な解釈、あなたや第三者によって被った、あるいは『プログラム』が他のプログラムといっしょにうまく動作しなかったために引き起こされた損害などが含まれるが、これらに限定されない)。 +17. 第15項と第16項の解釈について¶ + +上記のような保証の否認や責任の限定が、特定国内においてそういった条項が指定する通りの法的効力を持ち得ない場合、再審裁判所は、『プログラム』に関連したすべての民事責任の絶対的棄権に最も近く肉薄する国内法を適用すべきである。ただし、報酬の見返りとして責任の保証や引き受けが『プログラム』のコピーに付随する場合は除く。 + diff --git a/jTsSplitter/license.txt b/jTsSplitter/license.txt new file mode 100644 index 0000000..69e51ec --- /dev/null +++ b/jTsSplitter/license.txt @@ -0,0 +1,254 @@ +GNU LESSER GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. +0. Additional Definitions. + +As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License. + +“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. + +An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. + +A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”. + +The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. + +The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. +1. Exception to Section 3 of the GNU GPL. + +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. +2. Conveying Modified Versions. + +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: + + * a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or + * b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. + +3. Object Code Incorporating Material from Library Header Files. + +The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: + + * a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. + * b) Accompany the object code with a copy of the GNU GPL and this license document. + +4. Combined Works. + +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: + + * a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. + * b) Accompany the Combined Work with a copy of the GNU GPL and this license document. + * c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. + * d) Do one of the following: + o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. + * e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) + +5. Combined Libraries. + +You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: + + * a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. + * b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +6. Revised Versions of the GNU Lesser General Public License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. + + +GNU GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. +TERMS AND CONDITIONS +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. +1. Source Code. + +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. +2. Basic Permissions. + +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + * a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + * b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + * c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + * d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + * a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + * b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + * c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + * d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + * e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. +7. Additional Terms. + +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + * a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + * b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + * c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + * d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + * e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + * f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. +11. Patents. + +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. +13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. diff --git a/manual/Makefile.base b/manual/Makefile.base new file mode 100755 index 0000000..de63667 --- /dev/null +++ b/manual/Makefile.base @@ -0,0 +1,17 @@ +MAJOR = 0 +MINOR = 9 +REVISION = 10 +VER = $(MAJOR).$(MINOR).$(REVISION) + + +all: + cd tstools;make all +clean: + cd tstools;make clean +install: + cd rec10;make install + cd tstools;make install +uninstall: + cd tstools;make uninstall + cd rec10;make uninstall + diff --git a/manual/install.sh b/manual/install.sh new file mode 100755 index 0000000..028100b --- /dev/null +++ b/manual/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash +SELF_DIR=`dirname $0` +cd ${SELF_DIR} +cd rec10 +bash install.sh +cd ../ +mv Makefile.base Makefile diff --git a/manual/readme.txt b/manual/readme.txt new file mode 100755 index 0000000..8087507 --- /dev/null +++ b/manual/readme.txt @@ -0,0 +1,210 @@ +########################################### +# Rec10 -Ts Recording system- # +# Ver.0.9.9.2 # +# 2011/03/23 Yukikaze & long.inus # +# Copyright (C) 2009-2011 Yukikaze # +########################################### + +本ソフトはpythonおよびperlによって書かれた録画ツールです。 +ライセンスは LGPL v3に準拠します(license.txt参照) + +[必要コマンド] +python(2.6,2.7にて動作確認) +wine +mencoder +ffmpeg +x264 +mp4box +MySQL +MySQLdb(MySQL-pythonなどの名前) +mkvmerge(mkv使用時) +java(jre1.6で動作を確認) + +[必要環境:Webインターフェース部分] +perl +一部のperlモジュール(rectool.pl,rec10webg2) + +[必要環境:外部ツール] +jTsSplitter(included) +BonTsDemux(included) +epgdump(included) +b25(not included) +recpt1(recfriioでもいいはずです)(not included) +MySQLdb + +事前準備: +ネットの情報を参考にpt1ドライバーを無効化する +pt1などのドライバーをインストールした上(chardev版)で、recpt1などのソフトを導入、 +b25をインストールしておいてください。 +*注意 +11å¹´10月01日からのBS新チャンネル対応のためには、10/02現在ではrecpt1にパッチを当てる必要があります。 +rec10同梱版のepgrecはts解析によってチャンネルデータを得るように改変してあるので +変更は不要です。 + +1:install.shを実行 +2:表示にしたがって設定の変更(チャンネルなど) +3:make +4:su +5:make install +6:rec10を実行するユーザーで/usr/local/share/rec10を実行 +7:cronに書き加える +8:rectool.plをインストール(Makefile.PLの実行 rectool.plの配置) + +付け足し + +7.cronの設定 + +最後にrec10d.pyをcronで五分おきに実行するようにしてください +crontab -e を実行するとcronを編集できるようになるので +*/5 * * * * python /usr/local/bin/rec10 +のように書いてください(5扮ごとに実行) + +ログは/var/log/rec10に移動しました。 + +8.rectoolのインストール +Makefile.PLを実行します。 +実行した後にrectool.plをhttpの公開ディレクトリ(wwwフォルダなど)に置いてください。 + +ちなみに +エンコードの設定を変えたい場合はts2x264を参照してください + + +チャンネルの設定を変えた場合はを編集した後に +chdata.pyを実行してください(python chdata.py) +その後番組表が更新されます + +バグだらけのコードですが、改善点などを指摘していただけるとうれしいです。 +yukikaze.jp@gmail.com + + +動作確認のとれたディストリ + +11/03/10 SVN Centos 5.5 (yukikaze) +11/03/10 0.9.9.1+a ArchLinux (yukikaze) +11/02/20 0.9.9.1+a Debian 6.0 +11/02/XX 0.9.9 Ubuntu 10.10 +10/12/XX 0.9.8 Centos 5.5 (yukikaze) +10/XX/XX 0.9.8 Fedora13 (long.inus) + + +[History] +11/XX/XX 0.9.10 +add Bluray compatible option("B") +ステレオ音声時のBonTsDemux仕様オプション追加("b") +lameの実行パスチェックを実装 +mencoderのコマンドラインを最新版対応へ +ffmpegのオプション追加 +epggenreを追加 +keywordの重複チェックをより賢く +logoのインポートに対応 +ArchLinuxサポートのための細かな変更 +新BSチャンネル対応 + +11/02/02 0.9.9 +BonTsDemuxを最新版へ(nogui化によりXvfbが不要) +一部CSチャンネルの追加 +epg_chを変更(ontvの削除) +チャンネルスキャン機能を実装 +キーワード予約の自動実行オプション追加(in_auto_jbkにauto,optの追加) +番組初頭の解像度変更に対応 +キーワード予約自動実行オプションの重複チェック実装 +延長対応機能の修正 +移動後のオプション引き継ぎに対応 + +10/10/09 0.9.8 release +インターレース保持エンコードに対応 +色空間を修正 +放送大学のマルチチャンネルに仮対応 +verboseモードの実装 +ログレベルの実装 +画面サイズが取得できなかったときの処理を追加 +python2.5/2.7に対応 +音声の自動復帰を修正 + +10/07/10 0.9.7 release +ヒストリーチャンネルのタイトルを修正 +ffmpeg使用時にscale拡大をするように修正 +一時ファイル削除機能の修正 +sarの変更を実装 +最新版のCaption2Assに対応 + +10/05/29 0.9.6 release +バグ修正 +ログシステムの修正 + +0.9.5(内部リリース) +b25自動削除機能の改善 +自動仕分け機能のアップデート +Caption2Assやaac取り出しがうまくいかないときの自動復帰処理の実装 +バグ修正 + +10/04/02 0.9.4 release +バグ修正 +インストーラーの大幅な改善 +ログシステムの変更 +エンコードの変更 +チャンネル変更に対応(CS) + +10/03/20 0.9.3 release(internal) +lots of bug fixes. +change DB. +implement updating function(from 0.9.1 or 0.9.2) +10/03/06 0.9.2 release(internal) +few bug fix.(!!! amazing i think) +implement new encoding system. +use x264cli and mencoder throwgh fifo. +implement final production changing system(you can choose mkv and mp4 now.) + +10/02/21 0.9.1 release +Lots of bug fixes. +change video filter. +change encode option. +implement installer. + +09/12/07 0.9.0 release +change config path.(config.ini to rec10.conf) +add Makefile +change large number of var name. +support b25_remote(thanks long.inus) +support auto copy function. +change video filter. +change encode option. +fix a lot of bugs. +finish to support iEPG(iRec10EPG). + +09/10/27 0.8.0 relaase +Lots of bug fixes. +Use mkvmerge to mux avi to mkv. +Many changes. + +09/08/22 0.6.0 release +Lots of bug fixes. +Implement db using MySQL. +Change Ts splitting soft from Tssplitter to tssplitter_lite(included.) + +09/08/01 0.5.0 release +バグフィックス +検索録画のパターンマッチングアルゴリズムの変更(推測的な検索ができるようになった) +rectool.plを同梱するようにした。 +周辺ソフトのうちライセンスの問題がないものを同梱するようにした。 + +09/07/01 0.4.1 release +lots of bug fixes +add some cs-ch. +release pl src. +09/05/24 0.3.1 release +fix +チャンネルの増加 +エンコードオプションを実際に使えるようにした。 +1passモード実装 +niceコマンドをより広範囲に適用するようにした。 +09/05/08 0.1.1 release +fix +2passエンコードのログファイルがかぶるのを訂正 +一部チャンネル指定が間違っていたのを訂正 +その他多くのバグの訂正 +09/05/05 0.0.1b release +fix +replace tab to 4 spaces(it caused errors) +add some cs-e2 channels +09/05/04 0.0.1a release diff --git a/manual/rec10Manual0.9.9.pdf b/manual/rec10Manual0.9.9.pdf new file mode 100755 index 0000000..3e503ed Binary files /dev/null and b/manual/rec10Manual0.9.9.pdf differ diff --git a/readme.txt b/readme.txt new file mode 100755 index 0000000..8087507 --- /dev/null +++ b/readme.txt @@ -0,0 +1,210 @@ +########################################### +# Rec10 -Ts Recording system- # +# Ver.0.9.9.2 # +# 2011/03/23 Yukikaze & long.inus # +# Copyright (C) 2009-2011 Yukikaze # +########################################### + +本ソフトはpythonおよびperlによって書かれた録画ツールです。 +ライセンスは LGPL v3に準拠します(license.txt参照) + +[必要コマンド] +python(2.6,2.7にて動作確認) +wine +mencoder +ffmpeg +x264 +mp4box +MySQL +MySQLdb(MySQL-pythonなどの名前) +mkvmerge(mkv使用時) +java(jre1.6で動作を確認) + +[必要環境:Webインターフェース部分] +perl +一部のperlモジュール(rectool.pl,rec10webg2) + +[必要環境:外部ツール] +jTsSplitter(included) +BonTsDemux(included) +epgdump(included) +b25(not included) +recpt1(recfriioでもいいはずです)(not included) +MySQLdb + +事前準備: +ネットの情報を参考にpt1ドライバーを無効化する +pt1などのドライバーをインストールした上(chardev版)で、recpt1などのソフトを導入、 +b25をインストールしておいてください。 +*注意 +11å¹´10月01日からのBS新チャンネル対応のためには、10/02現在ではrecpt1にパッチを当てる必要があります。 +rec10同梱版のepgrecはts解析によってチャンネルデータを得るように改変してあるので +変更は不要です。 + +1:install.shを実行 +2:表示にしたがって設定の変更(チャンネルなど) +3:make +4:su +5:make install +6:rec10を実行するユーザーで/usr/local/share/rec10を実行 +7:cronに書き加える +8:rectool.plをインストール(Makefile.PLの実行 rectool.plの配置) + +付け足し + +7.cronの設定 + +最後にrec10d.pyをcronで五分おきに実行するようにしてください +crontab -e を実行するとcronを編集できるようになるので +*/5 * * * * python /usr/local/bin/rec10 +のように書いてください(5扮ごとに実行) + +ログは/var/log/rec10に移動しました。 + +8.rectoolのインストール +Makefile.PLを実行します。 +実行した後にrectool.plをhttpの公開ディレクトリ(wwwフォルダなど)に置いてください。 + +ちなみに +エンコードの設定を変えたい場合はts2x264を参照してください + + +チャンネルの設定を変えた場合はを編集した後に +chdata.pyを実行してください(python chdata.py) +その後番組表が更新されます + +バグだらけのコードですが、改善点などを指摘していただけるとうれしいです。 +yukikaze.jp@gmail.com + + +動作確認のとれたディストリ + +11/03/10 SVN Centos 5.5 (yukikaze) +11/03/10 0.9.9.1+a ArchLinux (yukikaze) +11/02/20 0.9.9.1+a Debian 6.0 +11/02/XX 0.9.9 Ubuntu 10.10 +10/12/XX 0.9.8 Centos 5.5 (yukikaze) +10/XX/XX 0.9.8 Fedora13 (long.inus) + + +[History] +11/XX/XX 0.9.10 +add Bluray compatible option("B") +ステレオ音声時のBonTsDemux仕様オプション追加("b") +lameの実行パスチェックを実装 +mencoderのコマンドラインを最新版対応へ +ffmpegのオプション追加 +epggenreを追加 +keywordの重複チェックをより賢く +logoのインポートに対応 +ArchLinuxサポートのための細かな変更 +新BSチャンネル対応 + +11/02/02 0.9.9 +BonTsDemuxを最新版へ(nogui化によりXvfbが不要) +一部CSチャンネルの追加 +epg_chを変更(ontvの削除) +チャンネルスキャン機能を実装 +キーワード予約の自動実行オプション追加(in_auto_jbkにauto,optの追加) +番組初頭の解像度変更に対応 +キーワード予約自動実行オプションの重複チェック実装 +延長対応機能の修正 +移動後のオプション引き継ぎに対応 + +10/10/09 0.9.8 release +インターレース保持エンコードに対応 +色空間を修正 +放送大学のマルチチャンネルに仮対応 +verboseモードの実装 +ログレベルの実装 +画面サイズが取得できなかったときの処理を追加 +python2.5/2.7に対応 +音声の自動復帰を修正 + +10/07/10 0.9.7 release +ヒストリーチャンネルのタイトルを修正 +ffmpeg使用時にscale拡大をするように修正 +一時ファイル削除機能の修正 +sarの変更を実装 +最新版のCaption2Assに対応 + +10/05/29 0.9.6 release +バグ修正 +ログシステムの修正 + +0.9.5(内部リリース) +b25自動削除機能の改善 +自動仕分け機能のアップデート +Caption2Assやaac取り出しがうまくいかないときの自動復帰処理の実装 +バグ修正 + +10/04/02 0.9.4 release +バグ修正 +インストーラーの大幅な改善 +ログシステムの変更 +エンコードの変更 +チャンネル変更に対応(CS) + +10/03/20 0.9.3 release(internal) +lots of bug fixes. +change DB. +implement updating function(from 0.9.1 or 0.9.2) +10/03/06 0.9.2 release(internal) +few bug fix.(!!! amazing i think) +implement new encoding system. +use x264cli and mencoder throwgh fifo. +implement final production changing system(you can choose mkv and mp4 now.) + +10/02/21 0.9.1 release +Lots of bug fixes. +change video filter. +change encode option. +implement installer. + +09/12/07 0.9.0 release +change config path.(config.ini to rec10.conf) +add Makefile +change large number of var name. +support b25_remote(thanks long.inus) +support auto copy function. +change video filter. +change encode option. +fix a lot of bugs. +finish to support iEPG(iRec10EPG). + +09/10/27 0.8.0 relaase +Lots of bug fixes. +Use mkvmerge to mux avi to mkv. +Many changes. + +09/08/22 0.6.0 release +Lots of bug fixes. +Implement db using MySQL. +Change Ts splitting soft from Tssplitter to tssplitter_lite(included.) + +09/08/01 0.5.0 release +バグフィックス +検索録画のパターンマッチングアルゴリズムの変更(推測的な検索ができるようになった) +rectool.plを同梱するようにした。 +周辺ソフトのうちライセンスの問題がないものを同梱するようにした。 + +09/07/01 0.4.1 release +lots of bug fixes +add some cs-ch. +release pl src. +09/05/24 0.3.1 release +fix +チャンネルの増加 +エンコードオプションを実際に使えるようにした。 +1passモード実装 +niceコマンドをより広範囲に適用するようにした。 +09/05/08 0.1.1 release +fix +2passエンコードのログファイルがかぶるのを訂正 +一部チャンネル指定が間違っていたのを訂正 +その他多くのバグの訂正 +09/05/05 0.0.1b release +fix +replace tab to 4 spaces(it caused errors) +add some cs-e2 channels +09/05/04 0.0.1a release diff --git a/rec10/Makefile.base b/rec10/Makefile.base new file mode 100644 index 0000000..0da6338 --- /dev/null +++ b/rec10/Makefile.base @@ -0,0 +1,33 @@ +PREFIX = /usr/local/share +MAJOR = 0 +MINOR = 9 +REVISION = 10 +VER = $(MAJOR).$(MINOR).$(REVISION) + +DEST = $(PREFIX)/rec10 + +install: + if ! [ -d $(PREFIX)/rec10 ]; then mkdir -p $(PREFIX)/rec10 ;fi + cp ./*.py $(DEST)/ + /bin/echo -e "#!/bin/bash" > ./rec10 + /bin/echo -e "if type -P python2.6 > /dev/null\nthen\nexport LANG=\"ja_JP.UTF-8\" && python2.6 ${DEST}/rec10d.py" >> ./rec10 + /bin/echo -e "elif type -P python26 > /dev/null\nthen\nexport LANG=\"ja_JP.UTF-8\" && python26 ${DEST}/rec10d.py\n" >> ./rec10 + /bin/echo -e "elif type -P python2.5 > /dev/null\nthen\nexport LANG=\"ja_JP.UTF-8\" && python2.5 ${DEST}/rec10d.py\n" >> ./rec10 + /bin/echo -e "elif type -P python25 > /dev/null\nthen\nexport LANG=\"ja_JP.UTF-8\" && python25 ${DEST}/rec10d.py" >> ./rec10 + /bin/echo -e "elif type -P python2.7 > /dev/null\nthen\nexport LANG=\"ja_JP.UTF-8\" && python2.7 ${DEST}/rec10d.py" >> ./rec10 + /bin/echo -e "elif type -P python27 > /dev/null\nthen\nexport LANG=\"ja_JP.UTF-8\" && python27 ${DEST}/rec10d.py" >> ./rec10 + /bin/echo -e "else export LANG=\"ja_JP.UTF-8\" && python ${DEST}/rec10d.py" >> ./rec10 + /bin/echo -e "fi\n" >> ./rec10 + install -m755 ./rec10 $(DEST)/ + if ! [ -f /usr/local/bin/rec10 ]; then ln $(DEST)/rec10 /usr/local/bin;fi + chmod 755 /usr/local/bin/rec10 + if [ -f /etc/rec10.conf ]; then rm /etc/rec10.conf;fi + cp ./rec10.conf /etc/rec10.conf + if ! [ -d /tmp/rec10 ]; then mkdir -p /tmp/rec10 ;fi + chmod 777 /tmp/rec10 + if ! [ -d /var/log/rec10 ]; then echo "" > /var/log/rec10 ;fi + chmod 777 /var/log/rec10 +uninstall: + rm -rf $(DEST) + rm -rf /tmp/rec10 + rm -f /usr/local/bin/rec10 diff --git a/rec10/auto_move.py b/rec10/auto_move.py new file mode 100644 index 0000000..195b1b8 --- /dev/null +++ b/rec10/auto_move.py @@ -0,0 +1,154 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import glob +import os +import os.path +import re +import time +import shutil +import traceback +import sys + +import recdblist +import guess +def getTitle(title): + rT=re.compile("(.+)_(\d+)\Z") + tT=rT.match(title) + rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv + tT2=rT2.match(title) + rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv + tT3=rT3.match(title) + rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv + tT4=rT4.match(title) + rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv + tT5=rT5.match(title) + ntitle=title + if tT : + ntitle=tT.group(1) + elif tT2: + ntitle=tT2.group(1) + elif tT3: + ntitle=tT3.group(1) + elif tT4: + ntitle=tT4.group(1) + elif tT5: + ntitle=tT5.group(1) + return ntitle +def searchFile(temppath,recpath,ext): + """ + 録画一時フォルダ内ファイルを検索 + """ + avilist = glob.glob(temppath + "/*"+ext) + ret=[] + for avif in avilist: + ##b25f is title.ts.b25 avi is title.avi + dir = os.path.split(avif)[0] + title = os.path.split(avif)[1] + title = title.replace(ext, "") + avipath = os.path.join(dir, title + ext) + if os.path.exists(avipath): + dtime = time.time()-os.path.getmtime(avipath) + dtime = int(dtime) + if dtime > 300: + if veryfySize(avipath): + ret.append(title) + return ret +def getMoveDestpath(title,temppath,recpath,ext): + dstpath=os.path.join(recpath,title+ext) + srcpath=os.path.join(temppath,title+ext) + if os.path.exists(dstpath): + if not os.path.getsize(dstpath) == os.path.getsize(srcpath): + gmtime=time.gmtime(os.path.getmtime(srcpath)) + iff="" + try: + iff=u"("+configreader.getConfEnv("iff")+u")_" + if iff==u"()_": + iff = u"" + except: + iff="" + title=title+u"_"+iff+time.strftime("%Y-%m-%dT%H-%M-%S",gmtime) + else: + recdblist.printutf8(u"同サイズのファイルが存在します") + + return title +def getDelpath(temppath,title,addfp=1): + delpath=[os.path.join(temppath,title+".ts")] + delpath.append(os.path.join(temppath,title+".avi")) + if addfp==1: + delpath.append(os.path.join(temppath,title+".mp4")) + delpath.append(os.path.join(temppath,title+".mkv")) + delpath.append(os.path.join(temppath,title+".m2v")) + delpath.append(os.path.join(temppath,title+".120.avi")) + delpath.append(os.path.join(temppath,title+".timecode.txt")) + delpath.append(os.path.join(temppath,title+".aac")) + delpath.append(os.path.join(temppath,title+".ts.b25")) + delpath.append(os.path.join(temppath,title+".ts.tsmix")) + delpath.append(os.path.join(temppath,title+".ts.log")) + delpath.append(os.path.join(temppath,title+".sa.avi")) + delpath.append(os.path.join(temppath,title+".sa.avi.log")) + delpath.append(os.path.join(temppath,title+".log")) + delpath.append(os.path.join(temppath,title+".log.zip")) + return delpath +def veryfySize(path): + #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h + vsize=[245,275,295,591,830] + vsize=vsize+[325,449,560,590,602,690,805,860,1014,1138,1237] + vsize=vsize+[261,535,540,616,740]#HD 30m 1h + #vsize=vsize+[381,895,447] + ret = 0 + for size in vsize: + if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024: + ret=1 + if os.path.getsize(path)>270*1024*1024: + ret=1 + return ret +def execMove(title,temppath,recpath,ext,autodel): + srcpath=os.path.join(temppath,title+ext) + # patched. orig: searchFolder(title, recpath) + sf=guess.searchFolder(title, recpath,200) + if sf!="": + destpath=os.path.join(sf,getMoveDestpath(title, temppath, sf, ext)+ext) + if os.path.exists(destpath): + if os.path.getsize(destpath) == os.path.getsize(srcpath): + recdblist.printutf8(u"同名同サイズのファイルが存在します。") + if autodel==1: + recdblist.printutf8(u"関連ファイルを削除します。") + delpath=getDelpath(temppath, title) + for dp in delpath: + try: + os.remove(dp) + "" + except: + "" + else: + recdblist.printutf8("moving now..") + recdblist.printutf8(srcpath+" : "+destpath) + print srcpath + shutil.copy(srcpath, destpath) + #shutil.copy(srcpath, destpath) + if autodel==1: + delpath=getDelpath(temppath, title) + for dp in delpath: + try: + os.remove(dp) + "" + except: + "" + else: + recdblist.printutf8("sf not fonud @ execMove",verbose_level=100) + +def execDelete(title,temppath): + delpath=getDelpath(temppath, title,0) + recdblist.printutf8(title+u" 関連の一時ファイルを削除します") + for dp in delpath: + try: + if os.path.exists(dp): + recdblist.printutf8(dp) + os.remove(dp) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) diff --git a/rec10/auto_process.py b/rec10/auto_process.py new file mode 100644 index 0000000..fabee05 --- /dev/null +++ b/rec10/auto_process.py @@ -0,0 +1,285 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import glob +import time +import datetime +import commands +import re +import os.path + +import chdb +import status +import configreader +import recdblist +import rec10d +import tv2mp4 +import epgdb +def updateToMP4(path): + """ + !現在未使用! + 録画一時フォルダ内mp4ファイルを検索 + """ + avilist = glob.glob(path + "/*.avi") + mkvlist = glob.glob(path+"/*.mkv") + avilist=avilist+mkvlist + for avif in avilist: + if avif.rfind("sa.avi")==-1: + dir = os.path.split(avif)[0] + title = os.path.split(avif)[1] + title = title.replace(".avi", "") + title = title.replace(".mkv", "") + avipath = os.path.join(dir, title + ".avi") + mkvpath = os.path.join(dir, title + ".mkv") + mp4path = os.path.join(dir, title + ".mp4") + if not os.path.exists(mp4path): + if os.path.exists(avipath): + avidtime = int(time.time()-os.path.getmtime(avipath)) + if avidtime>300: + if os.path.exists(mkvpath): + mkvdtime = int(time.time()-os.path.getmtime(mkvpath)) + if mkvdtime>300: + recdblist.printutf8(mkvpath+":"+mp4path) + tv2mp4.mkv2mp4(mkvpath,mp4path) + else: + recdblist.printutf8(avipath+":"+mp4path) + tv2mp4.avi2mp4(avipath,mp4path) + else: + recdblist.printutf8(avipath+":"+mp4path) + tv2mp4.avi2mp4(avipath,mp4path) + else: + if not os.path.exists(avipath): + if os.path.exists(mkvpath): + mkvdtime = int(time.time()-os.path.getmtime(mkvpath)) + if mkvdtime>300: + recdblist.printutf8(mkvpath+":"+mp4path) + tv2mp4.mkv2mp4(mkvpath,mp4path) +def autoCheck(path): + avilist = glob.glob(path + "/*.avi") + mkvlist = glob.glob(path+"/*.mkv") + mp4list = glob.glob(path+"/*.mp4") + tslist = glob.glob(path+"/*.ts") + b25list = glob.glob(path+"/*.ts.b25") + filelist=avilist+mkvlist+tslist+b25list+mp4list + add=[] + tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60) + tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200) + for fn in filelist: + if os.path.exists(fn): + if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000: + dir = os.path.split(fn)[0] + file = os.path.split(fn)[1] + title = os.path.splitext(file)[0] + title = unicode(title,'utf-8',errors='replace') + ext = os.path.splitext(file)[1] + if ext == ".b25": + title=title.replace(".ts","") + dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2) + if len(dbs)==0: + proc=checkProcess(dir, title) + chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title) + nchtxt="" + if chtxtt!=None: + nchtxt=chtxtt + if proc=="b25": + add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt]) + elif proc=="ts": + add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt]) + elif proc =="264": + add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt]) + #elif proc =="mp4": + # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt]) + #print add + if len(add)>0: + rec10d.rec10db.new_auto_proc() + for a in add: + rec10d.rec10db.add_auto_proc(a[0],a[1],a[2]) + time.sleep(1) +""" + 処理がどの段階まで言ったのかを調査し返す。 + return + recording + b25 + b25decoding + tssplitting + ts + encoding + avi + mp4making + mp4 +""" +def checkProcess(path,title): + path1 = os.path.join(path,title+".mkv") + if os.path.exists(path1): + if int(time.time()-os.path.getmtime(path1))>300: + return "mkv" + else: + return "mkvmaking" + elif os.path.exists(os.path.join(path,title+".mp4")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300: + return "mp4" + else: + return "mp4making" + elif os.path.exists(os.path.join(path,title+".264")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300: + return "264" + else: + return "encoding" + elif os.path.exists(os.path.join(path,title+".ts.log")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300: + return "encoding" + else: + return "ts" + elif os.path.exists(os.path.join(path,title+".ts")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300: + return "ts" + else: + return "tssplitting" + elif os.path.exists(os.path.join(path,title+".sa.avi")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300: + return "ts" + else: + return "tssplitting" + elif os.path.exists(os.path.join(path,title+".ts.b25")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300: + return "b25" + else: + return "recording" +def update_all_timeline_epg(): + now=datetime.datetime.now() + et=now+datetime.timedelta(days=7) + update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S")) +def update_timeline_epg(btime,etime): + update_timeline_epg_schedule(btime,etime) + update_timeline_dup(btime,etime) +def update_timeline_epg_schedule(btime,etime): + dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime) + #print dbl + for db in dbl: + ret=[] + #[chtxtt, title, btime, etime,exp,longexp,category] + if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS: + ret=epgdb.searchTime(db['title'], db['btime'], db['deltatime'], db['chtxt']) + if len(ret)>4 and len(ret[2])>18: + rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6]) + if not (db['btime'] == ret[2] and db['etime']==ret[3]): + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE : + ret=epgdb.searchTime(db['title'], db['btime'],"5", db['chtxt']) + if len(ret)>4 and len(ret[2])>18: + rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6]) + if not (db['btime'] == ret[2] and db['etime']==ret[3]): + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") +def update_timeline_dup(epgbtime,epgetime): + dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime) + for db in dbl: + if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS: + dbn=epgdb.countEpgSchedule(db['epgbtime'], db['epgetime']) + try: + bctypet=chdb.searchCHFromChtxt(db['chtxt'])['bctype'] + if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 : + if dbn[1]>status.getRecordingMax()[1]: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + else: + if dbn[0]>status.getRecordingMax()[0]: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + except: + "" +def killDeadEncode(path): + rawlist = glob.glob(path + "/*.264") + for fn in rawlist: + if int(time.time()-os.path.getmtime(fn))>3000: + m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8') + x264path=os.path.split(fn)[1] + folderpath=unicode(os.path.split(fn)[0],'utf-8') + x264path=re.sub("\\[","[",x264path) + x264path=re.sub("\[","\\\[",x264path) + x264path=re.sub("\\]","]",x264path) + x264path=re.sub("]","\\]",x264path) + tspath=unicode(x264path.replace(".264",".ts"),'utf-8') + m2vpath=unicode(x264path.replace(".264",".m2v"),'utf-8') + x264path=unicode(x264path,'utf-8') + os.environ['LANG']="ja_JP.UTF-8" + ktmp=[] + ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'") + ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'") + ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep ffmpeg | awk '{print $2}'") + recdblist.printutf8(u"エンコード処理異常終了タスク終了") + for istr in ktmp: + recdblist.printutf8(istr) + ktmt=commands.getoutput(istr.encode('utf-8')) + #print ktmt + #print len(ktmt) + if len(ktmt)>0: + #print ktmt + if len(ktmt[0])>0: + ktmt=ktmt[0] + #print ktmt + try: + if int(ktmt)>0: + ktmp=u"kill -9 `"+istr+u"`" + recdblist.printutf8(ktmp) + #print ktmp + os.system(ktmp.encode('utf-8')) + except: + "" +def deleteTmpFile(path,title,ext): + level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv + smsize= 0 + if re.search(".ts",ext): + level= 1 + smsize = 100*1000*1000 + elif re.search(".264",ext): + level= 5 + smsize = 10*1000*1000 + elif re.search(".mp4",ext): + level = 10 + smsize = 10*1000*1000 + elif re.search(".mkv",ext): + level = 15 + smsize = 10*1000*1000 + dp=[] + if level > 0 : + if os.path.exists(os.path.join(path,title+".ts")) and os.path.exists(os.path.join(path,title+".ts.b25")): + if os.path.getsize(os.path.join(path,title+".ts"))*12>os.path.getsize(os.path.join(path,title+".ts.b25")): + dp.append(os.path.join(path,title+".ts.b25")) + elif os.path.getsize(os.path.join(path,title+".ts"))>200*1000*1000: + dp.append(os.path.join(path,title+".ts.b25")) + if level > 4 : + if configreader.getConfEnv("remove_ts")=="1": + dp.append(os.path.join(path,title+".ts")) + if level > 9 : + dp.append(os.path.join(path,title+".avi")) + dp.append(os.path.join(path,title+".264")) + dp.append(os.path.join(path,title+".120.avi")) + dp.append(os.path.join(path,title+".noodml.avi")) + dp.append(os.path.join(path,title+".aac")) + dp.append(os.path.join(path,title+".m2v")) + dp.append(os.path.join(path,title+"_1.aac")) + dp.append(os.path.join(path,title+"_2.aac")) + dp.append(os.path.join(path,title+"_1.mp3")) + dp.append(os.path.join(path,title+"_2.mp3")) + dp.append(os.path.join(path,title+".srt")) + if level > 14 : + dp.append(os.path.join(path,title+".mp4")) + if os.path.exists(os.path.join(path,title+ext)): + if os.path.getsize(os.path.join(path,title+ext))>smsize: + for ip in dp: + try: + os.remove(ip) + except: + "" diff --git a/rec10/auto_rec.py b/rec10/auto_rec.py new file mode 100644 index 0000000..5e4b8d5 --- /dev/null +++ b/rec10/auto_rec.py @@ -0,0 +1,85 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import n_gram +import rec10d +def getDBKey(key,chtxt): + return rec10d.rec10db.select_by_key_in_auto_bayes_key(key, chtxt) +def changeDBEpg(chtxt,beforenum,newnum): + rec10d.rec10db.change_ratio_all_reduce_in_auto_bayes_key(chtxt, beforenum, newnum) +def changeDBNum(chtxt,recaddnum,alladdnum): + """ + add num.(Not change) + """ + rec10d.rec10db.add_num_in_auto_bayes_key(chtxt, recaddnum,alladdnum) +def changeDBRatioRec(key,chtxt,beforenum,addnum): + rec10d.rec10db.change_ratio_rec_in_auto_bayes_key(key, chtxt, beforenum, addnum) +def changeDBRatioMultiRec(chtxt,beforenum,list): + rec10d.rec10db.change_multi_ratio_rec_in_auto_bayes_key(chtxt, beforenum, list) +def changeDBReduceRatioRec(chtxt,beforenum,addnum): + rec10d.rec10db.change_ratio_rec_reduce_in_auto_bayes_key(chtxt, beforenum, addnum) +def changeDBRatioAll(key,chtxt,beforenum,addnum): + rec10d.rec10db.change_ratio_all_in_auto_bayes_key(key, chtxt, beforenum, addnum) +def changeDBRatioMultiAll(chtxt,beforenum,list): + rec10d.rec10db.change_multi_ratio_all_in_auto_bayes_key(chtxt,beforenum, list) +def getDBNum(chtxt): + ret=getDBKey("NUM", chtxt) + if len(ret)<3: + rec10d.rec10db.add_in_auto_bayes_key("NUM", chtxt, 1,1) + ret=getDBKey("NUM", chtxt) + return ret +def updateRecall(chtxt,titles,descs,newnum): + """ + update recall + """ + titles=" "+titles+" " + descs=" "+descs+" " + str1=titles*2+descs+titles*2 + noun=n_gram.getNounQuadGram(str1) + bnum=getDBNum(chtxt)[3] + if bnum<1: + bnum=100 + changeDBRatioMultiAll(chtxt, bnum,noun) + changeDBEpg(chtxt, bnum, newnum) + changeDBNum(chtxt, 0, newnum) +def addKey(chtxt,title,desc): + title=u" "+title+u" " + desc=u" "+desc+u" " + str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。 + noun=n_gram.getNounQuadGram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。 + bnum=getDBNum(chtxt)[2] + if bnum<1: + bnum=1 + changeDBRatioMultiRec(chtxt, bnum, noun) + changeDBNum(chtxt,1,0) + changeDBReduceRatioRec(chtxt, bnum,1) +def calcKey(chtxt,title,desc): + """ + + """ + title=u" "+title+u" " + desc=u" "+desc+u" " + str1=title*2+desc+title*2##タイトルは重視したいので幾度か足す。 + noun=n_gram.getNounQuadGram(str1)#nounは辞書のキーに文字を、中身に出現回数を書いたもの。 + tnum=1 + nump=0 + for key,num in noun.items(): + pp=getDBKey(key,chtxt) + pp2=getDBKey(key,"ALL") + if len(pp)>3: + tarec=0 + taall=0 + if len(pp2)>3: + tarec=pp2[2] + taall=pp2[3] + trec=pp[2] + tall=pp[3] + + tnum=tnum+1 + p=(1000*trec+5)/(1000*tall+5) + p=p*p*100 + p2=(1000*tarec+5)/(1000*taall+5) + p2=p2*100 + nump=nump+p+p2 + return int(nump/tnum) diff --git a/rec10/auto_test.py b/rec10/auto_test.py new file mode 100644 index 0000000..74fd961 --- /dev/null +++ b/rec10/auto_test.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import os.path +import time +import optparse +import sys +import datetime + +import configreader +import chdb +import tv2mp4 +import tv2ts +def testAllCHEncode(option,stime): + chl=chdb.getAllCH() + print chl + path= configreader.getConfPath("test") + tpath=os.path.join(path, "encode_test") + if not os.path.exists(tpath): + os.mkdir(tpath) + dnowt=datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+"_"+option+"" + tpatht=os.path.join(tpath,dnowt) + if not os.path.exists(tpatht): + os.mkdir(tpatht) + if len(chl)>0: + for t in chl: + print t + pathname=os.path.join(tpatht,t['chtxt']) + print pathname + tv2ts.tv2ts(pathname+".ts",t['ch'],t['csch'], stime,t['tsid']) + tv2mp4.ts2mp4(pathname+".ts", pathname+".mp4", option) + time.sleep(2) +if __name__ == "__main__": + usage="usage: " + version="%prog 0.9.7" + parser=optparse.OptionParser(usage=usage,version=version) + parser.add_option("-e","--Encode",action="store",type="string",dest="encode_option",default="",metavar="TITLE",help="encode test(option)") + (opts,args)=parser.parse_args(sys.argv) + if opts.encode_option != "":##-sの場合 + print "test_all_ch_encode" + testAllCHEncode(opts.encode_option, "10") diff --git a/rec10/chdata.py b/rec10/chdata.py new file mode 100644 index 0000000..0b2120a --- /dev/null +++ b/rec10/chdata.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +import os.path +import configreader +import xml.dom.minidom +import scan_ch +import datetime + +import rec10d + +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" + +def chAdd(bctype, chtxt, ch, csch,tsid="0"):#すべて文字列 + tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch,tsid, u"2010-01-01 00:00:00",u"2010-01-01 00:00:00",tnow) +def addCHlist(cl): + if len(cl)>0: + for c in cl: + chAdd(c[0],c[1],c[2],c[3]) +def getChList(xmlpath): + dom=xml.dom.minidom.parse(file(xmlpath)) + chlist=[] + for ch in dom.getElementsByTagName('channel'): + bctype=ch.getAttribute("bctype") + chd=ch.getAttribute("ch") + csch=ch.getAttribute("csch") + chtxt=ch.getAttribute("chtxt") + ontv=ch.getAttribute("ontvcode") + chlist.append([bctype,ontv,chtxt,chd,csch]) + return chlist +def deleteChListALL(): + rec10d.rec10db.new_epg_ch() +if __name__ == "__main__": + deleteChListALL() + scan_ch.searchCh() diff --git a/rec10/chdb.py b/rec10/chdb.py new file mode 100644 index 0000000..9763b53 --- /dev/null +++ b/rec10/chdb.py @@ -0,0 +1,101 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze + # モジュール属性 argv を取得するため +import rec10d + +def searchCHFromChtxt(chtxtin): + chtxtt=chtxtin.replace("_0","_%") + ret = [] + for datum in rec10d.rec10db.select_by_chtxt_epg_ch(chtxtt): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4],'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchCHFromBctype(bctypein): + ret = [] + for datum in rec10d.rec10db.select_by_bctype_epg_ch(bctypein): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchCHFromCh(chin): + ret = [] + for datum in rec10d.rec10db.select_by_ch_epg_ch(chin): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchCHFromCsch(cschin): + ret = [] + for datum in rec10d.rec10db.select_by_csch_epg_ch(cschin): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchAllCHFromCh(chin): + ret = [] + for datum in rec10d.rec10db.select_by_ch_epg_ch(chin): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret +def getAllCH(): + ret = [] + for datum in rec10d.rec10db.select_all_epg_ch(): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret +def update(): + ret = [] + CSupdate = 0 + CS2update = 0 + BSupdate = 0 + rec10d.rec10db.set_new_status("8") + for datum in rec10d.rec10db.select_get_update_epg_ch("6"): + bctype = datum[0] + if bctype == "cs1" or bctype == u"cs1": + if CSupdate == 0: + ret.append(u"cs1") + CSupdate = 1 + elif bctype == "cs2" or bctype == u"cs2": + if CS2update == 0: + ret.append(u"cs2") + CS2update = 1 + elif bctype == "bs" or bctype == u"bs": + if BSupdate == 0: + ret.append(u"bs") + BSupdate = 1 + else: + ret.append(bctype) + return ret +def changeCHShow(chtxt,isshow): + rec10d.rec10db.change_visible_epg_ch(chtxt, isshow) +def updateLogo(): + ret=[] + BSCSUpdate=0 + for datum in rec10d.rec10db.select_get_updatelogo_epg_ch("720"): + bctype=datum[0] + if bctype == "cs1" or bctype == u"cs1": + if BSCSUpdate==0: + ret.append(u"bs") + BSCSUpdate=1 + elif bctype == "cs2" or bctype == u"cs2": + if BSCSUpdate==0: + ret.append(u"bs") + BSCSUpdate=1 + elif bctype == "bs" or bctype == u"bs": + if BSCSUpdate==0: + ret.append(u"bs") + BSCSUpdate=1 + else: + ret.append(bctype) + return ret diff --git a/rec10/checker.py b/rec10/checker.py new file mode 100644 index 0000000..4e9bcc0 --- /dev/null +++ b/rec10/checker.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import os.path +import time + +def checkB25Decode(b25filepath, decodedfilepath , csch): + ret = 0 + if os.path.isfile(decodedfilepath):##tsファイルが存在している + dtime = time.time()-os.path.getmtime(decodedfilepath) + dtime = int(dtime) + if dtime > 20: + if csch>0: + if (compareFilesize(b25filepath, decodedfilepath, 10) and minimizeCheck(decodedfilepath, 800)): + ret = 1 + else: + if (compareFilesize(b25filepath, decodedfilepath, 60) and minimizeCheck(decodedfilepath, 800)): + ret = 1 + else: + time.sleep(30) + dtime = time.time()-os.path.getmtime(decodedfilepath) + dtime = int(dtime) + if dtime > 20: + if csch>0: + if (compareFilesize(b25filepath, decodedfilepath, 10) and minimizeCheck(decodedfilepath, 800)): + ret = 1 + else: + if (compareFilesize(b25filepath, decodedfilepath, 60) and minimizeCheck(decodedfilepath, 800)): + ret = 1 + #recdblist.printutf8("deleting b25 is " + str(ret)) + return ret +def compareFilesize(pathbase, path, percentage): + """ + return true if size of path is larger than that of pathbase. + percentage is int(0< <100) + """ + if not os.path.exists(pathbase): + return 0 + basesize = os.path.getsize(pathbase) + pathsize = os.path.getsize(path) + size = pathsize * 100-basesize * percentage + if size < 0: + return 0 + else: + return 1 +def minimizeCheck(filepath, minsize): + """ + minsize is Megabytes + """ + if os.path.getsize(filepath) > minsize * 1000 * 1000: + return 1 + else: + return 0 diff --git a/rec10/classify.py b/rec10/classify.py new file mode 100644 index 0000000..a496f1b --- /dev/null +++ b/rec10/classify.py @@ -0,0 +1,162 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import os +import os.path +import optparse +import sys + +import configreader +import recdblist +import auto_move +import guess +recordedpath=unicode(configreader.getConfPath("recorded"),'utf-8') +recpath=unicode(configreader.getConfPath("recpath"),'utf-8') + +if __name__ == "__main__": + usage="usage: %prog read -h" + version="%prog 0.9.4" + parser=optparse.OptionParser(usage=usage,version=version) + parser.add_option("-s","--search",action="store",type="string",dest="ltitle",default="",metavar="TITLE",help="test to search where the title should be contained(test for -e)") + parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)") + parser.add_option("-D","--Delete",action="store_true",dest="delete",default=False,help="auto delete tempfile mode(not a test)") + parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)") + parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -A)") + parser.add_option("-t","--tssearch",action="store_true",dest="tssearch",default=False,help="Ts move auto search") + parser.add_option("-T","--Tsmove",action="store_true",dest="tsmove",default=False,help="Ts auto move.") + parser.add_option("-S","--SeriesNum",action="store",type="string",dest="seriespath",default="",metavar="TITLE",help="Search Series Number in the path.") + parser.add_option("-m","--manual",action="store_true",dest="manual",default=False,help="manual classifying mode asking for y/n(not a test)") + #parser.add_option("-f","--filenumlist",action="store_true",dest="filenumlist",default=False,help="Guess Program Number.") + + (opts,args)=parser.parse_args(sys.argv) + if opts.ltitle!="":##-sの場合 + ltitle=unicode(opts.ltitle,'utf-8') + sf=guess.searchFolder(ltitle, recordedpath) + print "###MKV###" + recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mkv")+".mkv"),verbose_level=100) + print "\n" + print "###MP4###" + recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mp4")+".mp4"),verbose_level=100) + print "\n" + elif opts.auto:##-A の場合 + sa=auto_move.searchFile(recpath, recordedpath, ".mkv") + for t in sa: + recdblist.printutf8(u"自動推測実行中-MKV",verbose_level=100) + sf=guess.searchFolder(t,recordedpath) + if sf!="": + recdblist.printutf8(u"移動先",verbose_level=100) + recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mkv")+".mkv"),verbose_level=100) + recdblist.printutf8(u"実行中",verbose_level=100) + auto_move.execMove(t, recpath, recordedpath,".mkv",1) + else: + recdblist.printutf8(t+" can't find matching folder",verbose_level=100) + sa=auto_move.searchFile(recpath, recordedpath, ".mp4") + for t in sa: + recdblist.printutf8(u"自動推測実行中-MP4",verbose_level=100) + sf=guess.searchFolder(t,recordedpath,200) + if sf!="": + recdblist.printutf8(u"移動先",verbose_level=100) + recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100) + recdblist.printutf8(u"実行中",verbose_level=100) + auto_move.execMove(t, recpath, recordedpath,".mp4",1) + else: + recdblist.printutf8(t+" can't find matching folder",verbose_level=100) + elif opts.manual:##-m の場合 + # mkv無視します + sa=auto_move.searchFile(recpath, recordedpath, ".mp4") + for t in sa: + sf=guess.searchFolder(t,recordedpath,200) + if sf!="": + recdblist.printutf8(u"○候補:"+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100) + ans = raw_input("移動しますか? (y/n/h)") + if ans == 'y': + recdblist.printutf8(u"移動を実行します",verbose_level=100) + auto_move.execMove(t, recpath, recordedpath,".mp4",1) + elif ans == 'n': + recdblist.printutf8(u"移動を中止します",verbose_level=100) + elif ans == 'h': + recdblist.printutf8(u"移動のヒント",verbose_level=100) + recdblist.printutf8(u"FIXME:not implemented",verbose_level=100) + else: + recdblist.printutf8(u"×不明:"+t,verbose_level=100) + elif opts.delete:##-Dの場合 + sa=auto_move.searchFile(recpath, recordedpath,".mkv") + for t in sa: + auto_move.execDelete(t, recpath) + sa=auto_move.searchFile(recpath, recordedpath,".mp4") + for t in sa: + auto_move.execDelete(t, recpath) + elif opts.list:##-lの場合 + sa=auto_move.searchFile(recpath, recordedpath,".mkv") + for t in sa: + sf=guess.searchFolder(t,recordedpath) + if sf!="": + recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mkv")+".mkv"),verbose_level=100) + sa=auto_move.searchFile(recpath, recordedpath,".mp4") + for t in sa: + sf=guess.searchFolder(t,recordedpath) + if sf!="": + recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100) + elif opts.etitle!="": + if os.path.exists(os.path.join(recpath, etitle+".mkv")): + auto_move.execMove(etitle,recpath, recordedpath,".mkv",1) + elif os.path.exists(os.path.join(recpath, etitle+".mp4")): + auto_move.execMove(etitle,recpath, recordedpath,".mp4",1) + elif opts.tssearch:## -tの場合 + tsmovepath="" + try: + tsmovepath=unicode(configreader.getConfPath("ts_movepath"),'utf-8') + except: + "" + if tsmovepath!="": + sa=auto_move.searchFile(recpath, tsmovepath,".ts") + for t in sa: + sf=guess.searchFolder(t,tsmovepath,700) + if sf!="": + recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".ts")+".ts")) + print "\n" + sa=auto_move.searchFile(recpath, tsmovepath,".ts") + else: + recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100) + elif opts.tsmove:##-Tの場合 + tsmovepath="" + try: + tsmovepath=unicode(configreader.getConfPath("ts_movepath"),'utf-8') + except: + "" + if tsmovepath!="": + sa=auto_move.searchFile(recpath, tsmovepath,".ts") + for t in sa: + sf=guess.searchFolder(t,tsmovepath,700) + if sf!="": + recdblist.printutf8(u"移動先",verbose_level=100) + recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".ts")+".ts"),verbose_level=100) + recdblist.printutf8(u"実行中",verbose_level=100) + auto_move.execMove(t, recpath, tsmovepath,".ts",0) + sa=auto_move.searchFile(recpath, tsmovepath,".ts") + else: + recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100) + elif opts.seriespath!="":##-Sの場合##与えられたパスにシリーズがそろっているかを調べる。 + ss=guess.detSeriesNum(opts.seriespath) + for sstitle, ssv in ss.iteritems(): + if len(ssv)>0: + maxt=0 + bt=0 + alr=[] + for ssi,ssiv in ssv.iteritems(): + alr.append(ssi) + if maxt 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S") + if r[9]!=None: + r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S") + else: + r[9]="2012-04-01 00:00:00" + r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) + return ret + def select_by_bctype_epg_ch(self, bctype): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT bctype,chtxt,ch,csch,tsid,updatetime,status,chname,status,visible,logoupdate,scanupdate \ + FROM epg_ch \ + WHERE bctype = %s", \ + (bctype,)) + ret = [] + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + #recdblist.printutf8(dl) + r = list(dl) + r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S") + if r[10]!=None: + r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S") + else: + r[10]="2011-04-01 00:00:00" + r[11] = r[11].strftime("%Y-%m-%d %H:%M:%S") + r[6] = str(r[6]) + ret.append(r) + import random + ret.insert(0,ret[random.randint(0,len(ret)-1)]) + return ret + def select_by_ch_epg_ch(self, ch): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT \ + bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \ + FROM epg_ch \ + WHERE ch = %s", \ + (ch,)) + ret = [] + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S") + r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S") + r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) + return ret + def select_by_csch_epg_ch(self, csch): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT \ + bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \ + FROM epg_ch \ + WHERE csch = %s", \ + (csch,)) + ret = [] + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S") + r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S") + r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) + return ret + def select_all_epg_ch(self): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \ + FROM epg_ch \ + ") + ret = [] + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S") + r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S") + r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) + return ret + def change_visible_epg_ch(self,chtxt,visible): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch SET visible=%s WHERE chtxt=%s",(visible,chtxt)) + self.close_db(db) + def change_logodata_epg_ch(self,chtxt,logonum,logodata): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch SET logo"+str(logonum)+"=%s WHERE chtxt=%s",(logodata,chtxt)) + self.close_db(db) + def set_new_status(self,dhour): + db = self.connect_db() + dbexe = db[1].execute("UPDATE epg_ch \ + SET status = 1 \ + WHERE \ + ( \ + updatetime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR) \ + AND \ + status = 0 \ + )"\ + ) + def select_get_update_epg_ch(self, dhour): + db = self.connect_db() + dbexe = db[1].execute("SELECT bctype,chtxt,status FROM epg_ch \ + WHERE (\ + ( \ + updatetime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR) \ + AND \ + status = 1 \ + ) \ + OR \ + status > 1 )\ + ORDER BY status DESC") + ret = [] + #recdblist.printutf8(dbexe) + if dbexe > 0: + ret = db[1].fetchall() + self.close_db(db) + return ret + def select_get_updatelogo_epg_ch(self, dhour): + db = self.connect_db() + dbexe = db[1].execute("SELECT bctype,chtxt,logostatus FROM epg_ch \ + WHERE (\ + ( \ + updatetime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR) \ + AND \ + logostatus = 1 \ + ) \ + OR \ + logostatus > 1 )\ + ORDER BY status DESC") + ret = [] + #recdblist.printutf8(dbexe) + if dbexe > 0: + ret = db[1].fetchall() + self.close_db(db) + return ret + def update_by_bctype_epg_ch(self, bctype): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch \ + SET \ + updatetime=now() , \ + status = 1 \ + WHERE bctype = %s", (bctype,)) + self.close_db(db) + + def update_by_bctype_and_chtxt_epg_ch(self, bctype, chtxt): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch \ + SET \ + updatetime=now() , \ + status = 1\ + WHERE bctype = %s AND chtxt = %s", (bctype, chtxt)) + self.close_db(db) + def update_chname_by_chtxt_epg_ch(self,chtxt,chname): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch \ + SET \ + chname = %s \ + WHERE chtxt = %s", (chname,chtxt)) + self.close_db(db) + def update_status_by_bctype_epg_ch(self, bctype, status): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch \ + SET \ + status=%s , \ + updatetime=now() \ + WHERE bctype = %s", \ + (status, bctype)\ + ) + self.close_db(db) + def update_logostatus_by_bctype_epg_ch(self,bctype,logostatus): + db = self.connect_db() + db[1].execute("\ + UPDATE epg_ch \ + SET \ + logostatus=%s , \ + logoupdate=now() \ + WHERE bctype = %s", \ + (logostatus, bctype)\ + ) + self.close_db(db) + def add_auto_proc_tmp(self,type,title,chtxt): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into auto_proc_tmp \ + (type,title,chtxt) \ + values (%s,%s,%s)',(type,title,chtxt)) + ##db.commit() + self.close_db(db) + def new_auto_proc_tmp(self): + db = self.connect_db() + try: + db[1].execute('drop table auto_proc_tmp') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))): + recdblist.addCommonlogEX("Error", "new_auto_proc_tmp drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + try: + db[1].execute('\ + CREATE TABLE auto_proc_tmp \ + (\ + type VARCHAR(20),\ + title VARCHAR(100) PRIMARY KEY,\ + chtxt VARCHAR(30),\ + UNIQUE unibayeskey(title)\ + )') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_auto_proc_tmp (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + self.close_db(db) + def update_auto_proc(self): + db = self.connect_db() + try: + db[1].execute('INSERT INTO auto_proc SELECT * FROM auto_proc_tmp') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "update_auto_proc (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + self.close_db(db) + def new_auto_proc(self): + db = self.connect_db() + try: + db[1].execute('drop table auto_proc') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))): + recdblist.addCommonlogEX("Error", "new_auto_proc drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + try: + db[1].execute('\ + CREATE TABLE auto_proc \ + (\ + type VARCHAR(20),\ + title VARCHAR(100) PRIMARY KEY,\ + chtxt VARCHAR(30),\ + UNIQUE unibayeskey(title)\ + )') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_auto_proc (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + self.close_db(db) + def add_auto_proc(self,type,title,chtxt): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into auto_proc \ + (type,title,chtxt) \ + values (%s,%s,%s)',(type,title,chtxt)) + ##db.commit() + self.close_db(db) + def drop_in_settings(self): + db = self.connect_db() + try: + db[1].execute('drop table in_settings') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))): + recdblist.addCommonlogEX("Error", "drop_in_settings (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + def new_in_settings(self): + db = self.connect_db() + try: + db[1].execute('\ + CREATE TABLE in_settings \ + (\ + auto_jbk TINYINT,\ + auto_bayes TINYINT,\ + auto_opt VARCHAR(20),\ + auto_del_tmp TINYINT\ + )') + db[1].execute("INSERT IGNORE into in_settings VALUE (0,0,\"H\",1)") + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_in_settings (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + self.close_db(db) + def select_all_in_settings(self): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT auto_jbk,auto_bayes,auto_del_tmp,auto_opt \ + FROM in_settings \ + ") + ret = [] + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + r[0]=str(r[0]) + r[1]=str(r[1]) + r[2]=str(r[2]) + r[3]=r[3] + ret.append(r) + return ret + def add_in_timeline_log(self , chtxt="", title="", btime="", etime="", opt="", exp="", longexp="", category=""): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into in_timeline_log \ + (chtxt,title,btime,etime,opt,exp,longexp,category) \ + values (%s,%s,%s,%s,%s,%s,%s,%s)', \ + ( chtxt, title, btime, etime, opt,exp,longexp,category)) + ##db.commit() + self.close_db(db) + def del_in_timeline_log(self, title="", chtxt="", btime=""): + """ + + """ + db = self.connect_db() + db[1].execute("\ + DELETE FROM in_timeline_log \ + WHERE title = %s AND chtxt = %s AND btime = %s", \ + (title, chtxt, btime)) + #db.commit() + self.close_db(db) + def new_in_timeline_log(self): + db = self.connect_db() + try: + db[1].execute('\ + CREATE TABLE in_timeline_log \ + (\ + id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\ + chtxt VARCHAR(20),\ + title VARCHAR(100),\ + btime DATETIME,\ + etime DATETIME,\ + opt VARCHAR(20),\ + exp VARCHAR(200),\ + longexp TEXT,\ + category VARCHAR(100),\ + UNIQUE uni (chtxt,title,btime,category)\ + )') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_in_timeline_log (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + + self.close_db(db) + def select_chtxt_by_title_timeline_log(self,title): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT chtxt \ + FROM in_timeline_log \ + WHERE title LIKE \"%"+title+"%\"\ + GROUP by chtxt\ + ORDER by sum(1) DESC limit 1") + retdb=db[1].fetchall() + ret="" + if ret!=None: + if len(retdb)>0: + ret=retdb[0][0] + self.close_db(db) + return ret + def add_timeline(self, type="", chtxt="", title="", btime="", etime="", deltatime="", deltaday="", opt="" ,counter=-1): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into timeline \ + (type,chtxt,title,btime,etime,deltatime,deltaday,opt,counter) \ + values (%s,%s,%s,%s,%s,%s,%s,%s,%s)', \ + (type, chtxt, title, btime, etime, deltatime, deltaday, opt ,counter)) + ##db.commit() + self.close_db(db) + def update_epg_timeline(self,type,chtxt,title,btime,epgbtime,epgetime,epgtitle,epgexp,epgcategory): + db = self.connect_db() + db[1].execute('\ + UPDATE timeline \ + SET epgbtime=%s,epgetime=%s,epgtitle=%s,epgexp=%s,epgcategory=%s \ + WHERE type=%s AND chtxt=%s AND title=%s AND btime=%s ', \ + (epgbtime,epgetime,epgtitle,epgexp,epgcategory,type, chtxt, title, btime)) + ##db.commit() + self.close_db(db) + def update_status_change_timeline(self,type,chtxt,title,btime,epgchange): + db = self.connect_db() + db[1].execute('\ + UPDATE timeline \ + SET epgchange =%s \ + WHERE type=%s AND chtxt=%s AND title=%s AND btime=%s ', \ + (epgchange , type, chtxt, title, btime)) + ##db.commit() + self.close_db(db) + def update_status_dup_timeline(self,type,chtxt,title,btime,epgduplicate): + db = self.connect_db() + db[1].execute('\ + UPDATE timeline \ + SET epgduplicate =%s \ + WHERE type=%s AND chtxt=%s AND title=%s AND btime=%s ', \ + (epgduplicate , type, chtxt, title, btime)) + ##db.commit() + self.close_db(db) + def del_timeline(self, type="", title="", chtxt="", btime=""): + """ + + """ + db = self.connect_db() + db[1].execute("\ + DELETE FROM timeline \ + WHERE type = %s AND title = %s AND chtxt = %s AND btime = %s", \ + (type, title, chtxt, btime)) + #db.commit() + self.close_db(db) + def select_all_timeline(self): + db = self.connect_db() + recdata = [] + dbr = db[1].execute("\ + SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline") + dbl = db[1].fetchall() + self.close_db(db) + if dbr > 0: + recdata = self.getdic_timeline(dbl) + return recdata + def select_bytime_timeline(self, dminutes): + db = self.connect_db() + recdatum = [] + #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )") + dbr = db[1].execute("SELECT \ + type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline \ + WHERE btime BETWEEN DATE_SUB(now(),INTERVAL " + dminutes + " MINUTE ) AND \ + DATE_ADD(now(),INTERVAL " + dminutes + " MINUTE )") + dbl = db[1].fetchall() + self.close_db(db) + #recdblist.printutf8(dbl) + if dbr > 0: + recdatum = self.getdic_timeline(dbl) + return recdatum + def select_by_name_time_timeline(self,title,btime,btime2): + db = self.connect_db() + recdatum = [] + #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )") + dbr = db[1].execute("SELECT \ + type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline \ + WHERE btime > %s AND \ + btime < %s AND title = %s",(btime,btime2,title)) + dbl = db[1].fetchall() + self.close_db(db) + #recdblist.printutf8(dbl) + if dbr > 0: + recdatum = self.getdic_timeline(dbl) + return recdatum + def select_bytime_all_timeline(self,btime,etime): + db = self.connect_db() + recdatum = [] + #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )") + dbr = db[1].execute("SELECT \ + type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline \ + WHERE btime >= %s AND \ + etime <= %s",(btime,etime)) + dbl = db[1].fetchall() + self.close_db(db) + #recdblist.printutf8(dbl) + if dbr > 0: + recdatum = self.getdic_timeline(dbl) + return recdatum + def select_byepgtime_all_timeline(self,epgbtime,epgetime): + db = self.connect_db() + recdatum = [] + #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )") + dbr = db[1].execute("SELECT \ + type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline \ + WHERE epgbtime >= %s AND \ + epgetime <= %s",(epgbtime,epgetime)) + dbl = db[1].fetchall() + self.close_db(db) + #recdblist.printutf8(dbl) + if dbr > 0: + recdatum=self.getdic_timeline(dbl) + return recdatum + def select_byepgtime_over_timeline(self,epgbtime,epgetime): + db = self.connect_db() + recdatum = [] + #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )") + dbr = db[1].execute("SELECT \ + type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline \ + WHERE (NOT(( timeline.epgetime <= %s )OR( timeline.epgbtime >= %s )))"\ + ,(epgbtime,epgetime)) + dbl = db[1].fetchall() + self.close_db(db) + #recdblist.printutf8(dbl) + if dbr > 0: + recdatum=self.getdic_timeline(dbl) + return recdatum + def count_schedule_timeline(self, btime, etime): + """ + count rectasknum + return [te num,bs/cs num] + """ + db = self.connect_db() + dbexe = "SELECT type,epg_ch.bctype,timeline.chtxt,title FROM timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt" + dbexe = dbexe + " WHERE ((NOT(( timeline.etime <= %s )OR( timeline.btime >= %s ))) OR ((timeline.btime = %s) AND (timeline.etime = %s) ) )" + Srec = 0 + Trec = 0 + db[1].execute(dbexe, (btime, etime,btime,etime)) + dbl=db[1].fetchall() + for typet, bctypet, chtxtt, titlet in dbl: + if (typet == recdblist.REC_RESERVE) or (typet == recdblist.REC_FINAL_RESERVE) or (typet == recdblist.REC_KEYWORD) or (typet == recdblist.REC_KEYWORD_EVERY_SOME_DAYS): + if bctypet.find("cs") > -1: + Srec = Srec + 1 + elif bctypet.find("bs") > -1: + Srec = Srec + 1 + elif bctypet.find("te") > -1: + Trec = Trec + 1 + self.close_db(db) + return [Trec, Srec] + def search_schedule_timeline(self,btime,etime): + """ + count rectasknum + return [(type,bctype,chtxt,title,btime,etime)] + """ + db = self.connect_db() + dbexe = "SELECT type,epg_ch.bctype,timeline.chtxt,title,timeline.btime,timeline.etime FROM timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt" + dbexe = dbexe + " WHERE ((NOT(( timeline.etime <= %s )OR( timeline.btime >= %s ))) OR ((timeline.btime = %s) AND (timeline.etime = %s) ) )" + ret=[] + db[1].execute(dbexe, (btime, etime,btime,etime)) + dbl=db[1].fetchall() + for typet, bctypet, chtxtt, titlet , btimet, etimet in dbl: + if (typet == recdblist.REC_RESERVE) or (typet == recdblist.REC_FINAL_RESERVE) or (typet == recdblist.REC_KEYWORD) or (typet == recdblist.REC_KEYWORD_EVERY_SOME_DAYS): + ret.append([typet,bctypet,chtxtt,titlet,btimet,etimet]) + self.close_db(db) + return ret + def count_epgschedule_timeline(self, epgbtime, epgetime): + """ + count rectasknum + return [te num,bs/cs num] + """ + db = self.connect_db() + dbexe = "SELECT type,epg_ch.bctype,timeline.chtxt,title FROM timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt" + dbexe = dbexe + " WHERE (NOT(( timeline.epgetime <= %s )OR( timeline.epgbtime >= %s )))" + Srec = 0 + Trec = 0 + db[1].execute(dbexe, (epgbtime, epgetime)) + dbl=db[1].fetchall() + for typet, bctypet, chtxtt, titlet in dbl: + if (typet == recdblist.REC_RESERVE) or (typet == recdblist.REC_FINAL_RESERVE) or (typet == recdblist.REC_KEYWORD) or (typet == recdblist.REC_KEYWORD_EVERY_SOME_DAYS): + if bctypet.find("cs") > -1: + Srec = Srec + 1 + elif bctypet.find("bs") > -1: + Srec = Srec + 1 + elif bctypet.find("te") > -1: + Trec = Trec + 1 + self.close_db(db) + return [Trec, Srec] + def search_epgschedule_timeline(self,epgbtime,epgetime): + """ + count rectasknum + return [(type,bctype,chtxt,title,btime,etime)] + """ + db = self.connect_db() + dbexe = "SELECT type,epg_ch.bctype,timeline.chtxt,title,timeline.btime,timeline.etime FROM timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt" + dbexe = dbexe + " WHERE ((NOT(( timeline.epgetime <= %s )OR( timeline.epgbtime >= %s ))) OR ((timeline.epgbtime = %s) AND (timeline.epgetime = %s) ) )" + ret=[] + db[1].execute(dbexe, (epgbtime, epgetime,epgbtime,epgetime)) + dbl=db[1].fetchall() + for typet, bctypet, chtxtt, titlet , btimet, etimet in dbl: + if (typet == recdblist.REC_RESERVE) or (typet == recdblist.REC_FINAL_RESERVE) or (typet == recdblist.REC_KEYWORD) or (typet == recdblist.REC_KEYWORD_EVERY_SOME_DAYS): + ret.append([typet,bctypet,chtxtt,titlet,btimet,etimet]) + self.close_db(db) + return ret + def select_bytime_bychtxt_all_timeline(self,btime,etime,chtxt): + db = self.connect_db() + recdatum = [] + #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )") + dbr = db[1].execute("SELECT \ + type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\ + FROM timeline \ + WHERE btime > %s AND \ + etime < %s\ + AND chtxt=%s ",(btime,etime,chtxt)) + dbl = db[1].fetchall() + self.close_db(db) + #recdblist.printutf8(dbl) + if dbr > 0: + recdatum = self.getdic_timeline(dbl) + return recdatum + def getdic_timeline(self,timelinelists): + recdatum=[] + for typet, chtxt, title, btime, etime, deltatime, deltaday, opt ,epgbtimet , epgetimet ,epgtitlet ,epgduplicatet ,epgchanget ,countert in timelinelists: + ret = {} + ret['type'] = typet + ret['chtxt'] = chtxt + ret['title'] = title + btime = btime.strftime("%Y-%m-%d %H:%M:%S") + etime = etime.strftime("%Y-%m-%d %H:%M:%S") + ret['btime'] = btime + ret['etime'] = etime + ret['opt'] = opt + try: + ret['epgbtime'] = epgbtimet.strftime("%Y-%m-%d %H:%M:%S") + ret['epgetime'] = epgetimet.strftime("%Y-%m-%d %H:%M:%S") + except: + ret['epgbtime'] = "2010-01-01 00:00:00" + ret['epgetime'] = "2010-01-01 00:00:00" + ret['epgtitle'] = epgtitlet + ret['epgduplicate'] = epgduplicatet + ret['epgchange'] = epgchanget + if deltatime == None or deltatime == "": + deltatime = "3" + if deltaday == None or deltaday == "": + deltaday = "7" + if typet == recdblist.REC_KEYWORD: + ret['deltatime'] = deltatime + elif typet == recdblist.REC_KEYWORD_EVERY_SOME_DAYS: + ret['deltatime'] = deltatime + ret['deltaday'] = deltaday + try: + ret['counter'] = int(countert) + except: + ret['counter']=-1 + recdatum.append(ret) + return recdatum + def delete_old_timeline(self, dhour): + db = self.connect_db() + db[1].execute("\ + DELETE FROM timeline \ + WHERE \ + btime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR )") + #db.commit() + self.close_db(db) + def new_in_auto_jbk_key(self): + db = self.connect_db() + try: + db[1].execute("\ + CREATE TABLE in_auto_jbk_key \ + (\ + id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\ + keyword VARCHAR(200),\ + auto TINYINT DEFAULT 0,\ + opt VARCHAR(20),\ + UNIQUE unijbk (keyword)\ + )") + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_in_auto_jbk_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + def add_in_auto_jbk_key(self,key): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into in_auto_jbk_key \ + (keyword) \ + values (%s)', \ + (key,)) + ##db.commit() + self.close_db(db) + def select_all_in_auto_jbk_key(self): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT keyword,auto,opt \ + FROM in_auto_jbk_key \ +vim ") + ret = [] + if dbexe > 0: + ret = db[1].fetchall() + self.close_db(db) + return ret + def drop_in_status(self): + db = self.connect_db() + try: + db[1].execute('drop table in_status') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))): + recdblist.addCommonlogEX("Error", "drop_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + def new_in_status(self): + db = self.connect_db() + try: + db[1].execute("\ + CREATE TABLE in_status \ + (\ + ts2avi TINYINT DEFAULT 0,\ + terec TINYINT DEFAULT 0,\ + bscsrec TINYINT DEFAULT 0,\ + b252ts TINYINT DEFAULT 0,\ + installed TINYINT DEFAULT 0,\ + version TINYINT\ + )") + db[1].execute("INSERT IGNORE into in_status VALUE (0,0,0,0,0,0)") + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + def select_all_in_status(self): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT ts2avi,terec,bscsrec,b252ts \ + FROM in_status \ + ") + ret = [] + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + r[0]=str(r[0]) + r[1]=str(r[1]) + r[2]=str(r[2]) + r[3]=str(r[3]) + ret.append(r) + return ret + def select_version_in_status(self): + db = self.connect_db() + version=0 + try: + dbexe = db[1].execute("\ + SELECT version \ + FROM in_status \ + ") + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + version=int(str(r[0])) + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "select_version_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + return version + def change_version_in_status(self,version): + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET version=%s",str(version)) + self.close_db(db) + def change_ts2avi_in_status(self,i): + """ + statuをiだけ増減する + iはint + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET ts2avi=ts2avi+%s",i) + self.close_db(db) + def change_terec_in_status(self,i): + """ + statuをiだけ増減する + iはint + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET terec=terec+%s",i) + self.close_db(db) + def change_bscsrec_in_status(self,i): + """ + statuをiだけ増減する + iはint + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET bscsrec=bscsrec+%s",i) + self.close_db(db) + def change_b252ts_in_status(self,i): + """ + statuをiだけ増減する + iはint + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET b252ts=b252ts+%s",i) + self.close_db(db) + def select_installed_in_status(self): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT ts2avi,terec,bscsrec,b252ts,installed \ + FROM in_status \ + ") + ret = 0 + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + for dl in dls: + r = list(dl) + ret=r[4] + return ret + def change_chscaned_in_status(self): + """ + installedを設定する + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET installed=2") + self.close_db(db) + def change_installed_in_status(self,num=1): + """ + installedを設定する + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_status SET installed=%s",(num,)) + self.close_db(db) + def new_epg_timeline(self, bctype): + db = self.connect_db() + try: + db[1].execute("\ + DELETE FROM epg_timeline \ + WHERE bctype = %s", \ + (bctype,)) + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and (inst[0]==1007 or inst[0]==1146))or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_epg_timeline delete (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + try: + db[1].execute("\ + CREATE TABLE epg_timeline \ + (\ + bctype VARCHAR(20),\ + channel VARCHAR(100) NOT NULL,\ + start VARCHAR(30),\ + stop VARCHAR(30),\ + title VARCHAR(100),\ + exp VARCHAR(200),\ + longexp TEXT,\ + category VARCHAR(100),\ + UNIQUE unitv(bctype,channel,start,stop,title)\ + )") + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_epg_timeline (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + #db.commit() + self.close_db(db) + def add_epg_timeline(self, bctype, channel, start, stop, title, desc,longdesc, category): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE INTO epg_timeline \ + VALUES (%s,%s,%s,%s,%s,%s,%s,%s)', \ + (bctype, channel, start, stop, title, desc,longdesc,category)) + #db.commit() + self.close_db(db) + def add_multi_epg_timeline(self, tvlists): + """ + tvlists is (bctype,channel,start,stop,title,desc,longdesc,category) lists. + """ + db = self.connect_db() + db[1].executemany('\ + INSERT IGNORE INTO epg_timeline \ + (bctype,channel,start,stop,title,exp,longexp,category) \ + values(%s,%s,%s,%s,%s,%s,%s,%s)', \ + tvlists) + self.close_db(db) + def select_by_time_ngram_epg_timeline(self, btime, etime, chtxt): + db = self.connect_db() + dbexe = "\ + SELECT \ + channel,title,start,stop,exp,longexp,category \ + FROM epg_timeline \ + WHERE start >= %s \ + AND \ + start <= %s \ + AND \ + channel LIKE %s" + dbcmd = db[1].execute(dbexe, (btime, etime, chtxt)) + retall = [] + if dbcmd > 0: + retall = db[1].fetchall() + self.close_db(db) + return retall + def select_by_time_keyword_auto_suggest_epg_timeline(self,keyword,btime,etime): + db = self.connect_db() + dbexe = "\ + SELECT \ + epg_ch.chtxt,title,start,stop,exp,longexp,category \ + FROM epg_timeline \ + INNER JOIN epg_ch \ + WHERE epg_ch.chtxt=epg_timeline.channel \ + AND \ + epg_ch.visible=1 \ + AND \ + start >= %s \ + AND \ + stop <= %s \ + AND \ + ( \ + ( title LIKE \'%%"+keyword+"%%\' ) \ + OR \ + ( exp LIKE \'%%"+keyword+"%%\' ) \ + OR \ + ( longexp LIKE \'%%"+keyword+"%%\' ) \ + )" + dbcmd = db[1].execute(dbexe,(btime, etime)) + retall = [] + if dbcmd > 0: + retall = db[1].fetchall() + self.close_db(db) + return retall + def new_in_auto_bayes_key(self): + db = self.connect_db() + try: + db[1].execute('CREATE TABLE in_auto_bayes_key \ + (\ + keychar VARCHAR(10),\ + chtxt VARCHAR(20),\ + ratio_rec DECIMAL(32,14),\ + ratio_all DECIMAL(32,14),\ + UNIQUE unibayeskey(keychar,chtxt)\ + )') + db[1].execute('CREATE INDEX keycharindex ON in_auto_bayes_key(keychar)') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + + def add_in_auto_bayes_key(self,key,chtxt,ratio_rec,ratio_all): + db = self.connect_db() + ratio_rec=str(ratio_rec) + ratio_all=str(ratio_all) + db[1].execute('\ + INSERT IGNORE INTO in_auto_bayes_key \ + (keychar,chtxt,ratio_rec,ratio_all) \ + values (%s,%s,%s,%s)',\ + (key,chtxt,ratio_rec,ratio_all)) + self.close_db(db) + def add_num_in_auto_bayes_key(self,chtxt,add_rec_num,add_all_num): + db = self.connect_db() + add_rec_num=str(add_rec_num) + add_all_num=str(add_all_num) + db[1].execute("\ + UPDATE in_auto_bayes_key SET ratio_rec=CONVERT(ratio_rec+%s,DECIMAL(32,14)),ratio_all=CONVERT(ratio_all+%s,DECIMAL(32,14)) WHERE keychar=\"NUM\" AND chtxt=%s",\ + (add_rec_num,add_all_num,chtxt)) + self.close_db(db) + def change_in_auto_bayes_key(self,key,chtxt,new_ratio_rec,new_ratio_all): + """ + """ + db = self.connect_db() + db[1].execute("\ + UPDATE in_auto_bayes_key SET ratio_rec=%s,ratio_all=%s WHERE keychar=%s AND chtxt=%s",(str(new_ratio_rec),str(new_ratio_all),key,chtxt)\ + ) + self.close_db(db) + def change_ratio_all_reduce_in_auto_bayes_key(self,chtxt,beforenum,newnum): + beforenum=str(beforenum) + newnum=str(newnum) + db = self.connect_db() + db[1].execute("\ + UPDATE in_auto_bayes_key SET ratio_all=CONVERT(ratio_all*%s/(%s+%s),DECIMAL(32,14)) WHERE chtxt=%s AND NOT (keychar=\"NUM\")",(beforenum,newnum,beforenum,chtxt)\ + ) + self.close_db(db) + def change_ratio_all_in_auto_bayes_key(self,key,chtxt,beforenum,addnum): + db = self.connect_db() + beforenumf=beforenum + beforenum=str(beforenum) + db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \ + VALUES (%s,%s,%s,%s)\ + ON DUPLICATE KEY UPDATE \ + ratio_all=CONVERT((ratio_all*%s+%s)/%s,DECIMAL(32,14))",(key,chtxt,"0",str(Decimal(addnum)/beforenumf),beforenum,chtxt,key)) + self.close_db(db) + def change_multi_ratio_all_in_auto_bayes_key(self,chtxt,beforenum,list): + """ + list={key:addnum}のリスト + """ + beforenumf=beforenum + beforenum=str(beforenum) + db = self.connect_db() + for i,j in list.items(): + retl=(i,chtxt,"0",str(Decimal(j)/beforenumf),beforenum,str(j),beforenum) + try: + db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \ + VALUES (%s,%s,%s,%s)\ + ON DUPLICATE KEY UPDATE \ + ratio_all=CONVERT((ratio_all*%s+%s)/%s,DECIMAL(32,14))",retl) + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "change_multi_ratio_all_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + def change_ratio_rec_reduce_in_auto_bayes_key(self,chtxt,beforenum,newnum): + beforenum=str(beforenum) + newnum=str(newnum) + db = self.connect_db() + db[1].execute("\ + UPDATE in_auto_bayes_key SET ratio_rec=CONVERT(ratio_rec*%s/(%s+%s),DECIMAL(32,14)) WHERE chtxt=%s AND NOT (keychar=\"NUM\")",(beforenum,newnum,beforenum,chtxt)\ + ) + self.close_db(db) + def change_ratio_rec_in_auto_bayes_key(self,key,chtxt,beforenum,addnum): + db = self.connect_db() + beforenumf=beforenum + beforenum=str(beforenum) + db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \ + VALUES (%s,%s,%s,%s)\ + ON DUPLICATE KEY UPDATE \ + ratio_rec=CONVERT((ratio_rec*%s+%s)/%s,DECIMAL(32,14))",(key,chtxt,str(Decimal(addnum)/beforenumf),"0",beforenum,chtxt,key)) + self.close_db(db) + def change_multi_ratio_rec_in_auto_bayes_key(self,chtxt,beforenum,list):#self,key,chtxt,beforenum,addnum): + beforenumf=beforenum + beforenum=str(beforenum) + db = self.connect_db() + for i,j in list.items(): + retl=(i,chtxt,str(Decimal(j)/beforenumf),"0",beforenum,str(j),beforenum) + try: + db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \ + VALUES (%s,%s,%s,%s)\ + ON DUPLICATE KEY UPDATE \ + ratio_rec=CONVERT((ratio_rec*%s+%s)/%s,DECIMAL(32,14))",retl) + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "change_multi_ratio_rec_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + self.close_db(db) + def select_by_key_in_auto_bayes_key(self,key,chtxt): + db = self.connect_db() + dbexe = db[1].execute("\ + SELECT keychar,chtxt,ratio_rec,ratio_all \ + FROM in_auto_bayes_key \ + WHERE keychar = %s AND chtxt = %s", \ + (key,chtxt)) + dls = [] + if dbexe > 0: + dls = db[1].fetchall() + self.close_db(db) + if len(dls)>0: + return dls[0] + else: + return dls + def new_auto_timeline_keyword(self): + db = self.connect_db() + try: + db[1].execute('\ + CREATE TABLE auto_timeline_keyword \ + (\ + id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\ + chtxt VARCHAR(40),\ + title VARCHAR(100),\ + btime DATETIME,\ + etime DATETIME,\ + UNIQUE uni (chtxt,title,btime,etime)\ + )') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_auto_timeline_keyword (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + def add_auto_timeline_keyword(self,chtxt="", title="", btime="", etime=""): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into auto_timeline_keyword \ + (chtxt,title,btime,etime) \ + values (%s,%s,%s,%s)', \ + (chtxt, title, btime, etime)) + ##db.commit() + self.close_db(db) + def delete_old_auto_timeline_keyword(self, dhour): + db = self.connect_db() + db[1].execute("\ + DELETE FROM auto_timeline_keyword \ + WHERE \ + btime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR )") + self.close_db(db) + def new_auto_timeline_bayes(self): + db = self.connect_db() + try: + db[1].execute('\ + CREATE TABLE auto_timeline_bayes \ + (\ + id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\ + chtxt VARCHAR(40),\ + title VARCHAR(100),\ + btime DATETIME,\ + etime DATETIME,\ + point INT,\ + UNIQUE uni (chtxt,title,btime,etime)\ + )') + except Exception, inst: + if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)): + recdblist.addCommonlogEX("Error", "new_auto_timeline_bayes (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + def add_auto_timeline_bayes(self,chtxt="", title="", btime="", etime="",point=""): + db = self.connect_db() + db[1].execute('\ + INSERT IGNORE into auto_timeline_bayes \ + (chtxt,title,btime,etime,point) \ + values (%s,%s,%s,%s,%s)', \ + (chtxt, title, btime, etime,point)) + self.close_db(db) + def delete_old_auto_timeline_bayes(self, dhour): + db = self.connect_db() + db[1].execute("\ + DELETE FROM auto_timeline_bayes \ + WHERE \ + btime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR )") + self.close_db(db) + def update_db_to93(self): + db = self.connect_db() + self.drop_in_settings() + self.new_in_settings() + db[1].execute("\ + ALTER TABLE timeline ADD epgtitle VARCHAR(100),\ + ADD epgbtime DATETIME,\ + ADD epgetime DATETIME,\ + ADD epgduplicate TINYINT DEFAULT 0,\ + ADD epgchange TINYINT DEFAULT 0") + db[1].execute("\ + ALTER TABLE in_status ADD version TINYINT") + self.close_db(db) + self.change_version_in_status("93") + def update_db_93to94(self): + db = self.connect_db() + self.drop_in_settings() + self.new_in_settings() + db[1].execute("\ + ALTER TABLE timeline ADD counter TINYINT DEFAULT -1") + self.close_db(db) + self.change_version_in_status("94") + def update_db_94to95(self): + db = self.connect_db() + self.drop_in_settings() + self.new_in_settings() + db[1].execute("\ + ALTER TABLE timeline ADD epgexp VARCHAR(200)") + self.close_db(db) + self.change_version_in_status("95") + def update_db_95to96(self): + db = self.connect_db() + self.drop_in_settings() + self.new_in_settings() + self.close_db(db) + self.change_version_in_status("96") + def update_db_96to98(self): + db = self.connect_db() + self.drop_in_settings() + self.new_in_settings() + self.close_db(db) + self.change_version_in_status("98") + def update_db_98to100(self): + ###ここで前のepg_chをバックアップしてchtxtの変換をする必要がある。 + self.drop_in_settings() + self.new_in_settings() + db = self.connect_db() + db[1].execute("\ + UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT(CONCAT(epg_ch.ch,'_'),epg_ch.csch) WHERE NOT (substring(epg_ch.bctype,1,2) = 'bs' OR substring(epg_ch.bctype,1,2) = 'cs')") + db[1].execute("\ + UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT('BS_',epg_ch.ch) WHERE substring(epg_ch.bctype,1,2) = 'bs'") + db[1].execute("\ + UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT('CS_',epg_ch.csch) WHERE substring(epg_ch.bctype,1,2) = 'cs'") + try: + db[1].execute("\ + ALTER TABLE epg_ch DROP ontv") + except: + "" + db[1].execute("\ + ALTER TABLE epg_ch ADD logo0 BLOB,\ + ADD logo1 BLOB,\ + ADD logo2 BLOB,\ + ADD logo3 BLOB,\ + ADD logo4 BLOB,\ + ADD logo5 BLOB\ + ") + db[1].execute("\ + ALTER TABLE in_auto_jbk_key ADD auto TINYINT DEFAULT 0") + db[1].execute("\ + ALTER TABLE in_auto_jbk_key ADD opt VARCHAR(20) DEFAULT \"\"") + self.close_db(db) + self.change_installed_in_status(1)#チャンネルスキャンをさせる + self.change_version_in_status("100") + def update_db_100to101(self): + self.drop_in_settings() + self.new_in_settings() + self.new_epg_ch() + db = self.connect_db() + try: + db[1].execute("\ + ALTER TABLE timeline ADD epgcategory VARCHAR(100)\ + ") + except: + "" + self.close_db(db) + self.change_installed_in_status(1) + self.change_version_in_status("101") + #self.change_installed_in_status()#チャンネルスキャンをさせる + def update_db_101to102(sekf): + self.drop_in_settings() + self.new_in_settings() + self.new_epg_ch() + db = self.connect_db() + try: + db[1].execute("\ + ALTER TABLE epg_ch ADD tsid VARCHAR(20)\ + ") + except: + "" + self.close_db(db) + self.change_installed_in_status(1) + self.change_version_in_status("102") + #self.change_installed_in_status()#チャンネルスキャンをさせる + diff --git a/rec10/epgdb.py b/rec10/epgdb.py new file mode 100644 index 0000000..727209d --- /dev/null +++ b/rec10/epgdb.py @@ -0,0 +1,277 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import datetime +import os +import shutil +import time +import os.path +import traceback + +import chdb +import n_gram +import rec10d +import ts2epg +import xml2db_dom +import configreader +import recdblist +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +if not os.path.exists(tmppath): + os.mkdir(tmppath) +def update(chtxt): + recdblist.printutf8(chtxt) + tnow = datetime.datetime.now() + try: + lastup = datetime.datetime.strptime(chdb.searchCHFromChtxt(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S") + except: + lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S") + dt = tnow-lastup + dt = dt.days * 24 * 60 + dt.seconds + if dt > 2 * 60 * 60: + ts2epg.writeEpgXML(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['ch']) + xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['bctype']) +def updatebc(bctype): + bctypel = chdb.searchCHFromBctype(bctype) + #print bctype + try: + ts2epg.writeEpgXML(tmppath + bctype + "epgdata.xml", chdb.searchCHFromBctype(bctype)['ch']) + xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype) + shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml") + time.sleep(5) + rec10d.rec10db.update_by_bctype_epg_ch(bctype) + except Exception, inst: + recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200) + xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype) + rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2") +def updateLogo_bc(bctype): + bctypel = chdb.searchCHFromBctype(bctype) + #print bctype + try: + ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch']) + xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype) + shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml") + time.sleep(5) + rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1") + except Exception, inst: + recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200) + xml2db_dom.xml2db_dom(tmppath + bctype + "logo.bak.xml", bctype) + rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"2") +def searchTime(titletxt, timet, deltatime, chtxt): + time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") + ret = [] + deltatime = int(deltatime) + beforetime = time.strftime("%Y%m%d%H%M%S") + beforetime = time - datetime.timedelta(hours=deltatime) + aftertime = time + datetime.timedelta(hours=deltatime) + beforetime = beforetime.strftime("%Y%m%d%H%M%S") + aftertime = aftertime.strftime("%Y%m%d%H%M%S") + one = ["", "", "", "","","",""] + tempt = 0 + chtxtt=chtxt.replace("_0","_%") + d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt) + for chtxtt, title, start, stop ,exp,longexp,category in d: + #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop) + p = n_gram.bigram(titletxt, title) + btime = start + btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00" + etime = stop + etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + dt = bt-time + dt = abs(dt) + dt = 24 * 60 * 60 * dt.days + dt.seconds + 1 + p = p * 90 + dt = 1000-1000 * dt / (7 * 24 * 60 * 60) + if p > 0: + p = p + dt + if p > tempt: + one = [chtxtt, title, btime, etime,exp,longexp,category] + tempt = p + if p > 0: + #recdblist.printutf8(title + ":" + str(p) + u"点") + "" + ret = one + #print ret + return ret +def searchTimeAuto(keytxt, timet, deltatime): + time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") + ret = [] + deltatime = int(deltatime) + beforetime = time.strftime("%Y%m%d%H%M%S") + aftertime = time + datetime.timedelta(hours=deltatime) + aftertime = aftertime.strftime("%Y%m%d%H%M%S") + d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime) + for chtxtt, title, start, stop ,exp,longexp,category in d: + btime = start + btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00" + etime = stop + etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" + ret.append([chtxtt, title, btime, etime,exp,longexp,category]) + return ret +def countSchedule(btime,etime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime) + times = [] + btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + retcount = [0, 0] + for i in xrange(0, len(times)-2, 1): + bt1 = times[i] + et1 = times[i + 1] + btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + etime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1) + if retcount[0] < ret1[0]: + retcount[0] = ret1[0] + if retcount[1] < ret1[1]: + retcount[1] = ret1[1] + return retcount + +def searchSchedule(btime,etime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime) + times = [] + btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + ret=[] + for i in xrange(0, len(times)-2, 1): + bt1 = times[i] + et1 = times[i + 1] + btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + etime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1) + ret.append(ret1) + ret = list(set(ret)) + return ret + +def countEpgSchedule(epgbtime,epgetime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime) + #print dls + times = [] + btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + retcount = [0, 0] + for i in xrange(0, len(times)-1, 1): + bt1 = times[i] + et1 = times[i + 1] + epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1) + if retcount[0] < ret1[0]: + retcount[0] = ret1[0] + if retcount[1] < ret1[1]: + retcount[1] = ret1[1] + return retcount +def searchEpgSchedule(epgbtime,epgetime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime) + times = [] + btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + ret=[] + for i in xrange(0, len(times)-2, 1): + bt1 = times[i] + et1 = times[i + 1] + epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1) + ret.append(ret1) + ret = list(set(ret)) + return ret diff --git a/rec10/epgrefresh.py b/rec10/epgrefresh.py new file mode 100755 index 0000000..523bdfc --- /dev/null +++ b/rec10/epgrefresh.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import sys +import time + +import chdb +import epgdb +import recdblist + +update = chdb.update() +if len(update) > 0: + #recdblist.printutf8(u"番組表を更新") + #print update + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + for bctype in update: + time.sleep(1) + epgdb.updatebc(bctype) + sys.exit(0) \ No newline at end of file diff --git a/rec10/guess.py b/rec10/guess.py new file mode 100644 index 0000000..cad73e1 --- /dev/null +++ b/rec10/guess.py @@ -0,0 +1,240 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import os +import os.path +import re +import time +import os +import datetime +import n_gram +import recdblist +import zenhan +import auto_move + +def detSeriesNum(execpath): + files=os.listdir(execpath) + ss={} + for file in files: + ftitle=os.path.splitext(file) + fname=ftitle[0] + fname=zenhan.toHankaku(unicode(fname,"utf-8")) + nt=detNameType(fname, execpath) + st=nt['title'] + if not ss.has_key(st): + ss[st]={} + ss[st][nt['num']]=ftitle + print ss + return ss +def detDeltaNum(title,movepath): + """ + #番組の話数を推測する。 + """ + files=os.listdir(movepath) + ff=[] + maxnum=0 + for file in files: + recdblist.printutf8(unicode(file,'utf-8'),verbose_level=800) + file=os.path.join(movepath,file) + if os.path.isfile(file): + name=os.path.splitext(os.path.split(file)[1]) + name=name[0] + name=zenhan.toHankaku(unicode(name,'utf-8')) + p1=detNameType(name,movepath) + #recdblist.printutf8(p1['title']+" "+str(p1['num'])) + time1=time.localtime(os.path.getmtime(file)) + time1=datetime.datetime.fromtimestamp(os.path.getmtime(file)) + if p1['num']!=-1: + ff.append([p1['num'],p1['title'],time1]) + if maxnumd: + dn=dn+d + if dm%d*2>d: + dm=dm+d + if dp%d*2>d: + dp=dp+d + #recdblist.printutf8(str(d)+":"+str(dn)) + if dp!=dn: + ret.append([dn/d,60]) + ret.append([dp/d,40]) + elif dm!=dn: + ret.append([dn/d,60]) + ret.append([dm/d,40]) + else: + ret.append([dn/d,100]) + return ret +def detNameType(title,path): + """ + type A ---title# + type B ---title#subtitle + type C ---title subtitle + type D ---title(without number) + type Aj ---title第話 + path --search reflexively + """ + new=0 + if re.search(u"[新]",title) or re.search(u" 新",title): + title=title.replace(u"[新]","") + title=title.replace(u" 新","") + new=1 + recdblist.printutf8(title,verbose_level=800) + title=auto_move.getTitle(title)##titleから日時を除く + title=title.replace(u"無料≫","") + #rA=re.compile(".+(?P)#\d(?P<num>)\s[0,10]\z") + rA=re.compile("(.+)#(\d*)\s*\Z") + tA=rA.match(title) + rB=re.compile("(.+)#(\d*)\s*(\D*)") + tB=rB.match(title) + rAj=re.compile("(.+)第(\d*)話\s*\Z") + tAj=rAj.match(title) + ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""} + if tA: + #recdblist.printutf8("typeA") + #recdblist.printutf8("title="+tA.group(1)) + #recdblist.printutf8("num="+tA.group(2)) + ret['type']="A" + ret['title']=tA.group(1).replace(" ","") + ret['num']=int(tA.group(2)) + ret['folder']=searchFolder(tA.group(1),unicode(path,'utf-8')) + if tAj: + #recdblist.printutf8("typeA") + #recdblist.printutf8("title="+tAj.group(1)) + #recdblist.printutf8("num="+tAj.group(2)) + ret['type']="Aj" + ret['title']=tAj.group(1).replace(" ","") + ret['num']=int(tAj.group(2)) + ret['folder']=searchFolder(tAj.group(1),unicode(path,'utf-8')) + elif tB: + #recdblist.printutf8("typeB") + #recdblist.printutf8("title="+tB.group(1)) + #recdblist.printutf8("num="+tB.group(2)) + #recdblist.printutf8("subtitle="+tB.group(3)) + ret['type']="B" + ret['title']=tB.group(1).replace(" ","") + ret['num']=int(tB.group(2)) + ret['folder']=searchFolder(tB.group(1),unicode(path,'utf-8')) + ret['subtitle']=tB.group(3) + else:#type C or type D + #fold=searchFolder(title, path) + ts=title.split(" ") + tt="" + rt=["",0,""] + for t in ts: + tt=tt+" "+t + ft1=searchFolder(tt,unicode(path,'utf-8')) + #recdblist.printutf8(tt) + #print ft1 + if ft1!="": + #recdblist.printutf8(rt) + #recdblist.printutf8(ft1[0]+" : "+str(ft1[1])) + if ft1[1]>rt[1]: + rt[0]=tt + rt[1]=ft1[1] + rt[2]=ft1[0] + #recdblist.printutf8(rt) + #recdblist.printutf8("title="+rt[0][1:]+"/") + #recdblist.printutf8("subtitle = "+title.replace(rt[0][1:],"")[1:]) + ret['title']=rt[0][1:].replace(" ","") + ret['num']=-1 + ret['folder']=rt[2] + ret['subtitle']=title.replace(rt[0][1:],"")[1:] + if ret['subtitle'].replace(" ","")=="": + ret['type']="D" + else: + ret['type']="C" + if new==1: + ret['num']=1 + return ret +def searchFolder(title,path,threshold=500): + """ + titleからフォルダーを探す + """ + folderpath=os.listdir(path) + lfpath=[] + ngram=[] + for ft in folderpath: + fullpath=os.path.join(path, ft) + if os.path.isdir(fullpath): + lfpath.append(fullpath) + ftt=os.listdir(fullpath) + if len(ftt)>0: + for ft2 in ftt: + folderpath.append(os.path.join(fullpath, ft2)) + else: + lfpath.append(fullpath) + for dirp in lfpath: + cmpp="" + appp="" + if os.path.isdir(dirp): + cmpp=os.path.dirname(dirp) + appp=dirp + else: + cmpp=os.path.basename(dirp) + appp=os.path.dirname(dirp) + ntitle=auto_move.getTitle(title) + ncmpp=auto_move.getTitle(cmpp) + p=n_gram.trigram(ntitle,ncmpp) + if p>0: + ngram.append((p,appp)) + ngram=list(set(ngram)) + ngram.sort() + ngram.reverse() + if len(ngram)>0: + #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0])) + if ngram[0][0]>threshold: + return ngram[0][1] + else: + return "" + else: + return "" \ No newline at end of file diff --git a/rec10/install.py b/rec10/install.py new file mode 100644 index 0000000..d1f6da9 --- /dev/null +++ b/rec10/install.py @@ -0,0 +1,308 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import time +import os.path +import ConfigParser +import sys +import commands +import configwriter +import shutil +import traceback + +import recdblist +def printutf8(str): + print str.encode('utf-8') +def install(): + version = recdblist.version + recdblist.printutf8(u"rec10の環境インストールを開始します。",verbose_level=100) + time.sleep(1) + recdblist.printutf8(u"環境インストール処理中・・・",verbose_level=100) + path = str(os.path.dirname(os.path.abspath(__file__))) + confp = ConfigParser.SafeConfigParser() + Conf = 'rec10.conf' + confpath="" + if os.path.exists(os.path.join(path,Conf)): + confpath=os.path.join(path,Conf) + elif os.path.exists(os.path.join("/etc","rec10.conf")): + confpath=os.path.join("/etc","rec10.conf") + elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")): + confpath=os.path.join("/etc/rec10","rec10.conf") + if confpath!="": + confp.read(confpath) + else: + recdblist.printutf8(u"rec10.confが見つかりません。",verbose_level=100) + recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。",verbose_level=100) + sys.exit(1) + recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath,verbose_level=100) + if confp.get('path',"recpath")=="/path of /recording": + recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)",verbose_level=100) + sys.exit(1) + recdblist.printutf8(u"DB処理に入ります",verbose_level=100) + if os.path.exists(os.path.join(path,"rec10d.py")): + try: + update_db_all() + except Exception, inst: + recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。",verbose_level=100) + recdblist.printutf8(str(type(inst)),verbose_level=100) + recdblist.printutf8(str(inst)+"\n"+traceback.format_exc(),verbose_level=100) + import rec10d + rec10d.rec10db.change_installed_in_status() + recdblist.printutf8(u"チャンネル設定に入ります",verbose_level=100) + import scan_ch + rec10d.rec10db.new_epg_ch() + recdblist.printutf8(u"チャンネルスキャンの開始",verbose_level=100) + scan_ch.searchCh() + rec10d.rec10db.change_installed_in_status(100) + recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100) + recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100) + sys.exit(1) +def getLocalPath(cmd,exit=1): + printutf8(cmd+u"の場所を確認中") + txt=commands.getoutput(u"which "+cmd) + if len(txt.split(" "))>3: + if exit==1: + printutf8(cmd+u"の場所を確認できませんでした。終了します") + sys.exit(1) + else: + return "" + else: + printutf8(cmd+u" : "+txt) + if len(txt.splitlines()): + txt=txt.splitlines()[0] + return txt.strip() +def move(): + useB=0 + path = str(os.path.dirname(os.path.abspath(__file__))) + printutf8(u"rec10 ver "+recdblist.version_str+" installer.") + printutf8(u"rec10のインストールを開始します。") + maxn=16 + configwriter.setTempConfPath(u"wine", getLocalPath(u"wine")) + configwriter.setTempConfPath(u"recpt1", getLocalPath(u"recpt1",exit=0)) + #configwriter.setpath(u"x264", getLocalPath(u"x264")) + configwriter.setTempConfPath(u"mp4box", getLocalPath(u"MP4Box",exit=0)) + configwriter.setTempConfPath(u"mencoder", getLocalPath(u"mencoder")) + configwriter.setTempConfPath(u"ffmpeg", getLocalPath(u"ffmpeg")) + configwriter.setTempConfPath(u"mkvmerge", getLocalPath(u"mkvmerge",exit=0)) + configwriter.setTempConfPath(u"lame", getLocalPath(u"lame",exit=0)) + configwriter.setTempConfPath(u"b25", getLocalPath(u"b25")) + configwriter.setTempConfPath(u"tee", getLocalPath(u"tee")) + configwriter.setTempConfPath(u"java", getLocalPath(u"java")) + + try: + configwriter.setTempConfPath(u"lame", getLocalPath(u"lame")) + except: + printutf8(u"lameが見つかりません(NeroAacEncを導入する場合は問題ありません)") + printutf8(u"必須環境の設定が完了しました") + printutf8(u"個人設定に入ります") + if os.path.exists("/etc/rec10.conf"): + printutf8(u"以前の設定ファイルが見つかりました。") + printutf8(u"インポートしますか?") + useB=raw_input("[Y/n]:") + if useB=="N" or useB == "n": + useB=0 + else: + useB=1 + printutf8(u"設定ファイルのインポートを行います。") + printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/"+str(maxn)+")") + printutf8(u"100GB程度は確保されている必要があります") + recpath=getConf(useB,"/etc/rec10.conf","path","recpath","path : ") + configwriter.setTempConfPath(u"recpath",recpath) + printutf8(u"DBの設定に入ります。") + printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/"+str(maxn)+")") + mysql_user=getConf(useB,"/etc/rec10.conf","db","mysql_user","mysql_user : ") + configwriter.setTempConfDB("mysql_user", mysql_user) + printutf8(u"パスワードを設定してください(3/"+str(maxn)+")") + mysql_passwd=getConf(useB,"/etc/rec10.conf","db","mysql_passwd","mysql_passwd : ") + configwriter.setTempConfDB("mysql_passwd", mysql_passwd) + printutf8(u"BS/CSの設定に入ります") + printutf8(u"BS/CS(110度CS,スカパーe2)を受信しますか(4/"+str(maxn)+")") + useBSCS=raw_input("[Y/n]:") + if useBSCS=="N" or useBSCS=="n" or useBSCS=="no" or useBSCS=="NO": + useBSCS="0" + else: + useBSCS="1" + printutf8(u"ドライバの設定に入ります") + printutf8(u"DVB版のドライバを使用しますか(earth_pt1など。chardev版を使う場合はNo)(5/"+str(maxn)+")") + useDVB=raw_input("[y/N]:") + if useDVB=="Y" or useDVB=="y" or useDVB=="yes" or useDVB=="YES": + useDVB="1" + else: + useDVB="0" + configwriter.setTempConfDVB("useDVB", useDVB) + if useDVB=="1": + printutf8(u"DVBの設定に入ります") + printutf8(u"DVBAdapterの場所を設定して下さい") + printutf8(u"/dev/dvb/adapterなどdvr0の上のフォルダ(番号の前まで)を指定して下さい。") + getConf(useB,"/etc/rec10.conf","dvb","DVBadapter","/dev/dvb/adapter") + printutf8(u"地デジを受信可能なアダプタ番号を入力して下さい(1,3のように','で区切って下さい)") + getConf(useB,"/etc/rec10.conf","dvb","DVBTE","1,3") + if useBSCS=="1": + printutf8(u"BS/CSを受信可能なアダプタ番号を入力して下さい(0,2のように','で区切って下さい)") + getConf(useB,"/etc/rec10.conf","dvb","DVBBSCS","0,2") + else: + configwriter.setTempConfDVB("DVBBSCS","") + printutf8(u"同時録画可能数の設定に入ります") + printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(6/"+str(maxn)+")") + te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : "))) + configwriter.setTempConfEnv("te_max", te_max) + if useBSCS=="1": + printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(7/"+str(maxn)+")") + bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : "))) + configwriter.setTempConfEnv("bscs_max", bscs_max) + else: + configwriter.setTempConfEnv("bscs_max", "0") + printutf8(u"同時エンコード最大数を設定してください(8/"+str(maxn)+")") + printutf8(u"CPUのコア数が目安です") + enc_max=raw_input("[2]:") + if enc_max=="": + enc_max="2" + else: + enc_max=str(int(enc_max)) + configwriter.setTempConfEnv("enc_max", enc_max) + printutf8(u"二カ国語放送/5.1ch放送の音声変換の設定です。\nNeroAACエンコーダーを使用しますか?(NeroAACEncを別途入手してtstoolsに入れてください。))") + printutf8(u"入手先:http://www.nero.com/jpn/technologies-aac-codec.html\n (9/"+str(maxn)+")") + audioenc=raw_input("[y/N]: ") + if audioenc=="y" or audioenc=="Y": + configwriter.setTempConfPath("useNeroAAC", "1") + aacpath=getLocalPath(u"neroAacEnc",exit=0) + if len(aacpath)<2: + printutf8(u"NeroAACEncのパスを指定してください") + aacpath=getConf(useB,"/etc/rec10.conf","path","NeroAAC","[/usr/local/bin/neroAacEnc] : ") + if aacpath.replace(" ","")=="": + aacpath="/usr/local/bin/neroAacEnc" + configwriter.setTempConfPath("NeroAAC",aacpath) + else: + configwriter.setTempConfPath("useNeroAAC", "0") + aacpath="/usr/local/bin/neroAacEnc" + configwriter.setTempConfPath("NeroAAC",aacpath) + printutf8(u"lameを使用します。") + printutf8(u"x264のパスを指定してください(10/"+str(maxn)+")") + x264path=getConf(useB,"/etc/rec10.conf","path","x264","x264 path : ") + if x264path.replace(" ","")=="" or not os.path.isfile(x264path): + x264path=getLocalPath(u"x264") + configwriter.setTempConfPath("x264",x264path) + printutf8(u"保存する画質を教えてください(11/"+str(maxn)+")") + printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります") + crf=getConf(useB,"/etc/rec10.conf","env","crf","[24] : ") + if crf.replace(" ","")=="": + crf="24" + configwriter.setTempConfEnv("crf", crf) + printutf8(u"アニメーションを保存する画質を教えてください(12/"+str(maxn)+")") + printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります") + a_crf=getConf(useB,"/etc/rec10.conf","env","animation_crf","[20] : ") + if a_crf.replace(" ","")=="": + a_crf="20" + configwriter.setTempConfEnv("animation_crf", a_crf) + printutf8(u"x264の圧縮率を設定してください(13/"+str(maxn)+")") + printutf8(u"x264のpresetの値です。標準だとmedium、小さければ小さいほど高圧縮になります") + preset=getConf(useB,"/etc/rec10.conf","env","x264_preset","[4] : ") + if preset.replace(" ","")=="": + preset="4" + configwriter.setTempConfEnv("x264_preset", preset) + printutf8(u"保存するコンテナの設定(14/"+str(maxn)+")") + printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)") + useMP4=raw_input("[Y/n]:") + if useMP4=="N" or useMP4 == "n" : + useMP4="0" + else: + useMP4="1" + configwriter.setTempConfEnv("make_mp4", useMP4) + printutf8(u"TSファイルの自動削除(15/"+str(maxn)+")") + printutf8(u"中間体のtsファイルを削除しますか") + printutf8(u"(削除するとやり直しができないため残しておくことを推奨します。)") + removeTS=raw_input("[y/N]:") + if removeTS=="Y" or removeTS == "y" : + removeTS="1" + else: + removeTS="0" + configwriter.setTempConfEnv("remove_ts", removeTS) + printutf8(u"自機識別オプション(16/"+str(maxn)+")") + printutf8(u"本rec10の識別名を入力してください") + printutf8(u"複数台のrec10を運用する場合に効果的です。空白でもかまいません。") + printutf8(u"例 kobe01") + iff=getConf(useB,"/etc/rec10.conf","env","iff","[] : ") + configwriter.setTempConfEnv("iff", iff) + confp = ConfigParser.SafeConfigParser() + confp.read("/etc/rec10.conf") + if useB: + configwriter.setTempConfPath("recorded",confp.get("path","recorded")) + configwriter.setTempConfPath("move_destpath",confp.get("path","move_destpath")) + configwriter.setTempConfPath("tmp",confp.get("path","tmp")) + try: + configwriter.setTempConfEnv("x264_addline",confp.get("env","x264_addline")) + except: + configwriter.setTempConfEnv("x264_addline","") + if confp.get("path","b25_remote")=="": + configwriter.setTempConfPath("b25_remote", "0") + elif confp.get("path","b25_remote")=="1": + configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote")) + configwriter.setTempConfPath("b25", confp.get("path","b25")) + configwriter.setTempConfPath("b25_env", confp.get("path","b25_env")) + else: + configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote")) + + configwriter.writeTempConf() + printutf8(u"初期設定が終了しました。") + printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。") +def getConf(useBeforeConf,Confpath,dbsection,key,defaultstr): + tstr=defaultstr + if os.path.exists(Confpath) and useBeforeConf==1: + try: + confp = ConfigParser.SafeConfigParser() + confp.read("/etc/rec10.conf") + tstr=u"["+confp.get(dbsection,key)+u"]:" + except: + tstr=defaultstr + tmpconf=raw_input(tstr) + if tmpconf.replace(" ","")=="" and os.path.exists(Confpath) and useBeforeConf==1 : + confp = ConfigParser.SafeConfigParser() + confp.read("/etc/rec10.conf") + try: + tmpconf=confp.get(dbsection,key) + except: + tmpconf="" + return tmpconf +def update_db_all(): + import rec10d + tversion=0 + if rec10d.rec10db.select_installed_in_status()==1: + if rec10d.rec10db.select_version_in_status()==0: + tversion=0 + recdblist.printutf8(u"既存のDBが見つかりました。0.9.1と仮定してアップデート処理を行います。",verbose_level=100) + update_db(0) + time.sleep(1) + else: + recdblist.printutf8(u"既存のDBが見つかりました。アップデート処理を行います。",verbose_level=100) + tversion=int(rec10d.rec10db.select_version_in_status()) + while (recdblist.version>tversion): + update_db(tversion) + tversion=int(rec10d.rec10db.select_version_in_status()) + else: + rec10d.rec10db.drop_in_status() + rec10d.rec10db.drop_in_settings() + time.sleep(2) + rec10d.rec10db.new_in_status() + rec10d.rec10db.new_in_settings() + rec10d.rec10db.change_version_in_status(recdblist.version) +def update_db(version): + import rec10d + if version==0: + rec10d.rec10db.update_db_to93() + elif version==93: + rec10d.rec10db.update_db_93to94() + elif version==94: + rec10d.rec10db.update_db_94to95() + elif version==95: + rec10d.rec10db.update_db_95to96() + elif version==96: + rec10d.rec10db.update_db_96to98() + elif version==98: + rec10d.re/Users/matsuohidetoshi/Desktop/git/rec10-git/rec10/install.shc10db.update_db_98to100() + elif version==100: + rec10d.rec10db.update_db_100to101() + elif version==101: + rec10d.rec10db.update_db_100to102() +if __name__ == "__main__": + move() diff --git a/rec10/install.sh b/rec10/install.sh new file mode 100644 index 0000000..1b117d9 --- /dev/null +++ b/rec10/install.sh @@ -0,0 +1,17 @@ +#!/bin/bash +SELF_DIR=`dirname $0` +cd ${SELF_DIR} +if type -P python2.6 > /dev/null +then export LANG="ja_JP.UTF-8" && python2.6 ./install.py +elif type -P python26 > /dev/null +then export LANG="ja_JP.UTF-8" && python26 ./install.py +elif type -P python2.7 > /dev/null +then export LANG="ja_JP.UTF-8" && python2.7 ./install.py +elif type -P python27 > /dev/null +then export LANG="ja_JP.UTF-8" && python27 ./install.py +elif type -P python2.5 > /dev/null +then export LANG="ja_JP.UTF-8" && python2.5 ./install.py +elif type -P python25 > /dev/null +then export LANG="ja_JP.UTF-8" && python25 ./install.py +fi +mv Makefile.base Makefile diff --git a/rec10/license-ja.txt b/rec10/license-ja.txt new file mode 100644 index 0000000..b489776 --- /dev/null +++ b/rec10/license-ja.txt @@ -0,0 +1,462 @@ +GNU 劣等一般公衆利用許諾書 (GNU Lesser General Public License)¶ + +バージョン3、2007å¹´6月29日 +日本語訳、2007å¹´9月5日 + +Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +(訳: 本ライセンス文書を、一字一句忠実に複製、頒布することは許可する。しかし変更は認めない。) + +This is an unofficial translation of the GNU Lesser General Public License into Japanese. It was not published by the Free Software Foundation, and does not legally state the distribution terms for software that uses the GNU LGPL--only the original English text of the GNU LGPL does that. However, we hope that this translation will help Japanese speakers understand the GNU LGPL better. + +(訳: 以下はGNU Lesser General Public Licenseの非公式な日本語訳です。これはフリーソフトウェア財団 (Free Software Foundation)によって正式に発表されたものではなく、GNU LGPLが適用されたソフトウェアの頒布条件を法的に有効な形で述べたものではありません。頒布条件としては、GNU LGPLの英語版テキストで指定されているもののみが有効です。しかしながら、私たちはこの翻訳が、日本語を使用する人々にとってGNU LGPLをより良く理解する助けとなることを望んでいます。) + +翻訳は八田真行 <mhatta@gnu.org>が行った。原文はhttp://www.gnu.org/licenses/lgpl-3.0.html である。誤訳の指摘や訳の改善案を歓迎する。なお、日本語訳の利用条件は原文に準ずる。 + +このバージョンのGNU 劣等一般利用許諾書では、GNU 一般公衆利用許諾書(GNU General Public License)バージョン3が規定する利用条件を取り込んだ上で、以下に列挙する追加的許可で補足するものとする。 +0. 追加された定義¶ + +本文中で使われている通り、「本許諾書」はGNU 劣等一般公衆利用許諾書バージョン3を指す。「GNU GPL」は、GNU 一般公衆利用許諾書バージョン3を指す。 + +『ライブラリ』(The Library)とは、本許諾書の下で管理された『保護された作品』のうち、以下で定義する『アプリケーション』や『結合された作品』以外のものを指す。 + +『アプリケーション』(Application)とは、『ライブラリ』が提供するインターフェースを利用するが、『ライブラリ』を基にはしていない作品すべてのことである。『ライブラリ』によって定義されたクラスの下位クラスを定義するのは、『ライブラリ』が提供するインターフェースの利用の一形態と見なされる。 + +『結合された作品』(Combined Work)とは、『アプリケーション』と『ライブラリ』を結合ないしリンクすることによって作成された作品のことである。また、それによって『結合された作品』が作られた特定のバージョンの『ライブラリ』は、『リンクされたバージョン』(Linked Version)と呼ばれる。 + +『結合された作品』に対する『最小限の対応するソース』 (Minimal Corresponding Source)とは、『結合された作品』に対する(訳注: GPLv3における)『対応するソース』のことを意味する。ただし、『結合された作品』に含まれる部分のうち、それのみを分離して考えた場合、『アプリケーション』を基にしているが、『リンクされたバージョン』は基にしていない部分のソースコードのすべては除外される。 + +『結合された作品』に『対応するアプリケーションコード』 (Corresponding Application Code)とは、『アプリケーション』のオブジェクトコードかソースコードを意味する。『対応するアプリケーションコード』には、『アプリケーション』から『結合された作品』を再生成するために必要なデータやユーティリティ・プログラムすべてが含まれるが、『結合された作品』の『システムライブラリ』は除く。 +1. GNU GPL第3項への例外¶ + +あなたは本許諾書の第3項および第4項に従い、『保護された作品』を伝達することができる。その際、GNU GPL第3項の第2段落に束縛される必要はない。 +2. 改変されたバージョンの伝達¶ + +『ライブラリ』のコピーを改変し、かつあなたの改変点において、ある機能が (その機能が呼び出される際に引数として渡されるものを除いて)その機能を利用する『アプリケーション』から提供される関数やデータを参照する場合、以下のどちらかに従えば、あなたは改変されたバージョンのコピーを伝達することができる: + + * a) 本許諾書に従って伝達する。ただし、『アプリケーション』が関数やデータを提供しない場合でも、その機能が依然として動作し、機能の目的のうち意味あるものとして残った部分はすべて実行するよう誠実な配慮を尽くさなければならない。あるいは、 + * b) GNU GPLに従って伝達する。この場合、本ライセンス文書によってそのコピーに適用可能な追加的許可は一切認められない。 + +3. ライブラリのヘッダファイルに由来するコードや各種データを取り込んだオブジェクトコード¶ + +オブジェクトコード形式の『アプリケーション』は、『ライブラリ』の一部であるヘッダファイルに含まれるコードや各種データを取り込むことができる。あなたは、そのようなオブジェクトコードを、あなたが選択したいかなる条項の下でも複製、伝達して構わない。ただし、取り込まれたコード等が数値的パラメータや、データ構造のレイアウトやアクセサー、小さなマクロ、インライン関数やテンプレート(長さにして10行以下)ではない場合、あなたは以下の両方を行わなければならない。 + + * a) オブジェクトコードのコピーそれぞれにおいて、『ライブラリ』がその中で利用されており、『ライブラリ』とその利用は本許諾書によって保護されている旨を目立つように告知する。 + * b) オブジェクトコードに、GNU GPLと本許諾書のコピーを添付する。 + +4. 結合された作品¶ + +あなたは、『結合された作品』に含まれる『ライブラリ』部分の改変を事実上禁止したり、そのような改変をデバッグするためのリバースエンジニアリングを禁止したりしない限り、『結合された作品』をあなたが選択したいかなる条件の下でも複製、伝達して構わない。ただしその場合、以下をすべて行う必要がある: + + * a) 『ライブラリ』が『結合された作品』中で利用されており、また『ライブラリ』とその利用は本許諾書によって保護されるということを、『結合された作品』のコピーそれぞれにおいて目立つように告知する。 + * b) 『結合された作品』に、GNU GPLと本ライセンス文書のコピーを添付する。 + * c) 実行中に『コピーライト』告知を表示する『結合された作品』の場合、そういった告知文中に 『ライブラリ』の著作権告知と、ユーザに対してGNU GPLと本ライセンス文書のコピーがどこにあるかを示す参照先情報を含める。 + * d) 以下のどれか一つを行う: + o 0) 本許諾書の条項に従い、『最小限の対応するソース』を伝達する。また、『対応するアプリケーションコード』を、『対応するソース』の伝達に関して GNU GPL第6項が指定しているのと同様のやり方で、ユーザが『アプリケーション』を『ライブラリ』の改変されたバージョンと再結合または再リンクして改変された『結合された作品』を作成するのに適した形式、かつそういった再結合や再リンクを許可する条項の下で伝達する。 + o 1) 『ライブラリ』をリンクするのに適した共有ライブラリメカニズムを利用する。適したメカニズムとは、(a)実行時すでにユーザのコンピュータシステムに存在する『ライブラリ』のコピーを利用し、(b) 『リンクされたバージョン』とインターフェースに互換性がある『ライブラリ』の改変されたバージョンと共に適切に機能するものである。 + * e) 『インストール用情報』を提供する。ただしこれはGNU GPL第6項に従いそのような情報を提供することが義務付けられている場合に限られ、またそのような情報が、『リンクされたバージョン』の改変されたバージョンと『アプリケーション』を再結合ないし再リンクすることによって作成された『結合された作品』の改変されたバージョンをインストール、実行するのに必要とされる限りにおいてのみである(あなたが小項4dの0を選択する場合、『インストール用情報』は『最小限の対応するソース』と『対応するアプリケーションコード』と共に供しなければならない。あなたが小項4dの1を選択する場合、あなたは『インストール用情報』をGNU GPL第6項が『対応するソース』の伝達に関して指定するのと同様のやり方で提供しなければならない)。 + +5. 結合されたライブラリ¶ + +あなたは、『ライブラリ』を基にした作品であるライブラリ機能を、『アプリケーション』ではなく、かつ本許諾書で保護されていない他のライブラリ機能と一緒に、単一のライブラリ内で並置し、そのような結合されたライブラリをあなたが選んだ条項に従って伝達することができる。ただしその場合、以下の両方を行わなければならない。 + + * a) 結合されたライブラリに、他のいかなるライブラリ機能とも結合されておらず、本許諾書の条項に従って伝達される、元のままの『ライブラリ』を基にした作品のコピーを添付する。 + * b) その一部が『ライブラリ』を元にした作品である結合されたライブラリに、対応する結合されていない形式の同じ作品がどこで見つかるかを説明した目立つ告知を載せる。 + +6. GNU 劣等一般公衆利用許諾書の改訂されたバージョン¶ + +フリーソフトウェア財団は、改訂された、あるいは新しいバージョンのGNU 劣等一般公衆利用許諾書を折りに触れて発行することができる。そのような新バージョンは、その精神においては現在のバージョンと似たものになるだろうが、細部については新たに生じた問題や懸念を解決すべく異なるものになるだろう。 + +それぞれのバージョンには、見分けがつくようなバージョン番号が振られている。あなたが受領した『ライブラリ』において、ある特定のバージョン番号が振られたGNU 劣等一般公衆利用許諾書「かそれ以降のバージョンのいずれか (or any later version)」が適用されると指定されていた場合、あなたは指定された番号のバージョンか、それ以降にフリーソフトウェア財団によって発行されたバージョンのいずれかのバージョンのどちらの利用条件に従うかを選ぶことができる。あなたが受領した『ライブラリ』が特定のバージョン番号の GNU 劣等一般公衆利用許諾書を指定していなかった場合には、あなたはフリーソフトウェア財団がそれまでに発行したGNU 劣等一般公衆利用許諾書のバージョンの中からどれを選択しても構わない。 + +(訳注: 日本語訳のバージョンは日付で管理している。冒頭を見よ。) + +あなたが受領した『ライブラリ』において、GNU 劣等一般公衆利用許諾書の将来のバージョンのうちどれが適用されうるかは代理人が決定できる、と指定されていた場合、その代理人が、あるバージョンを受諾すると述べた公的な声明は、あなたに対し、その『ライブラリ』に関してそのバージョンのGNU LGPLを選ぶことを永続的かつ正式に許可するのと等しい。 + + + + + + +利用条件 (TERMS AND CONDITIONS)¶ +0. 定義¶ + +「本許諾書」(The License)とは、GNU 一般公衆利用許諾書のバージョン3を指す。 + +「『コピーライト』」(Copyright)とは、いわゆる著作権のみならず、半導体マスクのようなその他の作品に適用される、著作権に類似した法的権利をも意味する。 + +(訳注: この規定により、本許諾書は著作権法で保護されたいわゆる「著作物」よりも広い範囲をカバーすることになる。よってこの訳のライセンス本文中においては、work(s)に「著作物」ではなく「作品」という訳語を宛てることにした。) + +「『プログラム』」(The Program)とは、本許諾書の下でライセンスされた、『コピーライト』が主張可能な作品すべてを意味する。個々のライセンシーは「あなた」として表現される。ライセンシーは個人でも組織でも構わない。 + +ある作品の「改変」(modify)とは、その作品の全体ないし一部を、『コピーライト』の許可を必要とするようなやり方で複製ないし翻案することを意味する。ただし、完全に同一なコピーを作成する場合は除く。改変の結果出来た作品は、以前の作品の「改変されたバージョン」(modified version)、または、以前の作品を「基にした」(based on)作品と呼ばれる。 + +「『保護された作品』」(covered work)とは、改変されていない『プログラム』か、『プログラム』を基にした作品のいずれかを指す。 + +ある作品の「普及」(propagate)とは、コンピュータ上で実行すること、または私的なコピーを改変することを除き、適用可能な『コピーライト』法規の下で許可無く行うと、権利侵害として、直接的、あるいは間接的にあなたが責任を問われる何らかの行為を意味する。普及には、複製、頒布 (改変の有無を問わない)、公衆への利用可能化が含まれ、またいくつかの国々では他の活動も含まれる可能性がある。 + +ある作品の「伝達」(convey)とは、第三者がコピーを作成ないし受領するのを可能とする普及行為すべてを意味する。ただし、コンピュータネットワーク越しにユーザとやりとりするだけで、コピーの転送は伴わない場合は、伝達ではない。 + +対話的なユーザインターフェースが「『適切な法的告知』」(Appropriate Legal Notices)を表示するという場合、そのインターフェースは (1)適切な『コピーライト』告知を表示し、(2)ユーザに対して、その作品には何の保証もない(別途保証が提供されている場合は除く)ということ、ライセンシーはその作品を本許諾書の下で伝達できるということ、そして本許諾書のコピーを見るにはどうしたらよいかということを便利かつ顕著に視認できるような機能を含むものとする。もしインターフェースが、メニューのようなユーザコマンドやオプションの一覧を表示するならば、その一覧中には上記の基準を満たすようなアイテムが目立つように含まれていなければならない。 +1. ソースコード¶ + +ある作品の「ソースコード」(source code)とは、その作品に改変を加えるに当たって好ましいと考えられる形式のことである。「オブジェクトコード」 (object code)とは、作品がとりうるソースコード以外の形式すべてを意味する。 + +「標準インターフェース」(Standard Interface)とは、標準化団体として認知された組織によって定義された公式な標準か、ある特定のプログラミング言語向けに指定されたインターフェースの場合には、その言語を利用する開発者の間で広く使われているインターフェースのことを指す。 + +実行可能な作品の「『システムライブラリ』」(System Libraries)とは、 (a)「主要コンポーネント」(Major Component) の頒布物に通常含まれるが、その主要コンポーネントの一部ではなく、かつ(b)作品をその「主要コンポーネント」といっしょに利用することを可能にする、あるいは公衆にとってソースコード形式で利用可能な実装がひとつは存在する標準インターフェースを提供するためにのみ機能するものすべてを意味する。ただし、全体としての作品そのものは除く。ここでいう「主要コンポーネント」とは、実行可能な作品がその上で実行されるある特定のオペレーティングシステム (そういったものが必要ならば)の主要で不可欠な一部分(カーネルやウィンドウシステムなど)、あるいはその作品を作成するのに使われるコンパイラ、実行するのに使われるオブジェクトコードインタプリタなどを意味する。 + +オブジェクトコード形式の作品に「『対応するソース』」(Corresponding Source)とは、その作品を生成、インストール、(実行可能な作品に関しては)オブジェクトコードを実行、または作品を改変する上で必要とされるソースコードのすべてを意味する。この場合、そうした活動をコントロールするためのスクリプトは『対応するソース』に含まれるが、その作品にとっての『システムライブラリ』や、先ほど列挙した活動を行う上で改変されることなく利用されるものの作品の一部ではない、汎用のツールや一般的に利用可能なフリープログラムは除外される。例えば『対応するソース』には、その作品のソースファイルと連携するインターフェース定義ファイルに加え、共有ライブラリや動的にリンクされた下位プログラムと作品のその他の部分との間での親密なデータのやりとりやコントロールフローなどのために、その作品が設計上明確に必要とする、そうした共有ライブラリや下位プログラムのソースコードなどが含まれる。 + +『対応するソース』には、ユーザが『対応するソース』の他の部分から自動的に再生成できるものを含む必要はない。 + +ソースコード形式の作品にとっての『対応するソース』とは、その作品そのものである。 +2. 基本的な許可¶ + +本許諾書の下で認められるすべての権利は、『プログラム』に主張される『コピーライト』の条項に基づき授与されるものであり、ここで述べられた条件が満たされている限り覆すことはできない。本許諾書は、改変されていない『プログラム』をあなたが無制限に実行することを許可し、明示的に確約する。『保護された作品』を実行することから得られた出力結果は、その出力内容が『保護された作品』を構成する場合のみ本許諾書で保護される。本許諾書は、あなたが有するフェアユースまたはその同等物の権利を、『コピーライト』法規によって提供される通りに承認する。 + +その他の状況においてあなたのライセンスが有効である限り、『保護された作品』の、伝達を伴わない作成、実行、および普及は無条件に行うことができる。他者にあなた専用の改変を行わせる、あるいは他者にあなたがそういった作品を実行するための機能を提供させるということが唯一の目的であれば、『保護された作品』を他者に伝達することができる。ただしその場合、あなたが『コピーライト』を支配していない部分すべての伝達に関しては、本許諾書の条項に従わなければならない。従って、あなたのために『保護された作品』を作成または実行する者は、専らあなたのためだけに、あなたの監督と支配の下で、あなたとの関係の範囲外ではあなたが『コピーライト』を有する一部分のいかなるコピーをも作成することを禁止するという条件の下で行わなければならないということになる。 + +上記以外のあらゆる状況下においては、伝達は以下で述べる条件の下でのみ許可される。再許諾は認められない。下記第10項により、再許諾は必要ないからである。 +3. ユーザの法的権利を、技術的保護手段の回避を禁ずる法律から守る¶ + +『保護された作品』は、 1996å¹´12月20日に採択されたWIPO著作権条約第11項の下での義務を満たす適用可能な法のいずれか、あるいはそれに類似の法が、回避の禁止または制限の対象として規定する、「効果的な技術的手段」 (effective technological measure)の一部として見なされてはならない。 + +(訳注: WIPO著作権条約については、http://www.cric.or.jp/db/article/wch.html 等を参照せよ。) + +あなたが『保護された作品』を伝達する場合、『保護された作品』に関して本許諾書の下で権利を行使することにより、技術的手段の回避に影響が出る範囲において、そのような手段の回避を禁じるいかなる法的権力をも放棄することになる。また、あなたはその作品のユーザに対して、技術的手段の回避を禁じるためにあなたや第三者の法的権利を強制するための手段として、その作品の動作や改変を制限するいかなる意図も否認することになる。 +4. 一字一句忠実なコピーの伝達¶ + +あなたは、自分が受領した『プログラム』のソースコードと一字一句同じコピーであれば、いかなる媒体でも伝達することができる。ただしその場合、あなたはそれぞれのコピーにおいて、目立つように、かつ適切な形で、ふさわしい『コピーライト』告知を掲載しなければならない。すなわち、本許諾書と、下記第7項に従い追加された非許可的条項のすべてがそのコードに適用される旨の告知を掲載し、あらゆる保証が存在しない旨の告知をすべてそのまま保全し、かつ『プログラム』の受領者すべてに、『プログラム』といっしょにこの許諾書のコピーを与えなければならない。 + +あなたは、自分が伝達するコピーのそれぞれに関していかなる価格を付けても良いし、無料で伝達しても構わない。また、報酬を取ってサポートや保証保護 (warranty protection)を提供しても良い。 +5. 改変されたバージョンのソースの伝達¶ + +あなたは、『プログラム』を基にした作品、あるいはそうした作品を『プログラム』から作成するための改変点を、上記第4項の規定に従ってソースコード形式で伝達することができる。ただしその場合、あなたは以下に示す条件のすべてを満たさなければならない: + + * a) 作品には、あなたが作品を改変したということと、改変に関連した日時を記述した告知を目立つように載せなければならない。 + * b) 作品には、それが本許諾書と、下記第7項に従って追加された条件すべての下で公開されていることを記述した告知を目立つように載せなければな らない。この条件は、上記第4項における「告知をすべてそのまま保全」するための条項を改変する。 + * c) 作品の全部分を、総体として、コピーを所有するに至った人全員に、本許諾書の下でライセンスしなければならない。そこで、本許諾書は、本許諾書第7項に基づく適用可能な追加的条項のすべてとともに、作品全体に、すなわちその全部分に、それらがどのようにパッケージされているかに関わらず適用されることになる。本許諾書は、これ以外のやり方には作品をライセンスする許可を与えないが、あなたが本許諾書以外で別途許可を得ていた場合には、それによって得られた許可まで無効とするものではない。 + * d) 改変された作品が対話的なユーザインターフェースを有する場合、それらのインターフェースは『適切な法的告知』を表示しなければならない。ただし、『プログラム』に元々『適切な法的告知』を表示しない対話的なインターフェースがある場合、あなたの作品で表示するようにする必要はない。 + +一巻の記憶装置の中か頒布媒体上で、『保護された作品』と、本来『保護された作品』の拡張ではなく、『保護された作品』とより大規模なプログラムを形成するような形で結合されているわけでもないその他の分離かつ独立した作品とをまとめた編集物は、編集作業とそれに由来する『コピーライト』が、個々の作品が許可する範囲を越えて編集物のユーザの作品へのアクセスや法的権利を制限するのに使われない限り、「集積物」(aggregate)と呼ばれる。単に『保護された作品』を集積物に含めるだけでは、その集積物の他の部分にまで本許諾書が適用されるということにはならない。 +6. ソース以外の形式における伝達¶ + +あなたは、オブジェクトコード形式の『保護された著作物』を、上記第4項および第5項の規定に従って伝達することができる。ただしその場合、あなたは機械読み取り可能な『対応するソース』も本許諾書の条件に従って、以下のいずれかの方法で伝達しなければならない。 + + * a) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、『対応するソース』を、ソフトウェア のやりとりで一般的に使われる耐久性のある物理的媒体に固定していっしょに頒布する。 + * b) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、最低でも3年間、あるいはあなたがその製品モデルに補修用部品やカスタマーサポートを提供する限り有効な、書面 による申し出を添付する。その申し出には、(1) オブジェクトコードを所有する者すべてに対して、その製品に含まれるソフトウェアのうち本許諾書で保護されるものすべてに『対応するソース』のコピーを、ソフトウェアのやりとりで一般的に使われる耐久性のある物理的媒体で頒布する旨を記載する。その際、物理的にこのソースの伝達を行うのにかかる正当なコスト以上の価格を要求してはならない。あるいは、(2) 『対応するソース』を無料でネットワークサーバから複製するためのアクセスを提供する旨を記載する。 + * c) オブジェクトコードの個々のコピーを、対応するソースを提供するという書面による申し出のコピーといっしょに伝達する。この選択肢は特別な場合、かつ非商業的な場合のみに、そしてあなたがオブジェクトコードを上記小項 6bに合致した申し出といっしょに受領した場合にのみに認められる。 + * d) オブジェクトコードを、指定の場所から複製するためのアクセスを提供することによって伝達し、『対応するソース』に対しても同じ場所を通じて同じ方法で複製するための同等のアクセスを提供する。伝達は無料でも手数料を課しても構わないが、『対応するソース』に対して追加的な課金を行ってはならない。受領者に対して、『対応するソース』をオブジェクトコードといっしょに複製することを義務づける必要はない。オブジェクトコードの複製元がネットワークサーバの場合、対応するソースは同等の複製機能をサポートする異なったサーバ(あなたか第三者が運営)上にあっても良い。その場合、オブジェクトコードの傍らに、『対応するソース』はどこで見つけられるかを明確に指示しておかなければならない。どのサーバが『対応するソース』をホストするかに関わらず、あなたは『対応するソース』がこれらの条 項を満たすために必要なかぎり利用可能であることを保証する責任がある。 + * e) オブジェクトコードをピア・ツー・ピア伝送を使って伝達する。ただしこの場合、あなたは上記小項6dに従い、その作品のオブジェクトコードと 『対応するソース』がどこで一般公衆に無料で提供されるのかということを他のピアに知らせておかなければならない。 + +オブジェクトコードの分離した一部であり、そのソースコードが『対応するソース』から『システムライブラリ』として除外されているものは、オブジェクトコード作品を伝達する場合に含める必要はない。 + +「ユーザ製品」(User Product)とは、(1)「コンシューマ製品」(consumer product)、すなわち、個人、子供、あるいは家庭用に通常使用される有形個人資産すべてか、あるいは(2)居住所における導入を目的に設計ないし販売されるものすべてを指す。ある物品がコンシューマ製品であるかを決定する際疑義がある場合には、極力範囲を広げる方向で決定されるべきである。ここで、ある特定のユーザによって受領されたある特定の製品にとっての「通常使用」 (nomally used)とは、その種の製品において典型的な、あるいは一般的な利用のことであり、その特定のユーザが置かれた状況や、その特定のユーザがその製品を実際にどう使っているか、どう使うことを予期しているか、あるいは予期されているかとは関係ない。その製品に相当な商業的、産業的または非コンシューマ的な利用法があったとしても、そうした利用がその製品の唯一重要な利用形態を代表するものでない限り、その製品はコンシューマ製品である。 + +ユーザ製品の「『インストール用情報』」(Installation Information)とは、ユーザ製品内の『保護された作品』に関して、『対応するソース』の改変されたバージョンから得られる『保護された作品』の改変されたバージョンを、インストール、実行するために必要な手法、手順、認証キーやその他の情報すべてを意味する。この情報は、改変されたオブジェクトコードの継続的な動作が、改変が為されたということによってのみ拒否されたり妨害されることが決してないことを保証するのに十分なものでなければならない。 + +本節の下において、作品をユーザ製品の内で、またはユーザ製品と共に、あるいは特にユーザ製品での利用を念頭においてオブジェクトコードで伝達し、またその伝達がユーザ製品の受領者への所有と利用の権利の永遠ないし有期の移転の一部として起こる場合(移転がどのように行われるかは問わない)、この条項の下で『対応するソース』は『インストール用情報』と共に提供されなければならない。しかしこの条件は、あなたと第三者のいずれもが改変されたオブジェクトコードをユーザ製品にインストールする能力を有していない際には適用されない(例えば、作品がROMにインストールされている場合)。 + +『インストール用情報』を提供する条件には、受領者によって改変ないしインストールされた作品、あるいはそうした作品が改変ないしインストールされたユーザ製品に対し、サービスや保証、アップデートを提供しつづけるという条件は含まれない。改変自体がネットワークの運用に実質的かつ有害な影響をもたらし、ネットワークを介したコミュニケーションのプロトコルや規則に違反する場合には、ネットワークアクセスを拒否しても構わない。 + +伝達される『対応するソース』や提供される『インストール用情報』が本節を満たすためには、それらが公に文書化された形式で(かつ公衆に対してソースコード形式で利用可能な実装とともに)提供されなければならない。この場合、これらの圧縮展開や読み込み、複製に特別なパスワードやキーを必要としてならない。 +7. 追加的条項¶ + +「追加的許可」(Additional permissions)とは、本許諾書が課す条件に一つかそれ以上の例外を設けることにより、本許諾書の条項を補足する条項のことである。『プログラム』全体に適用可能な追加的許可は、適用可能な法の下でそれらが有効である限り、あたかもそれらが本許諾書に含まれているかのように扱われなければならない。追加的許可が『プログラム』の一部にのみ適用される場合、その部分に関してはそういった追加的許可の下で別途利用可能だが、『プログラム』全体としては追加的許可に関わりなく本許諾書によってのみ管理される。 + +あなたが『保護された作品』のコピーを伝達する場合、あなたは追加的許可をそのコピー、あるいはその一部から削除することを選択できる (追加的許可は、あなたが作品をある種の形で改変する際には、そうした許可自身の削除を要求するような形で書かれてもよい)。あなたは、あなたによって『保護された作品』に追加され、あなたが適切な『コピーライト』許可を有するか、与えることができる限り、その一部分に追加的許可を設定することができる。 + +本許諾書の他の条件に関わらず、あなたが『保護された作品』に追加した一部分について(その部分の『コピーライト』保有者らによって正式に許可されていれば)、本許諾書の条項を、以下に示す条項で補足することができる: + + * a) 本許諾書第15項および第16項の条項とは異なった形で保証の否認や責任の限定を主張する。あるいは、 + * b) 追加した一部分において、明示的で妥当な法的告知や作者特定の保全、またはそれを含む作品において『適切な法的告知』の表示を要求する。あるいは、 + * c) 追加した一部分の出自を不当に表示することを禁じるか、あるいはそのような一部分の改変されたバージョンはオリジナルのバージョンとは異なっ ているということを適切な方法で印づけることを要求する。あるいは、 + * d) その一部分のライセンサーや作者の名前を、宣伝目的で利用することを制限する。あるいは、 + * e) 商品名や商標、サービスマークの利用に関して、商標法に従い権利を授与することを拒否する。あるいは、 + * f) その一部分(あるいはその改変されたバージョン)を伝達する者に、受領 者への責任に関して契約上の引き受けがあり、そうした責任が直接的にそういったライセンサーや作者にまで課せられる場合、その一部分のライセンサーや作者の免責を要求する。 + +他の非許可的な追加的条項は下記第10項が意味するところの「さらなる権利制限」(further restrictions)とみなされる。あなたが受領した『プログラム』、あるいはその一部に、それが本許諾書とともにさらなる権利制限である条項によっても管理されていると述べた告知が含まれている場合には、あなたはそういった条項を削除して構わない。あるライセンス文書にさらなる権利制限がふくまれているが、しかし本許諾書の下での再許諾や伝達を許可しているならば、あなたはそのライセンス文書の条項によって管理されている一部分を『保護された作品』に追加することができる。ただしその場合、さらなる権利制限はそのような再許諾や伝達では無効としなければならない。 + +あなたが本節に従って『保護された著作物』に条項を追加した場合、あなたは関係するソースファイル中に、それらのファイルに適用される追加的条項に関する声明、あるいは適用可能な条項を見つけることができる場所を示す告知を掲載しなければならない。 + +追加的条項は、それが許可的であろうと非許可的であろうと、別途書面化されたライセンスという形式で述べられてもよいし、本許諾書への例外として述べられてもよい。上記の要件はどちらの場合でも適用される。 +8. 終了¶ + +あなたは『保護された作品』を、本許諾書の下で明示的に提供されている場合を除いて、普及、または改変してはならない。それ以外に『保護された作品』を普及、または改変しようとする試みはすべて無効であり、本許諾書の下であなたに認められた権利(下記第11項の第3段落に従い授与されたパテントライセンスすべてを含む)を自動的に終了させることになる。 + +しかしながら、あなたが本許諾書への違反をすべて中止するならば、あなたがある特定の『コピーライト』保有者から得たライセンスは、(a)その『コピーライト』保有者が明白かつ決定的にあなたへのライセンスを終了させるか、あるいはさせないまでは暫定的に、(b)その『コピーライト』保有者が、あなたに対し違反について、何らかの正当な手段によりライセンス停止後60日以内に通知することができなかった場合には永続的に、回復される。 + +加えて、あなたがある特定の『コピーライト』保有者から得たライセンスは、その『コピーライト』保有者があなたに対して違反を何らかの正当な手段で通知し、それより前にその『コピーライト』保有者から、(当該作品に限らずその『コピーライト』保有者の作品のいずれかに関して)本許諾書に関する違反の通知を受領したことがなく、さらにあなたがその通知を受領してから30日以内に違反を正した場合、永続的に回復される。 + +本節に従いあなたの権利が終了した場合でも、本許諾書に従ってあなたからコピーや権利を受領した当事者が得た許諾は終了しない。あなたの権利が終了され、永続的に回復されなかった場合には、あなたは同じライセンス対象に関し下記第10項に従って新たにライセンスを受領する資格を失うものとする。 +9. コピーの所有に必要とされない受諾¶ + +あなたは、『プログラム』のコピーを受領あるいは実行するために本許諾書を受諾する必要はない。コピーを受領するためにピア・ツー・ピア伝送を使った結果としてのみ発生する『保護された作品』の付随的な普及も、同様に受諾を必要としない。しかしながら、他の場合においては、本許諾書以外にあなたに対して『保護された作品』の普及や改変をする許可を認めるものはない。これらの行為は、本許諾書を受諾しない限り『コピーライト』を侵害することになる。そこで、『保護された作品』を改変あるいは普及することにより、あなたはそうした行為を行うために本許諾書を受諾したということを示したことになる。 +10. 下流の受領者への自動的許諾¶ + +あなたが『保護された作品』を伝達するたびに、受領者は自動的にオリジナルのライセンサーから、本許諾書に従いその作品を実行、改変、普及するライセンスを得る。なお、あなたには第三者が本許諾書に従うことを強制する責任はない。 + +「主体取引」(entity transaction)とは、ある組織そのもの、ないしその組織の実質的に全ての資産の支配権が移転するか、あるいは組織の細分化や合併が行われるような取引を指す。もし主体取引の結果として『保護された作品』の普及が起こった場合、作品のコピーを受領したそれぞれの取引当事者は、利害関係のある当事者の先任者から、その先任者が前段落に従って有する、あるいは与えることができる、その作品に関するライセンスもまたすべて受領する。加えて個々の取引当事者は、利害関係のある先任者から、その先任者が有しているか、適正な努力によって得ることが可能な限りにおいて、その作品の『対応するソース』の所有権も得る権利を有する。 + +あなたは本許諾書の下で授与された、あるいは確約された権利の行使に対して、本許諾書が規定する以上のさらなる権利制限を課してはならない。たとえば、あなたはライセンス料、ロイヤルティや他の料金を、本許諾書の下で認められている権利の行使に関して課してはならない。また、あなたは『プログラム』やその一部の作成、利用、販売、販売の申し出、取り込みによって何らかのパテントクレームが侵害されたとして、訴訟(訴訟における反対請求ないし反訴を含む)を開始してはならない。 +11. 特許¶ + +「貢献者」(contributor)とは、本許諾書の下で『プログラム』、あるいは『プログラム』が基にした作品を利用することを正式に許可した『コピーライト』保有者のことを指す。従って、そのようにしてライセンスされた作品は、貢献者による「貢献者バージョン」(contributor version)と呼ばれる。 + +ある貢献者の「必須パテントクレーム」(essential patent claims)とは、すでに取得しているか、あるいは今後取得する見込みがあるため、その貢献者が現在所有ないし支配していると言える特許のうち、貢献者バージョンに対して、本許諾書で許可されているような作成や利用、販売といった何らかの形の行為を行うことによって侵害される可能性があるパテントクレームのすべてを意味する。ただし、貢献者バージョンをさらに改変した結果としてのみ侵害されるようなクレームは含まれない。この定義において、「支配」には本許諾書が課す条件と整合的なやり方で特許の再許諾を認める権利も含まれる。 + +個々の貢献者はあなたに対して、その貢献者の必須パテントクレームに関し、あなたがその貢献者バージョンの内容を作成、利用、販売、販売の申し出、取り込み、その他実行、改変、普及するために必要な、非排他的で全世界的に有効、かつロイヤルティフリーのパテントライセンスを授与する。 + +以下の3段落において「『パテントライセンス』」とは、ある特許を実施しないという明示的な協定やコミットメントのすべてを指す(例えば、ある特許の実施に対する明示的な許可や、特許侵害訴訟を提起しないという誓約など)。そのような『パテントライセンス』をある当事者に「授与」するとは、その当事者と特許を実施しないという協定やコミットメントを結ぶことを意味する。 + +もしあなたが、『保護された作品』の伝達を、それがある『パテントライセンス』に依存しており、よってその作品の『対応するソース』は、すべての人にとって、公衆が利用可能なネットワークサーバや他の容易にアクセス可能な手段を通じ、無料かつ本許諾書に従って複製可能ではないということを知りながら行うならば、あなたは (1)『対応するソース』も同様に利用可能にするか、 (2)この特定の作品に関して『パテントライセンス』から得られる便益を自ら剥奪するか、あるいは(3)下流の受領者に対しても、本許諾書の条項と整合的な形で、『パテントライセンス』が拡大されるように計らうかのいずれかを行わなければならない。ここで「『パテントライセンス』に依存するのを知りながら」というのは、あなたが『保護された作品』をある国で伝達すること、あるいはあなたの受領者が『保護された著作物』をある国で利用することが、『パテントライセンス』を授与されない限り、その国において、あなたにとってそれが有効だと信じるだけの理由がある一つかそれ以上の同定可能な特許を侵害するということを実際に知っているということである。 + +ある一対一の取引や協定に基づき、あるいは関連して、あなたが『保護された作品』の伝達、または伝達によって引き起こされる普及を行い、その際『保護された作品』を受領した一部の当事者に対して、『保護された作品』の特定のコピーの利用、普及、改変、または伝達を正式に許可するような『パテントライセンス』を授与するならば、あなたが授与した『パテントライセンス』は『保護された作品』やそれを基にした作品のすべての受領者にまで自動的に拡大されることになる。 + +ある『パテントライセンス』が「差別的」(discriminatory)であるとは、本許諾書の下で明確に認められた一つかそれ以上の権利を、『パテントライセンス』がカバーする範囲内に含まなかったり、そうした権利の行使を禁じたり、あるいは権利を行使しないことを条件として課すようなものである場合を指す。あなたを一方の当事者とし、ソフトウェアの頒布を生業とする第三者との間で、あなたは第三者に対し、作品を伝達する活動の程度に基づいて支払いを行う一方、第三者は、あなたから『保護された作品』を受領したすべての当事者に対して「差別的」な『パテントライセンス』を、(a)あなたが伝達した『保護された作品』のコピー(またはそうしたコピーから作成されたコピー)に対して、または(b)『保護された作品』を含む特定製品や編集物を、主要な、あるいは関連した対象として授与する、というような協定を結んでいる場合、あなたは『保護された作品』を伝達してはならない。ただし、あなたがそのような協定を締結したり、『パテントライセンス』を授与されたのが2007å¹´3月28日より以前である場合は本節の例外とする。 + +本許諾書に含まれる一切の記述は、適用可能な特許法の下であなたが利用可能な暗黙のライセンス、その他侵害への防御手段を排除したり制限したりするように解釈されてはならない。 +12. 他者の自由を明け渡してはならない¶ + +何らかの条件(裁判所の指令や協定など)があなたに課せられ、それが本許諾書の条件と矛盾したとしても、あなたが本許諾書の条件を免れることにはならない。あなたが、『保護された作品』を、本許諾書が課す義務と他の関連した義務の両方を同時に満たすような形で伝達できないのであれば、結果としてあなたがそれを伝達することは全く不可能ということになる。例えばあなたが、自分が『プログラム』を伝達した人々がさらに伝達を行う場合には、彼らからロイヤルティを徴収する、というような義務を負う条項に同意していた場合、あなたがそういった条項と本許諾書の両方を満たすには、『プログラム』の伝達を完全に止めてしまうしかないだろう。 +13. GNU Affero 一般公衆利用許諾書との利用¶ + +本許諾書に含まれる他の条件に関わらず、あなたには、『保護された作品』を GNU Affero 一般公衆利用許諾書バージョン3の下で許諾された作品とリンクまたは結合して単一の結合物とし、その結果物を伝達する許可が与えられる。本許諾書の条項は『保護された作品』である部分に関してはそのまま適用されるが、結合物それ自体としては、GNU Affero 一般公衆利用許諾書の第13項が規定する、ネットワークを介したやりとりに関する特殊な条件も適用されることになる。 + +(訳注: 訳出時点では、GNU Affero GPLは改定作業が依然続いており、確定バージョンはリリースされていない。 http://gplv3.fsf.org/agplv3-dd2-guide.htmlを参照せよ。) +14. 本許諾書の改訂されたバージョン¶ + +フリーソフトウェア財団は、改訂された、あるいは新しいバージョンの GNU 一般公衆利用許諾書を折りに触れて発行することができる。そのような新バージョンは、その精神においては現在のバージョンと似たものになるだろうが、細部については新たな問題や懸念を解決すべく異なるものになるだろう。 + +それぞれのバージョンには、見分けがつくようなバージョン番号が振られている。『プログラム』に、ある特定のバージョン番号が振られた GNU 一般公衆利用許諾書「かそれ以降のバージョンのいずれか(or any later version)」が適用されると指定されていた場合、あなたは指定された番号のバージョンか、それ以降にフリーソフトウェア財団によって発行されたいずれかのバージョンのどちらの利用条件に従うかを選ぶことができる。『プログラム』が本許諾書のバージョン番号を指定していなかった場合には、あなたはフリーソフトウェア財団がそれまでに発行したバージョンの中からどれを選択しても構わない。 + +(訳注: 日本語訳のバージョンは日付で管理している。冒頭を見よ。) + +『プログラム』において、GNU 一般公衆利用許諾書の将来のバージョンのうちどれが適用されうるかは代理人が決定できる、と指定されていた場合、その代理人が、あるバージョンを受諾すると述べた公的な声明は、あなたに対し、その『プログラム』に関してそのバージョンのGNU GPLを選ぶことを永続的かつ正式に許可するのと等しい。 + +本許諾書の今後のバージョンでは、あなたに追加的な、または従来とは異なった形での許可を与えるかもしれない。しかしながら、作者や『コピーライト』保有者に対し、あなたが以降のバージョンに従うことを選んだ結果として、追加的な義務が課せられることはない。 +15. 保証の否認¶ + +『プログラム』には、適用可能な法で許可されている範囲において何の保証もない。書面で述べられていない限り、『コピーライト』保有者やその他の当事者は『プログラム』を「あるがまま(as is)」で、明示的、暗示的を問わず、いかなる種類の保証もなく提供する。この保証には、商用可能性や特定目的への適合性の暗黙的保証が含まれるが、これらに限定されない。『プログラム』の質や性能に関するリスクはすべてあなたに帰属する。『プログラム』に問題があると判明した場合、あなたは必要なすべての対応、補修、修正にかかる費用を負うものとする。 +16. 責任の限定¶ + +適用可能な法において義務づけられるか、書面による同意がない限り、『コピーライト』保有者あるいはその他『プログラム』を上記で許可された通りに改変あるいは伝達する当事者は、たとえそうした保有者や他の当事者が損害が発生する可能性について事前に通知されていたとしても、あなたに対して損害賠償責任を有することはない。ここでいう損害には、『プログラム』の利用あるいは利用できないことから発生した一般的、特殊的、偶然的、必然的な損害のすべてが含まれる(データの消失やデータの不正確な解釈、あなたや第三者によって被った、あるいは『プログラム』が他のプログラムといっしょにうまく動作しなかったために引き起こされた損害などが含まれるが、これらに限定されない)。 +17. 第15項と第16項の解釈について¶ + +上記のような保証の否認や責任の限定が、特定国内においてそういった条項が指定する通りの法的効力を持ち得ない場合、再審裁判所は、『プログラム』に関連したすべての民事責任の絶対的棄権に最も近く肉薄する国内法を適用すべきである。ただし、報酬の見返りとして責任の保証や引き受けが『プログラム』のコピーに付随する場合は除く。 + + + + +GNU 一般公衆利用許諾書 (GNU General Public License)¶ + +バージョン3、2007å¹´6月29日 +日本語訳、2007å¹´9月5日 + +Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +(訳: 本ライセンス文書を、一字一句忠実に複製、頒布することは許可する。しかし変更は認めない。) + +This is an unofficial translation of the GNU General Public License into Japanese. It was not published by the Free Software Foundation, and does not legally state the distribution terms for software that uses the GNU GPL--only the original English text of the GNU GPL does that. However, we hope that this translation will help Japanese speakers understand the GNU GPL better. + +(訳: 以下はGNU General Public Licenseの非公式な日本語訳です。これはフリーソフトウェア財団 (Free Software Foundation)によって正式に発表されたものではなく、GNU GPLが適用されたソフトウェアの頒布条件を法的に有効な形で述べたものではありません。頒布条件としては、GNU GPLの英語版テキストで指定されているもののみが有効です。しかしながら、私たちはこの翻訳が、日本語を使用する人々にとってGNU GPLをより良く理解する助けとなることを望んでいます。) + +翻訳は八田真行 <mhatta@gnu.org>が行った。原文はhttp://www.gnu.org/licenses/gpl-3.0.html である。誤訳の指摘や訳の改善案を歓迎する。なお、日本語訳の利用条件は原文に準ずる。 +はじめに¶ + +GNU 一般公衆利用許諾書は、ソフトウェアやその他の種類の著作物のための、フリーかつコピーレフトを主張するライセンスです。 + +ソフトウェアやその他の実用的著作物向けのライセンスの大半は、あなたから著作物を共有したり変更したりする自由を奪い去るよう設計されています。それらとは対照的に、GNU 一般公衆利用許諾書は、あなたに対してあるプログラムの全てのバージョンを共有、変更する自由を保証すること、すなわち、そのソフトウェアがそのユーザすべてにとってフリーでありつづけることを保証することを目的としています。私たちフリーソフトウェア財団(Free Software Foundation)は、GNU 一般公衆利用許諾書を私たちのソフトウェアの大半に適用しています。その作者が私たちと同様の方法で公開するならば、他のいかなる著作物にも適用することが可能です。もちろん、あなたのプログラムにも適用することができます。 + +私たちがフリーソフトウェアについて語るとき、私たちは自由について言及しているのであって、価格は問題にしていません。私たちが用意した一般公衆利用許諾書の数々は、フリーソフトウェアのコピーを頒布する(そして希望によっては頒布に際して手数料を要求する)自由をあなたに保証すべく設計されています。すなわち、ソースコードを受領するか、望めばそれを手に入れられるということ、ソフトウェアを変更し、その一部を新たなフリープログラムで利用することができるということ、そしてこうしたことが可能であることをあなたが知っているということが保証されるのです。 + +(訳注: GNU GPL以外の一般公衆利用許諾書として、GNU AGPLとGNU LGPLが用意されている。) + +あなたの権利を守るため、私たちは誰か他人が上記のようなあなたの権利を否定したり、権利を放棄するように求めることを防ぐ必要があります。そこで、あなたがソフトウェアのコピーを頒布したり改変したりする場合、あなたにはある種の責任が発生します。それは、他人の自由を尊重するという責任です。 + +たとえば、本許諾書が適用されたプログラムのコピーをあなたが頒布する場合、それが無料であろうと手数料を取る場合であろうと、あなたは受領者たちに、あなた自身が受け取ったのと同じ自由を渡さなければなりません。あなたは、彼らもまた、ソースコードを受領するか後に得られることを保証しなければなりません。そしてあなたは、彼らに本許諾書の条項を示し、彼らの権利について彼らに知らしめなければなりません。 + +GNU GPLを利用する開発者は、あなたの権利を2段階の手順を踏んで守ります。その手順とは、(1) ソフトウェアに著作権を主張し、(2) あなたに本許諾書を提示して、ソフトウェアを複製、頒布、または改変する法的な許可を与える、というものです。 + +開発者や作者を守るため、GPLでは、このフリーソフトウェアには何の保証もないということを明確に説明しています。ユーザと開発者両方の便宜のため、 GPLでは改変されたバージョンには変更された旨を印づけるよう要求しており、改変されたバージョンの問題が、誤って以前のバージョンの作者に帰せられることがないようにしています。 + +一部の機器は、それらに収録されたソフトウェアを改変した上で再びインストールしたり、実行したりするために必要なアクセスを、製造者には拒否しないにもかわらずユーザに対しては拒否するよう設計されています。これは、ユーザが自らの有するソフトウェアを変更する自由を守るというGPLの目的とは、根本的に相容れません。このような技術の濫用は、往々にして個人使用向けの製品の分野で見られるものですが、まさにこのような分野こそ、こうした慣行が最も容認しがたいものとなるのです。そこで私たちは、このバージョンのGPLを、そうした製品においてこの種の慣行を禁止するように設計しました。もし同種の問題が他の領域にまで相当程度広がってきた場合には、私たちはユーザの自由を守るためのに必要とされるだけ、GPLの将来のバージョンにおいてこの規定をそうした領域にも拡大すべく準備を整えています。 + +最後に、すべてのプログラムはソフトウェア特許によって絶え間なく脅かされています。およそ国家は、特許が汎用コンピュータにおけるソフトウェアの開発と利用を制限することを認めるべきではありません。しかし、そういったことを認めてしまっている地域においては、私たちは、特許がフリーなプログラムに適用され、実質的にプログラムがプロプライエタリにされてしまうという特別な脅威を避けたいと思います。こうした事態を防ぐために、GPLでは、プログラムを非フリーとするために特許を使うことはできないということを保証します。 + +(訳注: 本許諾書で「プロプライエタリ (proprietary)」とは、ソフトウェアの利用や再頒布、改変が禁止されているか、許可を得ることが必要とされているか、あるいは厳しい制限が課せられていて自由にそうすることが事実上できなくなっている状態のことを指す。詳しくはhttp://www.gnu.org/philosophy/categories.ja.html#ProprietarySoftware をを参照せよ。) + +複製、頒布、改変に関する正確な利用条件は以下で述べていきます。 +利用条件 (TERMS AND CONDITIONS)¶ +0. 定義¶ + +「本許諾書」(The License)とは、GNU 一般公衆利用許諾書のバージョン3を指す。 + +「『コピーライト』」(Copyright)とは、いわゆる著作権のみならず、半導体マスクのようなその他の作品に適用される、著作権に類似した法的権利をも意味する。 + +(訳注: この規定により、本許諾書は著作権法で保護されたいわゆる「著作物」よりも広い範囲をカバーすることになる。よってこの訳のライセンス本文中においては、work(s)に「著作物」ではなく「作品」という訳語を宛てることにした。) + +「『プログラム』」(The Program)とは、本許諾書の下でライセンスされた、『コピーライト』が主張可能な作品すべてを意味する。個々のライセンシーは「あなた」として表現される。ライセンシーは個人でも組織でも構わない。 + +ある作品の「改変」(modify)とは、その作品の全体ないし一部を、『コピーライト』の許可を必要とするようなやり方で複製ないし翻案することを意味する。ただし、完全に同一なコピーを作成する場合は除く。改変の結果出来た作品は、以前の作品の「改変されたバージョン」(modified version)、または、以前の作品を「基にした」(based on)作品と呼ばれる。 + +「『保護された作品』」(covered work)とは、改変されていない『プログラム』か、『プログラム』を基にした作品のいずれかを指す。 + +ある作品の「普及」(propagate)とは、コンピュータ上で実行すること、または私的なコピーを改変することを除き、適用可能な『コピーライト』法規の下で許可無く行うと、権利侵害として、直接的、あるいは間接的にあなたが責任を問われる何らかの行為を意味する。普及には、複製、頒布 (改変の有無を問わない)、公衆への利用可能化が含まれ、またいくつかの国々では他の活動も含まれる可能性がある。 + +ある作品の「伝達」(convey)とは、第三者がコピーを作成ないし受領するのを可能とする普及行為すべてを意味する。ただし、コンピュータネットワーク越しにユーザとやりとりするだけで、コピーの転送は伴わない場合は、伝達ではない。 + +対話的なユーザインターフェースが「『適切な法的告知』」(Appropriate Legal Notices)を表示するという場合、そのインターフェースは (1)適切な『コピーライト』告知を表示し、(2)ユーザに対して、その作品には何の保証もない(別途保証が提供されている場合は除く)ということ、ライセンシーはその作品を本許諾書の下で伝達できるということ、そして本許諾書のコピーを見るにはどうしたらよいかということを便利かつ顕著に視認できるような機能を含むものとする。もしインターフェースが、メニューのようなユーザコマンドやオプションの一覧を表示するならば、その一覧中には上記の基準を満たすようなアイテムが目立つように含まれていなければならない。 +1. ソースコード¶ + +ある作品の「ソースコード」(source code)とは、その作品に改変を加えるに当たって好ましいと考えられる形式のことである。「オブジェクトコード」 (object code)とは、作品がとりうるソースコード以外の形式すべてを意味する。 + +「標準インターフェース」(Standard Interface)とは、標準化団体として認知された組織によって定義された公式な標準か、ある特定のプログラミング言語向けに指定されたインターフェースの場合には、その言語を利用する開発者の間で広く使われているインターフェースのことを指す。 + +実行可能な作品の「『システムライブラリ』」(System Libraries)とは、 (a)「主要コンポーネント」(Major Component) の頒布物に通常含まれるが、その主要コンポーネントの一部ではなく、かつ(b)作品をその「主要コンポーネント」といっしょに利用することを可能にする、あるいは公衆にとってソースコード形式で利用可能な実装がひとつは存在する標準インターフェースを提供するためにのみ機能するものすべてを意味する。ただし、全体としての作品そのものは除く。ここでいう「主要コンポーネント」とは、実行可能な作品がその上で実行されるある特定のオペレーティングシステム (そういったものが必要ならば)の主要で不可欠な一部分(カーネルやウィンドウシステムなど)、あるいはその作品を作成するのに使われるコンパイラ、実行するのに使われるオブジェクトコードインタプリタなどを意味する。 + +オブジェクトコード形式の作品に「『対応するソース』」(Corresponding Source)とは、その作品を生成、インストール、(実行可能な作品に関しては)オブジェクトコードを実行、または作品を改変する上で必要とされるソースコードのすべてを意味する。この場合、そうした活動をコントロールするためのスクリプトは『対応するソース』に含まれるが、その作品にとっての『システムライブラリ』や、先ほど列挙した活動を行う上で改変されることなく利用されるものの作品の一部ではない、汎用のツールや一般的に利用可能なフリープログラムは除外される。例えば『対応するソース』には、その作品のソースファイルと連携するインターフェース定義ファイルに加え、共有ライブラリや動的にリンクされた下位プログラムと作品のその他の部分との間での親密なデータのやりとりやコントロールフローなどのために、その作品が設計上明確に必要とする、そうした共有ライブラリや下位プログラムのソースコードなどが含まれる。 + +『対応するソース』には、ユーザが『対応するソース』の他の部分から自動的に再生成できるものを含む必要はない。 + +ソースコード形式の作品にとっての『対応するソース』とは、その作品そのものである。 +2. 基本的な許可¶ + +本許諾書の下で認められるすべての権利は、『プログラム』に主張される『コピーライト』の条項に基づき授与されるものであり、ここで述べられた条件が満たされている限り覆すことはできない。本許諾書は、改変されていない『プログラム』をあなたが無制限に実行することを許可し、明示的に確約する。『保護された作品』を実行することから得られた出力結果は、その出力内容が『保護された作品』を構成する場合のみ本許諾書で保護される。本許諾書は、あなたが有するフェアユースまたはその同等物の権利を、『コピーライト』法規によって提供される通りに承認する。 + +その他の状況においてあなたのライセンスが有効である限り、『保護された作品』の、伝達を伴わない作成、実行、および普及は無条件に行うことができる。他者にあなた専用の改変を行わせる、あるいは他者にあなたがそういった作品を実行するための機能を提供させるということが唯一の目的であれば、『保護された作品』を他者に伝達することができる。ただしその場合、あなたが『コピーライト』を支配していない部分すべての伝達に関しては、本許諾書の条項に従わなければならない。従って、あなたのために『保護された作品』を作成または実行する者は、専らあなたのためだけに、あなたの監督と支配の下で、あなたとの関係の範囲外ではあなたが『コピーライト』を有する一部分のいかなるコピーをも作成することを禁止するという条件の下で行わなければならないということになる。 + +上記以外のあらゆる状況下においては、伝達は以下で述べる条件の下でのみ許可される。再許諾は認められない。下記第10項により、再許諾は必要ないからである。 +3. ユーザの法的権利を、技術的保護手段の回避を禁ずる法律から守る¶ + +『保護された作品』は、 1996å¹´12月20日に採択されたWIPO著作権条約第11項の下での義務を満たす適用可能な法のいずれか、あるいはそれに類似の法が、回避の禁止または制限の対象として規定する、「効果的な技術的手段」 (effective technological measure)の一部として見なされてはならない。 + +(訳注: WIPO著作権条約については、http://www.cric.or.jp/db/article/wch.html 等を参照せよ。) + +あなたが『保護された作品』を伝達する場合、『保護された作品』に関して本許諾書の下で権利を行使することにより、技術的手段の回避に影響が出る範囲において、そのような手段の回避を禁じるいかなる法的権力をも放棄することになる。また、あなたはその作品のユーザに対して、技術的手段の回避を禁じるためにあなたや第三者の法的権利を強制するための手段として、その作品の動作や改変を制限するいかなる意図も否認することになる。 +4. 一字一句忠実なコピーの伝達¶ + +あなたは、自分が受領した『プログラム』のソースコードと一字一句同じコピーであれば、いかなる媒体でも伝達することができる。ただしその場合、あなたはそれぞれのコピーにおいて、目立つように、かつ適切な形で、ふさわしい『コピーライト』告知を掲載しなければならない。すなわち、本許諾書と、下記第7項に従い追加された非許可的条項のすべてがそのコードに適用される旨の告知を掲載し、あらゆる保証が存在しない旨の告知をすべてそのまま保全し、かつ『プログラム』の受領者すべてに、『プログラム』といっしょにこの許諾書のコピーを与えなければならない。 + +あなたは、自分が伝達するコピーのそれぞれに関していかなる価格を付けても良いし、無料で伝達しても構わない。また、報酬を取ってサポートや保証保護 (warranty protection)を提供しても良い。 +5. 改変されたバージョンのソースの伝達¶ + +あなたは、『プログラム』を基にした作品、あるいはそうした作品を『プログラム』から作成するための改変点を、上記第4項の規定に従ってソースコード形式で伝達することができる。ただしその場合、あなたは以下に示す条件のすべてを満たさなければならない: + + * a) 作品には、あなたが作品を改変したということと、改変に関連した日時を記述した告知を目立つように載せなければならない。 + * b) 作品には、それが本許諾書と、下記第7項に従って追加された条件すべての下で公開されていることを記述した告知を目立つように載せなければな らない。この条件は、上記第4項における「告知をすべてそのまま保全」するための条項を改変する。 + * c) 作品の全部分を、総体として、コピーを所有するに至った人全員に、本許諾書の下でライセンスしなければならない。そこで、本許諾書は、本許諾書第7項に基づく適用可能な追加的条項のすべてとともに、作品全体に、すなわちその全部分に、それらがどのようにパッケージされているかに関わらず適用されることになる。本許諾書は、これ以外のやり方には作品をライセンスする許可を与えないが、あなたが本許諾書以外で別途許可を得ていた場合には、それによって得られた許可まで無効とするものではない。 + * d) 改変された作品が対話的なユーザインターフェースを有する場合、それらのインターフェースは『適切な法的告知』を表示しなければならない。ただし、『プログラム』に元々『適切な法的告知』を表示しない対話的なインターフェースがある場合、あなたの作品で表示するようにする必要はない。 + +一巻の記憶装置の中か頒布媒体上で、『保護された作品』と、本来『保護された作品』の拡張ではなく、『保護された作品』とより大規模なプログラムを形成するような形で結合されているわけでもないその他の分離かつ独立した作品とをまとめた編集物は、編集作業とそれに由来する『コピーライト』が、個々の作品が許可する範囲を越えて編集物のユーザの作品へのアクセスや法的権利を制限するのに使われない限り、「集積物」(aggregate)と呼ばれる。単に『保護された作品』を集積物に含めるだけでは、その集積物の他の部分にまで本許諾書が適用されるということにはならない。 +6. ソース以外の形式における伝達¶ + +あなたは、オブジェクトコード形式の『保護された著作物』を、上記第4項および第5項の規定に従って伝達することができる。ただしその場合、あなたは機械読み取り可能な『対応するソース』も本許諾書の条件に従って、以下のいずれかの方法で伝達しなければならない。 + + * a) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、『対応するソース』を、ソフトウェア のやりとりで一般的に使われる耐久性のある物理的媒体に固定していっしょに頒布する。 + * b) オブジェクトコードを物理的製品(物理的頒布媒体を含む)で、あるいはそれに組み込んで伝達する。その際、最低でも3年間、あるいはあなたがその製品モデルに補修用部品やカスタマーサポートを提供する限り有効な、書面 による申し出を添付する。その申し出には、(1) オブジェクトコードを所有する者すべてに対して、その製品に含まれるソフトウェアのうち本許諾書で保護されるものすべてに『対応するソース』のコピーを、ソフトウェアのやりとりで一般的に使われる耐久性のある物理的媒体で頒布する旨を記載する。その際、物理的にこのソースの伝達を行うのにかかる正当なコスト以上の価格を要求してはならない。あるいは、(2) 『対応するソース』を無料でネットワークサーバから複製するためのアクセスを提供する旨を記載する。 + * c) オブジェクトコードの個々のコピーを、対応するソースを提供するという書面による申し出のコピーといっしょに伝達する。この選択肢は特別な場合、かつ非商業的な場合のみに、そしてあなたがオブジェクトコードを上記小項 6bに合致した申し出といっしょに受領した場合にのみに認められる。 + * d) オブジェクトコードを、指定の場所から複製するためのアクセスを提供することによって伝達し、『対応するソース』に対しても同じ場所を通じて同じ方法で複製するための同等のアクセスを提供する。伝達は無料でも手数料を課しても構わないが、『対応するソース』に対して追加的な課金を行ってはならない。受領者に対して、『対応するソース』をオブジェクトコードといっしょに複製することを義務づける必要はない。オブジェクトコードの複製元がネットワークサーバの場合、対応するソースは同等の複製機能をサポートする異なったサーバ(あなたか第三者が運営)上にあっても良い。その場合、オブジェクトコードの傍らに、『対応するソース』はどこで見つけられるかを明確に指示しておかなければならない。どのサーバが『対応するソース』をホストするかに関わらず、あなたは『対応するソース』がこれらの条 項を満たすために必要なかぎり利用可能であることを保証する責任がある。 + * e) オブジェクトコードをピア・ツー・ピア伝送を使って伝達する。ただしこの場合、あなたは上記小項6dに従い、その作品のオブジェクトコードと 『対応するソース』がどこで一般公衆に無料で提供されるのかということを他のピアに知らせておかなければならない。 + +オブジェクトコードの分離した一部であり、そのソースコードが『対応するソース』から『システムライブラリ』として除外されているものは、オブジェクトコード作品を伝達する場合に含める必要はない。 + +「ユーザ製品」(User Product)とは、(1)「コンシューマ製品」(consumer product)、すなわち、個人、子供、あるいは家庭用に通常使用される有形個人資産すべてか、あるいは(2)居住所における導入を目的に設計ないし販売されるものすべてを指す。ある物品がコンシューマ製品であるかを決定する際疑義がある場合には、極力範囲を広げる方向で決定されるべきである。ここで、ある特定のユーザによって受領されたある特定の製品にとっての「通常使用」 (nomally used)とは、その種の製品において典型的な、あるいは一般的な利用のことであり、その特定のユーザが置かれた状況や、その特定のユーザがその製品を実際にどう使っているか、どう使うことを予期しているか、あるいは予期されているかとは関係ない。その製品に相当な商業的、産業的または非コンシューマ的な利用法があったとしても、そうした利用がその製品の唯一重要な利用形態を代表するものでない限り、その製品はコンシューマ製品である。 + +ユーザ製品の「『インストール用情報』」(Installation Information)とは、ユーザ製品内の『保護された作品』に関して、『対応するソース』の改変されたバージョンから得られる『保護された作品』の改変されたバージョンを、インストール、実行するために必要な手法、手順、認証キーやその他の情報すべてを意味する。この情報は、改変されたオブジェクトコードの継続的な動作が、改変が為されたということによってのみ拒否されたり妨害されることが決してないことを保証するのに十分なものでなければならない。 + +本節の下において、作品をユーザ製品の内で、またはユーザ製品と共に、あるいは特にユーザ製品での利用を念頭においてオブジェクトコードで伝達し、またその伝達がユーザ製品の受領者への所有と利用の権利の永遠ないし有期の移転の一部として起こる場合(移転がどのように行われるかは問わない)、この条項の下で『対応するソース』は『インストール用情報』と共に提供されなければならない。しかしこの条件は、あなたと第三者のいずれもが改変されたオブジェクトコードをユーザ製品にインストールする能力を有していない際には適用されない(例えば、作品がROMにインストールされている場合)。 + +『インストール用情報』を提供する条件には、受領者によって改変ないしインストールされた作品、あるいはそうした作品が改変ないしインストールされたユーザ製品に対し、サービスや保証、アップデートを提供しつづけるという条件は含まれない。改変自体がネットワークの運用に実質的かつ有害な影響をもたらし、ネットワークを介したコミュニケーションのプロトコルや規則に違反する場合には、ネットワークアクセスを拒否しても構わない。 + +伝達される『対応するソース』や提供される『インストール用情報』が本節を満たすためには、それらが公に文書化された形式で(かつ公衆に対してソースコード形式で利用可能な実装とともに)提供されなければならない。この場合、これらの圧縮展開や読み込み、複製に特別なパスワードやキーを必要としてならない。 +7. 追加的条項¶ + +「追加的許可」(Additional permissions)とは、本許諾書が課す条件に一つかそれ以上の例外を設けることにより、本許諾書の条項を補足する条項のことである。『プログラム』全体に適用可能な追加的許可は、適用可能な法の下でそれらが有効である限り、あたかもそれらが本許諾書に含まれているかのように扱われなければならない。追加的許可が『プログラム』の一部にのみ適用される場合、その部分に関してはそういった追加的許可の下で別途利用可能だが、『プログラム』全体としては追加的許可に関わりなく本許諾書によってのみ管理される。 + +あなたが『保護された作品』のコピーを伝達する場合、あなたは追加的許可をそのコピー、あるいはその一部から削除することを選択できる (追加的許可は、あなたが作品をある種の形で改変する際には、そうした許可自身の削除を要求するような形で書かれてもよい)。あなたは、あなたによって『保護された作品』に追加され、あなたが適切な『コピーライト』許可を有するか、与えることができる限り、その一部分に追加的許可を設定することができる。 + +本許諾書の他の条件に関わらず、あなたが『保護された作品』に追加した一部分について(その部分の『コピーライト』保有者らによって正式に許可されていれば)、本許諾書の条項を、以下に示す条項で補足することができる: + + * a) 本許諾書第15項および第16項の条項とは異なった形で保証の否認や責任の限定を主張する。あるいは、 + * b) 追加した一部分において、明示的で妥当な法的告知や作者特定の保全、またはそれを含む作品において『適切な法的告知』の表示を要求する。あるいは、 + * c) 追加した一部分の出自を不当に表示することを禁じるか、あるいはそのような一部分の改変されたバージョンはオリジナルのバージョンとは異なっ ているということを適切な方法で印づけることを要求する。あるいは、 + * d) その一部分のライセンサーや作者の名前を、宣伝目的で利用することを制限する。あるいは、 + * e) 商品名や商標、サービスマークの利用に関して、商標法に従い権利を授与することを拒否する。あるいは、 + * f) その一部分(あるいはその改変されたバージョン)を伝達する者に、受領 者への責任に関して契約上の引き受けがあり、そうした責任が直接的にそういったライセンサーや作者にまで課せられる場合、その一部分のライセンサーや作者の免責を要求する。 + +他の非許可的な追加的条項は下記第10項が意味するところの「さらなる権利制限」(further restrictions)とみなされる。あなたが受領した『プログラム』、あるいはその一部に、それが本許諾書とともにさらなる権利制限である条項によっても管理されていると述べた告知が含まれている場合には、あなたはそういった条項を削除して構わない。あるライセンス文書にさらなる権利制限がふくまれているが、しかし本許諾書の下での再許諾や伝達を許可しているならば、あなたはそのライセンス文書の条項によって管理されている一部分を『保護された作品』に追加することができる。ただしその場合、さらなる権利制限はそのような再許諾や伝達では無効としなければならない。 + +あなたが本節に従って『保護された著作物』に条項を追加した場合、あなたは関係するソースファイル中に、それらのファイルに適用される追加的条項に関する声明、あるいは適用可能な条項を見つけることができる場所を示す告知を掲載しなければならない。 + +追加的条項は、それが許可的であろうと非許可的であろうと、別途書面化されたライセンスという形式で述べられてもよいし、本許諾書への例外として述べられてもよい。上記の要件はどちらの場合でも適用される。 +8. 終了¶ + +あなたは『保護された作品』を、本許諾書の下で明示的に提供されている場合を除いて、普及、または改変してはならない。それ以外に『保護された作品』を普及、または改変しようとする試みはすべて無効であり、本許諾書の下であなたに認められた権利(下記第11項の第3段落に従い授与されたパテントライセンスすべてを含む)を自動的に終了させることになる。 + +しかしながら、あなたが本許諾書への違反をすべて中止するならば、あなたがある特定の『コピーライト』保有者から得たライセンスは、(a)その『コピーライト』保有者が明白かつ決定的にあなたへのライセンスを終了させるか、あるいはさせないまでは暫定的に、(b)その『コピーライト』保有者が、あなたに対し違反について、何らかの正当な手段によりライセンス停止後60日以内に通知することができなかった場合には永続的に、回復される。 + +加えて、あなたがある特定の『コピーライト』保有者から得たライセンスは、その『コピーライト』保有者があなたに対して違反を何らかの正当な手段で通知し、それより前にその『コピーライト』保有者から、(当該作品に限らずその『コピーライト』保有者の作品のいずれかに関して)本許諾書に関する違反の通知を受領したことがなく、さらにあなたがその通知を受領してから30日以内に違反を正した場合、永続的に回復される。 + +本節に従いあなたの権利が終了した場合でも、本許諾書に従ってあなたからコピーや権利を受領した当事者が得た許諾は終了しない。あなたの権利が終了され、永続的に回復されなかった場合には、あなたは同じライセンス対象に関し下記第10項に従って新たにライセンスを受領する資格を失うものとする。 +9. コピーの所有に必要とされない受諾¶ + +あなたは、『プログラム』のコピーを受領あるいは実行するために本許諾書を受諾する必要はない。コピーを受領するためにピア・ツー・ピア伝送を使った結果としてのみ発生する『保護された作品』の付随的な普及も、同様に受諾を必要としない。しかしながら、他の場合においては、本許諾書以外にあなたに対して『保護された作品』の普及や改変をする許可を認めるものはない。これらの行為は、本許諾書を受諾しない限り『コピーライト』を侵害することになる。そこで、『保護された作品』を改変あるいは普及することにより、あなたはそうした行為を行うために本許諾書を受諾したということを示したことになる。 +10. 下流の受領者への自動的許諾¶ + +あなたが『保護された作品』を伝達するたびに、受領者は自動的にオリジナルのライセンサーから、本許諾書に従いその作品を実行、改変、普及するライセンスを得る。なお、あなたには第三者が本許諾書に従うことを強制する責任はない。 + +「主体取引」(entity transaction)とは、ある組織そのもの、ないしその組織の実質的に全ての資産の支配権が移転するか、あるいは組織の細分化や合併が行われるような取引を指す。もし主体取引の結果として『保護された作品』の普及が起こった場合、作品のコピーを受領したそれぞれの取引当事者は、利害関係のある当事者の先任者から、その先任者が前段落に従って有する、あるいは与えることができる、その作品に関するライセンスもまたすべて受領する。加えて個々の取引当事者は、利害関係のある先任者から、その先任者が有しているか、適正な努力によって得ることが可能な限りにおいて、その作品の『対応するソース』の所有権も得る権利を有する。 + +あなたは本許諾書の下で授与された、あるいは確約された権利の行使に対して、本許諾書が規定する以上のさらなる権利制限を課してはならない。たとえば、あなたはライセンス料、ロイヤルティや他の料金を、本許諾書の下で認められている権利の行使に関して課してはならない。また、あなたは『プログラム』やその一部の作成、利用、販売、販売の申し出、取り込みによって何らかのパテントクレームが侵害されたとして、訴訟(訴訟における反対請求ないし反訴を含む)を開始してはならない。 +11. 特許¶ + +「貢献者」(contributor)とは、本許諾書の下で『プログラム』、あるいは『プログラム』が基にした作品を利用することを正式に許可した『コピーライト』保有者のことを指す。従って、そのようにしてライセンスされた作品は、貢献者による「貢献者バージョン」(contributor version)と呼ばれる。 + +ある貢献者の「必須パテントクレーム」(essential patent claims)とは、すでに取得しているか、あるいは今後取得する見込みがあるため、その貢献者が現在所有ないし支配していると言える特許のうち、貢献者バージョンに対して、本許諾書で許可されているような作成や利用、販売といった何らかの形の行為を行うことによって侵害される可能性があるパテントクレームのすべてを意味する。ただし、貢献者バージョンをさらに改変した結果としてのみ侵害されるようなクレームは含まれない。この定義において、「支配」には本許諾書が課す条件と整合的なやり方で特許の再許諾を認める権利も含まれる。 + +個々の貢献者はあなたに対して、その貢献者の必須パテントクレームに関し、あなたがその貢献者バージョンの内容を作成、利用、販売、販売の申し出、取り込み、その他実行、改変、普及するために必要な、非排他的で全世界的に有効、かつロイヤルティフリーのパテントライセンスを授与する。 + +以下の3段落において「『パテントライセンス』」とは、ある特許を実施しないという明示的な協定やコミットメントのすべてを指す(例えば、ある特許の実施に対する明示的な許可や、特許侵害訴訟を提起しないという誓約など)。そのような『パテントライセンス』をある当事者に「授与」するとは、その当事者と特許を実施しないという協定やコミットメントを結ぶことを意味する。 + +もしあなたが、『保護された作品』の伝達を、それがある『パテントライセンス』に依存しており、よってその作品の『対応するソース』は、すべての人にとって、公衆が利用可能なネットワークサーバや他の容易にアクセス可能な手段を通じ、無料かつ本許諾書に従って複製可能ではないということを知りながら行うならば、あなたは (1)『対応するソース』も同様に利用可能にするか、 (2)この特定の作品に関して『パテントライセンス』から得られる便益を自ら剥奪するか、あるいは(3)下流の受領者に対しても、本許諾書の条項と整合的な形で、『パテントライセンス』が拡大されるように計らうかのいずれかを行わなければならない。ここで「『パテントライセンス』に依存するのを知りながら」というのは、あなたが『保護された作品』をある国で伝達すること、あるいはあなたの受領者が『保護された著作物』をある国で利用することが、『パテントライセンス』を授与されない限り、その国において、あなたにとってそれが有効だと信じるだけの理由がある一つかそれ以上の同定可能な特許を侵害するということを実際に知っているということである。 + +ある一対一の取引や協定に基づき、あるいは関連して、あなたが『保護された作品』の伝達、または伝達によって引き起こされる普及を行い、その際『保護された作品』を受領した一部の当事者に対して、『保護された作品』の特定のコピーの利用、普及、改変、または伝達を正式に許可するような『パテントライセンス』を授与するならば、あなたが授与した『パテントライセンス』は『保護された作品』やそれを基にした作品のすべての受領者にまで自動的に拡大されることになる。 + +ある『パテントライセンス』が「差別的」(discriminatory)であるとは、本許諾書の下で明確に認められた一つかそれ以上の権利を、『パテントライセンス』がカバーする範囲内に含まなかったり、そうした権利の行使を禁じたり、あるいは権利を行使しないことを条件として課すようなものである場合を指す。あなたを一方の当事者とし、ソフトウェアの頒布を生業とする第三者との間で、あなたは第三者に対し、作品を伝達する活動の程度に基づいて支払いを行う一方、第三者は、あなたから『保護された作品』を受領したすべての当事者に対して「差別的」な『パテントライセンス』を、(a)あなたが伝達した『保護された作品』のコピー(またはそうしたコピーから作成されたコピー)に対して、または(b)『保護された作品』を含む特定製品や編集物を、主要な、あるいは関連した対象として授与する、というような協定を結んでいる場合、あなたは『保護された作品』を伝達してはならない。ただし、あなたがそのような協定を締結したり、『パテントライセンス』を授与されたのが2007å¹´3月28日より以前である場合は本節の例外とする。 + +本許諾書に含まれる一切の記述は、適用可能な特許法の下であなたが利用可能な暗黙のライセンス、その他侵害への防御手段を排除したり制限したりするように解釈されてはならない。 +12. 他者の自由を明け渡してはならない¶ + +何らかの条件(裁判所の指令や協定など)があなたに課せられ、それが本許諾書の条件と矛盾したとしても、あなたが本許諾書の条件を免れることにはならない。あなたが、『保護された作品』を、本許諾書が課す義務と他の関連した義務の両方を同時に満たすような形で伝達できないのであれば、結果としてあなたがそれを伝達することは全く不可能ということになる。例えばあなたが、自分が『プログラム』を伝達した人々がさらに伝達を行う場合には、彼らからロイヤルティを徴収する、というような義務を負う条項に同意していた場合、あなたがそういった条項と本許諾書の両方を満たすには、『プログラム』の伝達を完全に止めてしまうしかないだろう。 +13. GNU Affero 一般公衆利用許諾書との利用¶ + +本許諾書に含まれる他の条件に関わらず、あなたには、『保護された作品』を GNU Affero 一般公衆利用許諾書バージョン3の下で許諾された作品とリンクまたは結合して単一の結合物とし、その結果物を伝達する許可が与えられる。本許諾書の条項は『保護された作品』である部分に関してはそのまま適用されるが、結合物それ自体としては、GNU Affero 一般公衆利用許諾書の第13項が規定する、ネットワークを介したやりとりに関する特殊な条件も適用されることになる。 + +(訳注: 訳出時点では、GNU Affero GPLは改定作業が依然続いており、確定バージョンはリリースされていない。 http://gplv3.fsf.org/agplv3-dd2-guide.htmlを参照せよ。) +14. 本許諾書の改訂されたバージョン¶ + +フリーソフトウェア財団は、改訂された、あるいは新しいバージョンの GNU 一般公衆利用許諾書を折りに触れて発行することができる。そのような新バージョンは、その精神においては現在のバージョンと似たものになるだろうが、細部については新たな問題や懸念を解決すべく異なるものになるだろう。 + +それぞれのバージョンには、見分けがつくようなバージョン番号が振られている。『プログラム』に、ある特定のバージョン番号が振られた GNU 一般公衆利用許諾書「かそれ以降のバージョンのいずれか(or any later version)」が適用されると指定されていた場合、あなたは指定された番号のバージョンか、それ以降にフリーソフトウェア財団によって発行されたいずれかのバージョンのどちらの利用条件に従うかを選ぶことができる。『プログラム』が本許諾書のバージョン番号を指定していなかった場合には、あなたはフリーソフトウェア財団がそれまでに発行したバージョンの中からどれを選択しても構わない。 + +(訳注: 日本語訳のバージョンは日付で管理している。冒頭を見よ。) + +『プログラム』において、GNU 一般公衆利用許諾書の将来のバージョンのうちどれが適用されうるかは代理人が決定できる、と指定されていた場合、その代理人が、あるバージョンを受諾すると述べた公的な声明は、あなたに対し、その『プログラム』に関してそのバージョンのGNU GPLを選ぶことを永続的かつ正式に許可するのと等しい。 + +本許諾書の今後のバージョンでは、あなたに追加的な、または従来とは異なった形での許可を与えるかもしれない。しかしながら、作者や『コピーライト』保有者に対し、あなたが以降のバージョンに従うことを選んだ結果として、追加的な義務が課せられることはない。 +15. 保証の否認¶ + +『プログラム』には、適用可能な法で許可されている範囲において何の保証もない。書面で述べられていない限り、『コピーライト』保有者やその他の当事者は『プログラム』を「あるがまま(as is)」で、明示的、暗示的を問わず、いかなる種類の保証もなく提供する。この保証には、商用可能性や特定目的への適合性の暗黙的保証が含まれるが、これらに限定されない。『プログラム』の質や性能に関するリスクはすべてあなたに帰属する。『プログラム』に問題があると判明した場合、あなたは必要なすべての対応、補修、修正にかかる費用を負うものとする。 +16. 責任の限定¶ + +適用可能な法において義務づけられるか、書面による同意がない限り、『コピーライト』保有者あるいはその他『プログラム』を上記で許可された通りに改変あるいは伝達する当事者は、たとえそうした保有者や他の当事者が損害が発生する可能性について事前に通知されていたとしても、あなたに対して損害賠償責任を有することはない。ここでいう損害には、『プログラム』の利用あるいは利用できないことから発生した一般的、特殊的、偶然的、必然的な損害のすべてが含まれる(データの消失やデータの不正確な解釈、あなたや第三者によって被った、あるいは『プログラム』が他のプログラムといっしょにうまく動作しなかったために引き起こされた損害などが含まれるが、これらに限定されない)。 +17. 第15項と第16項の解釈について¶ + +上記のような保証の否認や責任の限定が、特定国内においてそういった条項が指定する通りの法的効力を持ち得ない場合、再審裁判所は、『プログラム』に関連したすべての民事責任の絶対的棄権に最も近く肉薄する国内法を適用すべきである。ただし、報酬の見返りとして責任の保証や引き受けが『プログラム』のコピーに付随する場合は除く。 + diff --git a/rec10/license.txt b/rec10/license.txt new file mode 100644 index 0000000..69e51ec --- /dev/null +++ b/rec10/license.txt @@ -0,0 +1,254 @@ +GNU LESSER GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/> + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. +0. Additional Definitions. + +As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License. + +“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. + +An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. + +A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”. + +The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. + +The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. +1. Exception to Section 3 of the GNU GPL. + +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. +2. Conveying Modified Versions. + +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: + + * a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or + * b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. + +3. Object Code Incorporating Material from Library Header Files. + +The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: + + * a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. + * b) Accompany the object code with a copy of the GNU GPL and this license document. + +4. Combined Works. + +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: + + * a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. + * b) Accompany the Combined Work with a copy of the GNU GPL and this license document. + * c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. + * d) Do one of the following: + o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. + * e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) + +5. Combined Libraries. + +You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: + + * a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. + * b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +6. Revised Versions of the GNU Lesser General Public License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. + + +GNU GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/> + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. +TERMS AND CONDITIONS +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. +1. Source Code. + +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. +2. Basic Permissions. + +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + * a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + * b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + * c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + * d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + * a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + * b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + * c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + * d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + * e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. +7. Additional Terms. + +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + * a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + * b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + * c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + * d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + * e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + * f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. +11. Patents. + +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. +13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. diff --git a/rec10/n_gram.py b/rec10/n_gram.py new file mode 100644 index 0000000..f24a097 --- /dev/null +++ b/rec10/n_gram.py @@ -0,0 +1,120 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import zenhan +def bigram(str1, str2): + str1 = zenhan.toHankaku(str1) + str2 = zenhan.toHankaku(str2) + str1 = str1.replace(" ", "") + str2 = str2.replace(" ", "") + """ + bigramによる単語の近さを計算します。 + """ + gram = [] + if len(str1) < 2: + gram.append(str1) + else: + tmp = str1[0] + for x in str1[1:]: + gram.append(tmp + x) + tmp = x + point = 0 + for x in gram: + i = findGram(x, str2) + if i > 0: + i = 90 + 10 * i + else: + i = 0 + point = point + i + return point +def trigram(str1, str2): + """ + trigramによる単語の近さを計算します。 + 単語文字列の長さも考慮にいれます。 + """ + str1 = zenhan.toHankaku(str1) + str2 = zenhan.toHankaku(str2) + str1 = str1.replace(" ", "") + str2 = str2.replace(" ", "") + gram = [] + if len(str1) < 3: + gram.append(str1) + else: + tmp1 = str1[0] + tmp2 = str1[1] + for x in str1[2:]: + gram.append(tmp1 + tmp2 + x) + tmp1 = tmp2 + tmp2 = x + point = 0 + count = 0 + for x in gram: + i = findGram(x, str2) + if i > 0: + i = 90 + 10 * i + count=count + 1 + else: + i = 0 + point = point + i + point = point + 20*count*count + point = point / len(str1) * 10 + point = point / len(str2) * 10 + return point +def findGram(gram, s): + """ + s中にあらわれるgramの数を調べる + """ + st = s + i = 0 + while st.find(gram) != -1: + i = i + 1 + st = st[st.find(gram) + 1:] + return i +def getNounQuadGram(s): + """ + 。 + """ + str1 = zenhan.toHankaku(s) + gram={} + if len(str1) > 4: + tmp1 = str1[0] + tmp2 = str1[1] + tmp3 = str1[2] + skipnum=0 + for x in str1[3:]: + if skipnum>0: + skipnum=skipnum-1 + else: + tmps=tmp1 + tmp2 + tmp3 + x + if tmps.find(" ")<0: + if zenhan.checkCharacterType(tmp1)>0: + if (zenhan.checkCharacterType(tmp1)==zenhan.checkCharacterType(tmp2)): + if (zenhan.checkCharacterType(tmp2)==zenhan.checkCharacterType(tmp3)): + if (zenhan.checkCharacterType(tmp3)==zenhan.checkCharacterType(x)): + gram[tmps]=gram.get(tmps,0)+1 + skipnum=0 + else: + skipnum=3 + else: + if (zenhan.checkCharacterType(tmp3)==zenhan.checkCharacterType(x)): + skipnum=2 + else: + skipnum=3 + else: + if (zenhan.checkCharacterType(tmp2)==zenhan.checkCharacterType(tmp3)): + if (zenhan.checkCharacterType(tmp3)==zenhan.checkCharacterType(x)): + skipnum=0 + else: + skipnum=3 + else: + if (zenhan.checkCharacterType(tmp3)==zenhan.checkCharacterType(x)): + skipnum=2 + else: + skipnum=3 + tmp1 = tmp2 + tmp2 = tmp3 + tmp3 = x + return gram +"" \ No newline at end of file diff --git a/rec10/readme.txt b/rec10/readme.txt new file mode 100644 index 0000000..7feec4d --- /dev/null +++ b/rec10/readme.txt @@ -0,0 +1,222 @@ +########################################### +# Rec10 -Ts Recording system- # +# Ver.0.9.10 # +# 2012/05/12 Yukikaze & long.inus # +# Copyright (C) 2009-2012 Yukikaze # +########################################### + +本ソフトはpythonおよびperlによって書かれた録画ツールです。 +ライセンスは LGPL v3に準拠します(license.txt参照) + +[必要コマンド] +python(2.6,2.7にて動作確認) +wine +mencoder +ffmpeg +x264 +mp4box +MySQL +MySQLdb(MySQL-pythonなどの名前) +mkvmerge(mkv使用時) +java(jre1.6で動作を確認) + +[必要環境:Webインターフェース部分] +perl +一部のperlモジュール(rectool.pl,rec10webg2) + +[必要環境:外部ツール] +jTsSplitter(included) +BonTsDemux(included) +epgdump(included) +b25(not included) +#recpt1(recfriioでもいいはずです)(not included) +MySQLdb +tunerec(included)が追加で必要 + +1:install.shを実行 +2:表示にしたがって設定の変更(チャンネルなど) +3:make +4:su +5:make install +5'rec10を実行するユーザーをvideoグループに加える(DVB版を使う場合) +6:rec10を実行するユーザーで/usr/local/share/rec10を実行 +7:cronに書き加える +8:rectool.plをインストール(Makefile.PLの実行 rectool.plの配置) + +付け足し + +7.cronの設定 + +最後にrec10d.pyをcronで五分おきに実行するようにしてください +crontab -e を実行するとcronを編集できるようになるので +*/5 * * * * python /usr/local/bin/rec10 +のように書いてください(5扮ごとに実行) + +ログは/var/log/rec10に移動しました。 + +8.rectoolのインストール +Makefile.PLを実行します。 +実行した後にrectool.plをhttpの公開ディレクトリ(wwwフォルダなど)に置いてください。 + +ちなみに +エンコードの設定を変えたい場合はts2x264.pyを参照してください + + +チャンネルの設定を変えた場合はを編集した後に +chdata.pyを実行してください(python chdata.py) +その後番組表が更新されます + +バグだらけのコードですが、改善点などを指摘していただけるとうれしいです。 +yukikaze.jp@gmail.com + +rec10オプション一覧 + +サイズ : S(720x480)/W(854x480)/H(1280x720)/F(1920x1080)/I(Interlaced) +画質(x264 のcrf, 小さい方が高画質) : u(+2)/i(+1)/default(設定値)/o(-1)/p(-2) +圧縮率(x264 のpreset) : q(veryfast)/w(fast)/default(medium)/e(slow)/r(slower) +コンテナ : m(mkv mkvmerge が必要)/default(設定値)/4(mp4 MP4Box が必要) +音声 : d(二ヶ国語)/default(通常音声)/5(5.1ch) b(ステレオBonTsDemux使用、NHKの一部など) +フレームレート : a(24fps)/default(30fps) +移動opt : R(録画後移動)/D(復号後移動)/E(エンコード後移動)/default(移動なし) +その他 : N(自動命名オプション) / t(作業途中ファイルを残す) +特定デバイス向け : B(Blu-ray) 1(モバイル:QVGAのファイルを追加) 2(WVGAのファイルを追加) + + +動作確認のとれたディストリ +13/03/22 SVN Centos 6.4(dvb,yukikaze) +12/01/08 SVN Debian6.0 +11/03/10 SVN Centos 5.5 (yukikaze) +11/03/10 0.9.9.1+a ArchLinux (yukikaze) +11/02/20 0.9.9.1+a Debian 6.0 +11/02/XX 0.9.9 Ubuntu 10.10 +10/12/XX 0.9.8 Centos 5.5 (yukikaze) +10/XX/XX 0.9.8 Fedora13 (long.inus) + + +[History] +13/XX/XX 0.9.10 +DVB版の実装を修正 +12/XX/XX SVN +add Bluray compatible option("B") +ステレオ音声時のBonTsDemux仕様オプション追加("b") +lameの実行パスチェックを実装 +mencoderのコマンドラインを最新版対応へ +ffmpegのオプション追加 +epggenreを追加 +keywordの重複チェックをより賢く +logoのインポートに対応 +ArchLinuxサポートのための細かな変更 +新BSチャンネル対応 +lavf有効x264でのエラーに対応 +DVB版のドライバに対応 +PMT処理のバグを修正(jTsSplitter) +DVB版のBS放送のtsid変更に対応 + +11/02/02 0.9.9 +BonTsDemuxを最新版へ(nogui化によりXvfbが不要) +一部CSチャンネルの追加 +epg_chを変更(ontvの削除) +チャンネルスキャン機能を実装 +キーワード予約の自動実行オプション追加(in_auto_jbkにauto,optの追加) +番組初頭の解像度変更に対応 +キーワード予約自動実行オプションの重複チェック実装 +延長対応機能の修正 +移動後のオプション引き継ぎに対応 + +10/10/09 0.9.8 release +インターレース保持エンコードに対応 +色空間を修正 +放送大学のマルチチャンネルに仮対応 +verboseモードの実装 +ログレベルの実装 +画面サイズが取得できなかったときの処理を追加 +python2.5/2.7に対応 +音声の自動復帰を修正 + +10/07/10 0.9.7 release +ヒストリーチャンネルのタイトルを修正 +ffmpeg使用時にscale拡大をするように修正 +一時ファイル削除機能の修正 +sarの変更を実装 +最新版のCaption2Assに対応 + +10/05/29 0.9.6 release +バグ修正 +ログシステムの修正 + +0.9.5(内部リリース) +b25自動削除機能の改善 +自動仕分け機能のアップデート +Caption2Assやaac取り出しがうまくいかないときの自動復帰処理の実装 +バグ修正 + +10/04/02 0.9.4 release +バグ修正 +インストーラーの大幅な改善 +ログシステムの変更 +エンコードの変更 +チャンネル変更に対応(CS) + +10/03/20 0.9.3 release(internal) +lots of bug fixes. +change DB. +implement updating function(from 0.9.1 or 0.9.2) +10/03/06 0.9.2 release(internal) +few bug fix.(!!! amazing i think) +implement new encoding system. +use x264cli and mencoder throwgh fifo. +implement final production changing system(you can choose mkv and mp4 now.) + +10/02/21 0.9.1 release +Lots of bug fixes. +change video filter. +change encode option. +implement installer. + +09/12/07 0.9.0 release +change config path.(config.ini to rec10.conf) +add Makefile +change large number of var name. +support b25_remote(thanks long.inus) +support auto copy function. +change video filter. +change encode option. +fix a lot of bugs. +finish to support iEPG(iRec10EPG). + +09/10/27 0.8.0 relaase +Lots of bug fixes. +Use mkvmerge to mux avi to mkv. +Many changes. + +09/08/22 0.6.0 release +Lots of bug fixes. +Implement db using MySQL. +Change Ts splitting soft from Tssplitter to tssplitter_lite(included.) + +09/08/01 0.5.0 release +バグフィックス +検索録画のパターンマッチングアルゴリズムの変更(推測的な検索ができるようになった) +rectool.plを同梱するようにした。 +周辺ソフトのうちライセンスの問題がないものを同梱するようにした。 + +09/07/01 0.4.1 release +lots of bug fixes +add some cs-ch. +release pl src. +09/05/24 0.3.1 release +fix +チャンネルの増加 +エンコードオプションを実際に使えるようにした。 +1passモード実装 +niceコマンドをより広範囲に適用するようにした。 +09/05/08 0.1.1 release +fix +2passエンコードのログファイルがかぶるのを訂正 +一部チャンネル指定が間違っていたのを訂正 +その他多くのバグの訂正 +09/05/05 0.0.1b release +fix +replace tab to 4 spaces(it caused errors) +add some cs-e2 channels +09/05/04 0.0.1a release diff --git a/rec10/rec10.conf b/rec10/rec10.conf new file mode 100644 index 0000000..ee07571 --- /dev/null +++ b/rec10/rec10.conf @@ -0,0 +1,84 @@ +[path] +wine = /usr/bin/wine +x264 = /usr/bin/x264 +mencoder = /usr/bin/mencoder +tee = /usr/bin/tee +ffmpeg = /usr/bin/ffmpeg +rec10 = /usr/local/share/rec10 +lame = /usr/bin/lame +java = /usr/bin/java +#recpathは録画先のフォルダを指定 +recpath = /path of /recording + +recpt1 = /usr/local/bin/recpt1 + +#録画終了後に動画を置いておくフォルダを指定するとrectool.plでリスト化できます。 +recorded = + +#複数のrec10で役割を分担するときに用いる移動先 +move_destpath = +ts_movepath = + +#一時キャッシュに使用するフォルダです。 指定しない場合rec10本体と同じフォルダが使われます。 +tmp = /tmp/rec10 +epgdump = /usr/local/bin/epgdump +tssplitter = /usr/bin/java -jar /usr/local/share/rec10/tstools/jTsSplitter.jar +jTsSplitter = /usr/local/share/rec10/tstools/jTsSplitter.jar +bontsdemux = /usr/local/share/rec10/tstools/BonTsDemux.exe +caption2ass = /usr/local/share/rec10/tstools/Caption2Ass.exe +mp4box = /usr/bin/MP4Box +mkvmerge = /usr/bin/mkvmerge +mkvextract = /usr/bin/mkvextract +gridserver_port=10910 + +#b25関連の設定 +b25_remote=0 +#b25_remoteを使う場合は1にしてください。 +b25 = /usr/local/bin/b25 +#b25_remoteを使う場合、下記の"192.168.0.1"および"/~~~/b25-client.so"を書き換えてください。 +#b25_env = "export B25_SERVER_IP=192.168.0.1 && export LD_PRELOAD=/~~~/b25-client.so" + +useNeroAAC = 0 +NeroAAC = /usr/local/bin/neroAacEnc + +[dvb] +useDVB = 0 +DVBtune = /usr/local/bin/tunerec +DVBadapter = /dev/dvb/adapter +DVBTE = 1,3 +DVBBSCS = 0,2 +[db] +db = MySQL +mysql_dbname=rec10 +mysql_host=localhost +mysql_user=nobody +mysql_passwd=nobody +mysql_port=3306 +[env] +#同時エンコード最大数(自分のコア数が目安です。) +enc_max=2 +#地上デジタル放送録画可能数(PT-xは2,friioは1) +te_max=2 +#BS/CS放送録画可能数(PT-xは2,黒friioは1) +bscs_max=2 +iff = +bs = 0 +cs = 0 +make_mp4 = 1 +#エンコードの重さの設定 大きければ大きいほど(1-6)速度は遅くなるが同じ画質でもサイズが小さくなる。 +x264_preset=4 +crf=24 +animation_crf=18 +x264_thread = 0 +x264_addline = +remove_ts = 0 +bluray = 1 +[log] +verbose_level = 400#デーモンとして使う場合は変更する必要はありません。 +log_level = 900# +[dvb] +dvbtune = /usr/local/bin/tunerec +dvbadapter = /dev/dvb/adapter +usedvb = 0 +dvbte = 1,3 +dvbbscs = 0,2 diff --git a/rec10/rec10d.py b/rec10/rec10d.py new file mode 100644 index 0000000..637ac1e --- /dev/null +++ b/rec10/rec10d.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import os.path +import warnings +warnings.filterwarnings('ignore', "the sets module is deprecated") +import configreader +import dbMySQL +import timerec +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +if not os.path.exists(tmppath): + os.makedirs(tmppath) +global rec10db +def main(): + timerec.task() +db = configreader.getConfDB("db") +if db == "MySQL": + dbn = configreader.getConfDB("mysql_dbname") + dbh = configreader.getConfDB("mysql_host") + dbu = configreader.getConfDB("mysql_user") + dbpwd = configreader.getConfDB("mysql_passwd") + dbport = int(configreader.getConfDB("mysql_port")) + rec10db = dbMySQL.DB_MySQL(dbname=dbn, host=dbh, user=dbu, passwd=dbpwd, port=dbport) + rec10db.new_in_status() +else: + rec10db = dbSQLite.DB_SQLite(path + "ch.db") +if __name__ == "__main__": + main() + diff --git a/rec10/recdb.py b/rec10/recdb.py new file mode 100644 index 0000000..8f3b41b --- /dev/null +++ b/rec10/recdb.py @@ -0,0 +1,95 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import chdb +import n_gram +import rec10d +import recdblist + +def reserveKeyword(keyword, chtxt, btime, etime, deltatime, opt): + rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt) +def reserveEverydayKeyword(keyword, chtxt, btime, etime, deltatime, opt, deltaday,count): + tcount=count + if tcount<0: + tcount=-1 + rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD_EVERY_SOME_DAYS, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt, deltaday=deltaday,counter=tcount) +def reserveReckey(type, title, chtxt, btime, etime, opt): + rec10d.rec10db.add_timeline(type=type, chtxt=chtxt, title=title, btime=btime, etime=etime, opt=opt) +def deleteReckey(type, title, chtxt, btime): + rec10d.rec10db.del_timeline(type=type, title=title, chtxt=chtxt, btime=btime) +def reserveAutoKeyword(chtxt,title,btime,etime): + rec10d.rec10db.add_auto_timeline_keyword(chtxt, title, btime, etime) +def addAutoBayesKeyword(chtxt,title,btime,etime,point): + rec10d.rec10db.add_auto_timeline_bayes(chtxt, title, btime, etime,point) +def getProgramsInTheseHours(dhour): + dhour = int(dhour) + dminutes = 60 * dhour + dminutes = str(dminutes) + return rec10d.rec10db.select_bytime_timeline(dminutes) +def getProgramsInTheseMinutes(dminutes): + return rec10d.rec10db.select_bytime_timeline(dminutes) +def countRecNow(dhour): + d = getProgramsInTheseHours(dhour) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + ret = ret + 1 + return ret +def countRecNow_minutes(dminutes): + d = getProgramsInTheseMinutes(dminutes) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + ret = ret + 1 + return ret +def countRecNow_minutes_BSCS(dminutes): + d = getProgramsInTheseMinutes(dminutes) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + if len(chdb.searchCHFromChtxt(i['chtxt'])['ch']) > 2: + ret = ret + 1 + return ret +def countRecNow_minutes_TE(dminutes): + d = getProgramsInTheseMinutes(dminutes) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + if len(chdb.searchCHFromChtxt(i['chtxt'])['ch']) < 3: + ret = ret + 1 + return ret +def deleteOldProgramBeforeTheseHours(dhour): + """ + delete keys except recdblist.REC_MISS_ENCODE and recdblist.REC_KEYWORD_EVERY_SOME_DAYS before dhour hours from now. + """ + rec10d.rec10db.delete_old_timeline(dhour) +def delete_old_auto_keyword(dhour): + rec10d.rec10db.delete_old_auto_timeline_keyword(dhour) +def delete_old_auto_bayes(dhour): + rec10d.rec10db.delete_old_auto_timeline_bayes(dhour) +def getAll(): + return rec10d.rec10db.select_all_timeline() +def addRecLogProgram(title,chtxt,btime,etime,opt,exp,longexp,category): + rec10d.rec10db.add_in_timeline_log(chtxt,title,btime,etime,opt,exp,longexp,category) +def getAllJbkKeyword(): + return rec10d.rec10db.select_all_in_auto_jbk_key() +def checkDuplicated(title,chtxt,epgbtime,epgetime): + tl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime,epgetime) + nel=rec10d.rec10db.select_bytime_all_timeline(epgbtime, epgetime) + dup=0 + for t in tl: + if t["title"]==title and t["chtxt"]==chtxt: + dup=1 + elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt: + dup=1 + for t in nel: + if t["title"]==title and t["chtxt"]==chtxt: + dup=1 + elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt: + dup=1 + return dup diff --git a/rec10/recdblist.py b/rec10/recdblist.py new file mode 100644 index 0000000..8bb5edf --- /dev/null +++ b/rec10/recdblist.py @@ -0,0 +1,209 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +""" +task names +""" +import datetime +import os +import os.path +import traceback + +import configreader + +global REC_RESERVE +global REC_FINAL_RESERVE +global REC_ENCODE_GRID +global REC_ENCODE_LOCAL +global REC_ENCODE_QUE +global REC_MISS_ENCODE +global REC_KEYWORD +global REC_KEYWORD_EVERY_SOME_DAYS +global REC_FIN_LOCAL +global REC_MISS_DECODE +global REC_TS_DECODE_QUE +global REC_TS_DECODING +global REC_TS_RECORDING +global REC_AVI_TO_MKV +global REC_AVI_TO_MP4 +global REC_MKV_TO_MP4 +global REC_CHANGING_CANTAINER + +#ここから処理のちに移動 + +global REC_MOVE_END + +#ここから自動で提起される処理。 +global REC_AUTO_SUGGEST_REC +global REC_AUTO_SUGGEST_DECODE +global REC_AUTO_SUGGEST_ENCODE +global REC_AUTO_SUGGEST_AVI2MP4 +global REC_AUTO_SUGGEST_MKV2MP4 +global REC_AUTO_SUGGEST_AVI2FP +global REC_AUTO_SUGGEST_AP2FP +global REC_BAYES_SUGGEST +global REC_AUTO_KEYWORD +REC_RESERVE = "reserve_flexible" +REC_FINAL_RESERVE = "reserve_fixed" +REC_ENCODE_GRID = "convert_ts_mp4_network" +REC_ENCODE_LOCAL = "convert_ts_mp4_running" +REC_ENCODE_QUE = "convert_ts_mp4" +REC_MISS_ENCODE = "convert_avi_mp4_miss" +REC_KEYWORD = "search_today" +REC_KEYWORD_EVERY_SOME_DAYS = "search_everyday" +REC_FIN_LOCAL = "convert_ts_mp4_finished" +REC_MISS_DECODE = "convert_b25_ts_miss" +REC_TS_DECODE_QUE = "convert_b25_ts" +REC_TS_DECODING = "convert_b25_ts_running" +REC_TS_RECORDING = "reserve_running" +REC_CHANGING_CANTAINER = "convert_mkv_mp4_runnings" +REC_AVI_TO_MKV = "convert_avi_mkv" +REC_AVI_TO_MP4 = "convert_avi_mp4" +REC_MKV_TO_MP4 = "convert_mkv_mp4" + +REC_MOVE_END = "move_end" + +REC_AUTO_SUGGEST_REC = "auto_suggest_rec" +REC_AUTO_SUGGEST_DECODE = "auto_suggest_dec" +REC_AUTO_SUGGEST_ENCODE = "auto_suggest_enc" +REC_AUTO_SUGGEST_AVI2FP = "auto_suggest_avi2fp" +REC_AUTO_SUGGEST_AP2FP = "auto_suggest_ap2fp" +REC_AUTO_KEYWORD = "auto_keyword" +REC_BAYES_SUGGEST ="bayes_suggest" + +global BONTSDEMUX_DELAY +BONTSDEMUX_DELAY="0" + +version = 102 +version_str="0.9.10" + +global verbose_level_now +global log_level_now + +try: + log_level_now=int(configreader.getConfLog("log_level")) + verbose_level_now=int(configreader.getConfLog("verbose_level")) +except: + log_level_now=900 + verbose_level_now=400 + +os.environ['LANG'] = "ja_JP.UTF-8" +my_env = os.environ +my_env['LANG'] = "ja_JP.UTF-8" + +def getEnv(): + return my_env +def printutf8(unicode,verbose_level=500): + if verbose_level_now > verbose_level: + try: + str=unicode.encode('utf-8') + print str + except Exception, inst: + recdblist.addCommonlogEX("Error", "printutf8(recdblist.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) +def printutf8ex(unicode,verbose_level=500,log_level=500): + str=unicode.encode('utf-8') + if verbose_level_now > verbose_level: + print str + logfname="/var/log/rec10" + mode="a" + if log_level_now > log_level: + if os.path.exists(logfname): + f=open(logfname,mode) + f.write(str+"\n") + f.close() +def printutf8_Important(unicode): + printutf8ex(unicode,100,100) +def printutf8_Normal(unicode): + printutf8ex(unicode,300,300) +def printutf8_Detailed(unicode): + printutf8ex(unicode,600,600) +def addCommonlogEX(type,place,inst,txt,verbose_level=500,log_level=500): + lt=unicode(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))+u":" + if txt=="": + lt=lt+u"["+type+u"] "+place+u" "+inst + else: + try: + lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt + except: + print [type,place,inst,txt] + lt=lt.encode('utf-8') + logfname="/var/log/rec10" + mode="a" + if verbose_level_now > verbose_level: + print lt + if log_level_now > log_level: + if os.path.exists(logfname): + f=open(logfname,mode) + f.write(lt+"\n") + f.close() +def addCommandLog(tspath,log_title,cmd,cmd_log=""): + addLog(tspath,cmd,log_title+u"ログ-コマンド") + addLog(tspath,cmd_log,log_title+u"ログ-詳細") +def addCommandLogZip(tspath,log_title,log_filename_add,cmd,cmd_log=""): + logtitle=getLogTitle(tspath) + logo=logtitle+"."+log_filename_add+".log" + logzip=logtitle+".log.zip" + addLogAll(tspath,cmd+"\n\n"+cmd_log,log_title,logo) + import zip + zip.addFile2FileZip(logo,logzip) + os.remove(logo) +def addCommandSelfLog(tspath,command): + logpath=getLogTitle(tspath)+".command.log" + f="" + if os.path.exists(logpath): + f=open(logpath,'a') + else: + f=open(logpath,'w') + tc=command+u"\n\n" + tc=unicode(tc) + f.write(tc.encode("utf-8")) + #f.write(tc.encode('utf-8','ignore')) + f.close() +def getLogTitle(tspath): + logo=tspath + logo=logo.replace("_1.wav",".ts") + logo=logo.replace("_2.wav",".ts") + logo=logo.replace("_1.aac",".ts") + logo=logo.replace("_2.aac",".ts") + logo=logo.replace("_1.mp3",".ts") + logo=logo.replace("_2.mp3",".ts") + logo=logo.replace(".ts.tsmix",".ts") + logo=logo.replace(".ts.b25",".ts") + logo=logo.replace(".sa.avi",".ts") + logo=logo.replace(".m2v",".ts") + logo=logo.replace(".avi",".ts") + logo=logo.replace(".mkv",".ts") + logo=logo.replace(".wav",".ts") + logo=logo.replace(".mp4",".ts") + logo=logo.replace(".mp3",".ts") + logo=logo.replace(".aac",".ts") + logo=logo.replace(".srt",".ts") + logo=logo.replace(".264",".ts") + logo=logo.replace(".ts","") + return logo +def addLog(tspath,txt,log_title,maxtextlength=1500): + logo=getLogTitle(tspath)+".log" + f=open(logo,'a') + s=len(txt) + stxt="" + if s>maxtextlength*2 and maxtextlength>0: + stxt=txt[0:maxtextlength]+"\n\n(ry..)\n" + st=txt[s-maxtextlength:].find("\n") + if st>0: + stxt=stxt+txt[s-1500+st:] + else: + stxt=txt + txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + txtw=txtw+"\n####"+log_title+"####\n"+stxt + f.write(txtw.encode('utf-8')) + f.close() +def addLogAll(tspath,txt,log_title,logpath): + logo=logpath + f=open(logo,'a') + stxt=txt + txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + txtw=txtw+"\n####"+log_title+"####\n"+stxt + f.write(txtw.encode('utf-8')) + f.close() diff --git a/rec10/recording_earth_pt1.py b/rec10/recording_earth_pt1.py new file mode 100644 index 0000000..9fb8693 --- /dev/null +++ b/rec10/recording_earth_pt1.py @@ -0,0 +1,109 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze + +import sys +import subprocess +import time +import os +import os.path +import signal + +import configreader +import recdblist +# +#CHの定義は +#1-64 地デジ +#BS1,BS3...BS23 BS放送 +#CS2,CS4...CS24 CS放送 + +tmppath = configreader.getConfPath("tmp")+"/" +def channel2freq(channel):##freqを返す + freq="" + if channel[0:2].upper() != "CS" and channel[0:2].upper() != "BS": + ch=int(channel) + if ch<65:#TE 13ch 473_142857 + freq=str(473+(ch-13)*6)+u"142857" + elif channel[0:2].upper() == "CS":#CS2,CS4,CS6...CS24 + ch=int(channel.upper().replace("CS","")) + #freq = 12291000 + (CH_IDX - 2) * 40000 / 2 - 10678000; + freq=str((ch-2)*40000/2+1613000) + elif channel[0:2].upper() == "BS":#BS1,BS3,BS5...BS23 + ch=int(channel.upper().replace("BS","")) + freq=str((ch-1)*38360/2+1049480) + return freq +def testTune(adapter,channel,tsid): + my_env=recdblist.getEnv() + #tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapter+u" "+channel2freq(channel) + #p1=subprocess.Popen(tunecmd,shell=True) + recdblist.printutf8_Important([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel),tsid,"0.2","/dev/null"]) + p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel),tsid,"0.2","/dev/null"],env=my_env,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + time.sleep(0.2) + try: + os.kill(p1.pid,signal.SIGKILL) + except: + "" + if p1.communicate()[1].find("busy")>-1: + try: + p1.wait() + except: + "" + return 0 + else: + try: + p1.wait() + except: + "" + return 1 +def getAdapter(channel): + chl=[] + if channel[0:2].upper()=="BS" or channel[0:2].upper()=="CS": + chl=configreader.getConfDVB("DVBBSCS").split(",") + elif int(channel)<65: + chl=configreader.getConfDVB("DVBTE").split(",") + chlr=[] + for i in chl: + chlr.append(int(i)) + return chlr +def getActiveAdapter(channel,tsid="0"): + for i in getAdapter(channel): + rt=testTune(str(i),channel,tsid) + if rt==1: + return str(i) +def record(channel,tsid,out,timelength,decode=0): + if not os.path.exists(tmppath+u"rec.sh"): + ft=open(tmppath+u"rec.sh","w") + ft.write(u"#!/bin/bash\n/bin/cat $1 > \"$2\"") + ft.close() + os.system(u"chmod +x "+tmppath+u"rec.sh") + adapt=getActiveAdapter(channel,tsid) + my_env=recdblist.getEnv() + if adapt!=None: + tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapt+u" "+channel2freq(channel)+u" "+tsid+u" "+timelength+u" "+out + #reccmd=u"/bin/cat \""+configreader.getConfDVB("DVBadapter")+adapt+u"/dvr0\" > \""+out+u"\"" + #if decode==1: + # reccmd=configreader.getConfPath("b25")+u" -v 0 \""+configreader.getConfDVB("DVBadapter")+adapt+u"/dvr0\" \""+out+"\"" + recdblist.addLog(out, tunecmd, "record(DVB)",100) + p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapt,channel2freq(channel),tsid,timelength,out],env=my_env) + #time.sleep(0.2) + #if decode==1: + # p2=subprocess.Popen([configreader.getConfPath("b25"),u"-v 0",u"\""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\"","\""+out+"\""],preexec_fn=os.setsid,env=my_env,bufsize=-1) + #else: + # p2=subprocess.Popen([tmppath+u"rec.sh",configreader.getConfDVB("DVBadapter")+adapt+"/dvr0",out],preexec_fn=os.setsid,env=my_env,bufsize=-1) + #p2=subprocess.Popen(reccmd,shell=True,preexec_fn=os.setsid,env=my_env,bufsize=-1) + #time.sleep(float(timelength)) + #os.killpg(p2.pid,signal.SIGKILL) + #p2.wait() + #os.kill(p1.pid,signal.SIGKILL) + p1.wait() + else: + recdblist.printutf8ex(u"tuner busy",100,100) +def useDVB(): + try: + if int(configreader.getConfDVB("useDVB").replace(" ",""))==1: + return 1 + else: + return 0 + except: + return 0 \ No newline at end of file diff --git a/rec10/recque.py b/rec10/recque.py new file mode 100644 index 0000000..739a41e --- /dev/null +++ b/rec10/recque.py @@ -0,0 +1,80 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +import datetime +import os +import os.path +import glob +import time +import traceback + +import configreader +import recdblist +import recdb +tmppath = configreader.getConfPath("tmp")+"/" +if not os.path.exists(tmppath): + os.mkdir(tmppath) +def writeRecQue(parentpath,chtxt,title,opts): + outputpath=os.path.join(parentpath,title+".recq") + tmpoppath=os.path.join(tmppath,title+".recq") + f=open(outputpath,"w") + optt=opts + str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getConfEnv("iff")+","+chtxt+","+title+","+optt + f.write(str.encode('utf-8')) + f.close() + if not os.path.exists(outputpath): + if os.path.exists(tmpoppath): + os.remove(tmpoppath) + f2=open(tmpoppath,"w") + f2.write(str.encode('utf-8')) + f2.close() + try: + os.chmod(tmpoppath) + except: + "" + shutil.copy(tmpoppath,outputpath) + os.remove(tmpoppath) +def readRecQue(recquepath): + f=open(recquepath,"r") + line = unicode(f.readline(),'utf-8') + title="" + opts="" + chtxt="" + while line: + linec=line.split(",") + if len(linec)>3: + if linec[0]=="99": + title=linec[4] + opts=linec[5] + chtxt=linec[2]+u"_"+linec[3] + break + line = unicode(f.readline(),'utf-8') + dbkey="" + if opts.find("R")>-1: + dbkey=recdblist.REC_TS_DECODE_QUE + opts=opts.replace("R","") + elif opts.find("D")>-1: + dbkey=recdblist.REC_ENCODE_QUE + opts=opts.replace("D","") + elif opts.find("E")>-1: + dbkey="" + opts=opts.replace("E","") + + bt=datetime.datetime.now()+datetime.timedelta(minutes=5) + et=bt+datetime.timedelta(minutes=30) + btime=bt.strftime("%Y-%m-%d %H:%M:%S") + etime=et.strftime("%Y-%m-%d %H:%M:%S") + if len(dbkey)>2: + recdb.reserveReckey(dbkey, title, chtxt, btime, etime, opts) +def searchRecQue(folderpath): + for file in glob.glob(os.path.join(folderpath,"*.recq")): + dtime = time.time()-os.path.getmtime(file) + dtime = int(dtime) + if dtime > 300: + try: + readRecQue(os.path.join(folderpath, file)) + os.remove(os.path.join(folderpath, file)) + except Exception, inst: + recdblist.addCommonlogEX("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) + diff --git a/rec10/scan_ch.py b/rec10/scan_ch.py new file mode 100644 index 0000000..d7b5380 --- /dev/null +++ b/rec10/scan_ch.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +import os +import os.path +import time +import commands +import traceback +import datetime + +import chdb +import rec10d +import configreader +import recdblist +import tv2ts +tmppath = configreader.getConfPath("tmp")+"/" +if not os.path.exists(tmppath): + os.mkdir(tmppath) +tssplitterp =configreader.getConfPath("java")+" -jar "+configreader.getConfPath("jTsSplitter") +def searchCh(): + if rec10d.rec10db.select_installed_in_status()<2: + rec10d.rec10db.change_installed_in_status(2) + #地上デジタル + for i in xrange(13,52):#62 + recdblist.printutf8ex(u"チャンネルスキャン:地上デジタル CH "+str(i), 200, 200) + if checkTs(str(i))>0: + addCh(str(i),u"te"+str(i),str(i)) + time.sleep(1) + #BSデジタル + recdblist.printutf8ex(u"チャンネルスキャン:BSデジタル ", 200, 200) + for i in xrange(100,299):#240 + recdblist.printutf8ex(u"チャンネルスキャン:BSデジタル CH "+str(i), 200, 200) + if checkTs(str(i))>0: + addCh(str(i),u"bs","BS") + for i2 in xrange(0,11): + chi=u"BS"+str(2*i2+1) + chii=2*i2+1 + recdblist.printutf8ex(u"チャンネルスキャン:BSデジタル CH "+chi, 200, 200) + for ts_offset in xrange(0,4): + for ts_idx in xrange(0,8): + t_tsid=16384+chii*16+ts_offset*512+ts_idx + recdblist.printutf8ex(u"TransportID "+str(t_tsid), 200, 200) + if checkTs(chi,str(t_tsid))>0: + addCh(str(chi),u"bs","BS",str(t_tsid)) + time.sleep(1) + #スカパーe2! + #http://www5e.biglobe.ne.jp/~kazu_f/digital-sat/trapon-nsat110.html + # + #CS1ネットワーク + if checkTs("CS2")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS2 ", 200, 200) + addCh("CS2","cs1","CS") + if checkTs("CS8")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS8", 200, 200) + addCh("CS8","cs1","CS") + if checkTs("CS10")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS10", 200, 200) + addCh("CS10","cs1","CS") + #CS2ネットワーク + if checkTs("CS4")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS4", 200, 200) + addCh("CS4","cs2","CS") + if checkTs("CS6")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS6", 200, 200) + addCh("CS6","cs2","CS") + if checkTs("CS12")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS12", 200, 200) + addCh("CS12","cs2","CS") + if checkTs("CS14")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS14", 200, 200) + addCh("CS14","cs2","CS") + if checkTs("CS16")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS16", 200, 200) + addCh("CS16","cs2","CS") + if checkTs("CS18")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS18", 200, 200) + addCh("CS18","cs2","CS") + if checkTs("CS20")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS20", 200, 200) + addCh("CS20","cs2","CS") + if checkTs("CS22")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS22", 200, 200) + addCh("CS22","cs2","CS") + if checkTs("CS24")>0: + recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS24", 200, 200) + addCh("CS24","cs2","CS") + rec10d.rec10db.change_installed_in_status(100) +def checkTs(ch,tsid="0"): + if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")): + os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts")) + if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25")): + os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25")) + tv2ts.tv2b25ts(os.path.join(tmppath,"ch_"+str(ch)+".ts"), ch, "1",tsid) + if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25")): + os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25")) + if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")): + os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts")) + return 1 + else: + return 0 + +def addCh(ch,bctype,chtxthead,tsid="0"): + prglist=getChProgNum(ch,tsid)##[prglist,logt] + for lstr in prglist[0]: + #print [bctype,chtxthead+"_"+lstr, ch, lstr] + try: + if int(lstr)<1000000: + if ch.find("bs")>-1: + if int(lstr)<300: + tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr,tsid, u"2010-01-01 00:00:00", u"2010-01-01 00:00:00",tnow) + else: + tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr,tsid, u"2010-01-01 00:00:00", u"2010-01-01 00:00:00",tnow) + except Exception, inst: + recdblist.addCommonlogEX("Warning", "addCh (scan_ch.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + checkB25Purchased(ch, prglist[1]) +def getChProgNum(ch,tsid): + pout=os.path.join(tmppath,"ch_"+str(ch)+".ts") + if tsid != "0": + pout=os.path.join(tmppath,"ch_"+str(ch)+"_"+tsid+".ts") + logt=tv2ts.tv2tsmix(pout, ch, "10",tsid) + retl=getTsProgNum(ch,pout) + try: + os.remove(pout) + except: + "" + return [retl,logt] +def getTsProgNum(ch,tspath): + pin=tspath + pout=os.path.join(tmppath,"chscan.txt") + chopt="-ch" + if ch.find("CS")>-1 or ch.find("BS")>-1 : + chopt="-cs" + elif int(ch)>99: + chopt="-bs" + doexe = tssplitterp + " "+chopt+" \""+ pin + "\" \""+ pout + "\"" + doexe = "nice -n 18 " + doexe + os.environ['LANG']="ja_JP.UTF-8" + os.system(u"touch \""+pout+"\"") + txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8','ignore') + f=open(pout) + lines=f.readlines() + f.close() + ret=[] + for l in lines: + try: + l=l.replace(" ","") + l=l.replace("\n","") + ret.append(str(int(l))) + except: + "" + recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド") + recdblist.addLog(pin, txt, u"TsSplitログ-詳細") + time.sleep(1) + try: + "" + os.remove(pout) + except: + "" + return ret +def getB25UnparchasedList(logtxt): + warning = 0 + ret=[] + for strt in logtxt.splitlines(): + if strt.find("unpurchased ECM")>-1: + warning=1 + if strt.find("total TS packet")>-1 and warning>0: + warning=0 + if strt.find("channel")>-1 and warning>0: + txt=strt.replace("channel:","") + txt=txt.replace("\n","") + txt=txt.replace(" ","") + ret.append(txt) + return ret +def checkB25Purchased(ch,logtxt): + chlists=chdb.searchAllCHFromCh(ch) + upl=getB25UnparchasedList(logtxt) + if len(upl)>0 and len(chlists)>0: + for chl in chlists: + if chl != None: + if chl['csch'] in upl: + chdb.changeCHShow(chl['chtxt'],"0") diff --git a/rec10/status.py b/rec10/status.py new file mode 100755 index 0000000..9353900 --- /dev/null +++ b/rec10/status.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import configreader +import os +import rec10d +path = os.path.dirname(os.path.abspath(__file__)) + "/" +def changeEncoding(i): + """ + iはint 増減 + """ + rec10d.rec10db.change_ts2avi_in_status(i) +def changeTERecording(i): + rec10d.rec10db.change_terec_in_status(i) +def changeBSCSRecording(i): + rec10d.rec10db.change_bscsrec_in_status(i) +def changeB25Decoding(i): + rec10d.rec10db.change_b252ts_in_status(i) +def getEncoding(): + """ + エンコードしている数を帰すint型 + """ + return int(rec10d.rec10db.select_all_in_status()[0][0]) +def getTERecording(): + return int(rec10d.rec10db.select_all_in_status()[0][1]) +def getBSCSRecording(): + return int(rec10d.rec10db.select_all_in_status()[0][2]) +def getB25Decoding(): + return int(rec10d.rec10db.select_all_in_status()[0][3]) +def getSettings_auto_bayes(): + return int(rec10d.rec10db.select_all_in_settings()[0][1]) +def getSettings_auto_jbk(): + return int(rec10d.rec10db.select_all_in_settings()[0][0]) +def getSettings_auto_del_tmp(): + return int(rec10d.rec10db.select_all_in_settings()[0][2]) +def getSettings_auto_opt(): + return rec10d.rec10db.select_all_in_settings()[0][3] + +def getRecordingMax(): + return [int(configreader.getConfEnv("te_max")),int(configreader.getConfEnv("bscs_max"))] diff --git a/rec10/tester.py b/rec10/tester.py new file mode 100644 index 0000000..ba59001 --- /dev/null +++ b/rec10/tester.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import sys +#import epgdb +#import tv2ts +import os +#import time +#import tv2avi +#import tv2mkv +#import checker +#import guess +#import auto_process +#import install +#import datetime +#import rec10d +import scan_ch +#import os +#import time +#import n_gram +#import profile +#import epgdb +#import recdblist +#import status +#import chdb +#import checker +#import configreader +#import classify +#import epgdb +#import rec10d +#import recdb +#import tv2mkv +#import tv2avi +#import xml2db +#import guess +#import zenhan +#import auto_process +#import chdb +##import epgdb +#import datetime +#import tv2mp4 +#import ts2x264 +#import recque +import recording_earth_pt1 +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +recpath = "/home/ftpusr/ftp-tmp/Recording/" +ftpusr = "/home/ftpusr/ftp-tmp" +recordedpath = u"/home/ftpusr/ftp-video" +if __name__ == "__main__": + #rec10d.rec10db.update_db_100to101() + #recque.searchRecQue(recpath) + #print chdb.updateLogo() + #epgdb.updateLogo_bc("bs") + #print ts2x264.getX264CoreVersion() + #auto_process.killDeadEncode(recpath) + #print "12" + #print recording_earth_pt1.channel2freq("12") + print "BS2" + print recording_earth_pt1.channel2freq("BS2") + print "CS6" + print recording_earth_pt1.channel2freq("CS6") + scan_ch.searchCh() + "" diff --git a/rec10/timerec.py b/rec10/timerec.py new file mode 100644 index 0000000..fd5068f --- /dev/null +++ b/rec10/timerec.py @@ -0,0 +1,767 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +import datetime +import os +import os.path +import re +import sys +import time +import shutil +import traceback + +import auto_rec +import auto_process +import chdb +import configreader +import epgdb +import rec10d +import recdb +import status +import tv2audio +import tv2avi +import tv2mkv +import tv2mp4 +import install +import recdblist +import recque +recpath = configreader.getConfPath('recpath') +movepath = configreader.getConfPath('move_destpath') +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +def task(): + """ + 数分毎に実行されるタスク処理 + 予定によって子プロセスを生成し処理する。 + """ + try: + if rec10d.rec10db.select_installed_in_status()==0 or rec10d.rec10db.select_version_in_status()<recdblist.version: + install.install() + elif rec10d.rec10db.select_installed_in_status()==1: + import scan_ch + rec10d.rec10db.new_epg_ch() + scan_ch.searchCh() + rec10d.rec10db.change_installed_in_status(100) + elif rec10d.rec10db.select_installed_in_status()==2: + recdblist.printutf8ex("Exit because CH scanning.", 200, 200) + sys.exit(0) + except Exception, inst: + recdblist.addCommonlogEX("Error", "install_check(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + #install.install() + recdb.deleteOldProgramBeforeTheseHours("24") + recdb.delete_old_auto_bayes("1") + recdb.delete_old_auto_keyword("1") + tasks = recdb.getProgramsInTheseHours("3") + inum = recdb.countRecNow_minutes("10") + recdblist.printutf8(u"rec10処理開始"+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),verbose_level=800) + recdblist.printutf8(u"直近録画予約件数:" + str(inum) + u"BS/CS録画中件数:" + str(status.getBSCSRecording()) + u"TE録画中件数:" + str(status.getTERecording()) ,verbose_level=800) + encodenum=0 + b25num=0 + dnow=datetime.datetime.now() + if dnow.minute % 10 < 5: + pid = os.fork() + if pid != 0: + "" + else: + search_keyword(recdb.getAllJbkKeyword()) + recque.searchRecQue(recpath) + sys.exit() + else: + pid = os.fork() + if pid!=0: + "" + else: + time.sleep(10) + auto_process.autoCheck(recpath) + time.sleep(10) + auto_process.killDeadEncode(recpath) + sys.exit() + update = chdb.update() + updatelogo = chdb.updateLogo() + updatelogo=[] + if len(update) > 0: + pid = os.fork() + if pid != 0: + "" + else: + i = 0 + for bctype in update: + recnum = 0 + if bctype.find('te') > -1: + recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("10") + recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10")),verbose_level=800) + recnum = int(configreader.getConfEnv("te_max")) -recnum + else: + recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("10") + recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10")),verbose_level=800) + recnum = int(configreader.getConfEnv("bscs_max")) -recnum + if recnum >0 : + recdblist.printutf8(str(update),verbose_level=750) + rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "0") + epgdb.updatebc(bctype) + update = chdb.update() + i = i + 1 + if i > 0: + break + time.sleep(5) + auto_process.update_all_timeline_epg() + sys.exit() + elif len(updatelogo)>0: + pid = os.fork() + if pid != 0: + "" + else: + i = 0 + for bctype in updatelogo: + recnum = 0 + if bctype.find('te') > -1: + recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("1200") + recdblist.printutf8(u"ロゴ未取得 : 放送種別-"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10")),verbose_level=800) + recnum = int(configreader.getConfEnv("te_max")) -recnum + else: + recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("1200") + recdblist.printutf8(u"ロゴ未取得 : 放送種別-"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10")),verbose_level=800) + recnum = int(configreader.getConfEnv("bscs_max")) -recnum + if recnum >0 : + recdblist.printutf8(u"ロゴ取得"+str(updatelogo),verbose_level=750) + rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"0") + epgdb.updateLogo_bc(bctype) + updatelogo = chdb.updateLogo() + i = i + 1 + if i > 0: + break + time.sleep(5) + sys.exit() + else: + pid = os.fork() + if pid != 0: + "" + else: + auto_process.update_all_timeline_epg() + sys.exit() + for task in tasks: + typetxt = task["type"] + try: + chtxt = task['chtxt'] + except: + chtxt = "" + try: + title = task['title'] + except: + title = "" + try: + btime = task['btime'] + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + except: + btime = "" + bt = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") + try: + etime = task['etime'] + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + except: + etime = "" + et = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") + try: + opt = task['opt'] + except: + opt = "" + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if task["type"] == recdblist.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_reserve(task["type"],chtxt,title,bt,et,opt) + sys.exit() + elif task["type"] == recdblist.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt + deltatime = task['deltatime'] + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_keyword(task["type"],chtxt,title, bt, et, opt, deltatime) + sys.exit() + elif task["type"] == recdblist.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday + deltatime = task['deltatime'] + deltaday = task['deltaday'] + try: + keyeverycounter=task['counter'] + except: + keyeverycounter=-1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_keyword_every_day(task["type"],chtxt, title, bt, et, opt, deltatime, deltaday,keyeverycounter) + sys.exit() + elif task["type"] == recdblist.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_final(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_TS_DECODE_QUE: + b25num=b25num+1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + time.sleep(5*b25num) + type_decode_que(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_ENCODE_QUE: + encodenum=encodenum+1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + time.sleep(5*encodenum) + type_encode_que(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_AVI_TO_MKV: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else: + makeMP4=1 + try: + if configreader.getConfEnv("make_mp4")==0: + makeMP4=0 + except: + "" + if re.search("m", opt): + makeMP4=0 + if re.search("4", opt): + makeMP4=1 + recdb.deleteReckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime) + recdb.reserveReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + if makeMP4==1: + tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) + else: + tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) + tv2mkv.mp42mkv(os.path.join(recpath,title+".mp4"), os.path.join(recpath,title+".mkv")) + os.remove(os.path.join(recpath,title+".mp4")) + recdb.deleteReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + elif task["type"] == recdblist.REC_AVI_TO_MP4: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else: + makeMP4=0 + try: + if configreader.getConfEnv("make_mp4")==1: + makeMP4=1 + except: + "" + if re.search("m", opt): + makeMP4=0 + if re.search("4", opt): + makeMP4=1 + recdb.deleteReckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime) + recdb.reserveReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + if makeMP4==1: + tv2mp4.ts2mp4(pin, pout, opt) + tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) + else: + tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mkv"),opt) + recdb.deleteReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + elif task["type"] == recdblist.REC_MKV_TO_MP4: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else: + recdb.deleteReckey(recdblist.REC_MKV_TO_MP4, title, chtxt, btime) + recdb.reserveReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + tv2mp4.mkv2mp4(os.path.join(recpath,title+".mkv"),os.path.join(recpath,title+".mp4")) + recdb.deleteReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + sys.exit() +def search_keyword(key): + tnow = datetime.datetime.now() + nows =tnow.strftime("%Y-%m-%d %H:%M:%S") + for k,auto,opt in key: + recdatum = epgdb.searchTimeAuto(k,nows, "144") + for recdata in recdatum: + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + btt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + ett = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = btt.strftime("%Y-%m-%d %H:%M:%S") + etimet = ett.strftime("%Y-%m-%d %H:%M:%S") + #if status.getSettings_auto_jbk()==1: + if auto==1 or status.getSettings_auto_jbk()==1: + topt=opt + if topt==None: + topt=status.getSettings_auto_opt() + if len(topt)==0: + topt=status.getSettings_auto_opt() + try: + maxnum=0 + ch=chdb.searchCHFromChtxt(chtxtt) + if len(ch['ch'])>2: + maxnum=epgdb.countSchedule(btimet, etimet)[1] + maxnum=int(configreader.getConfEnv("bscs_max"))-maxnum + else: + maxnum=epgdb.countSchedule(btimet, etimet)[0] + maxnum=int(configreader.getConfEnv("te_max"))-maxnum + if maxnum>0: + if recdb.checkDuplicated(titlet, chtxtt, btimet, etimet)==0: + recdb.reserveReckey(recdblist.REC_RESERVE,titlet,chtxtt, btimet, etimet,topt) + except Exception, inst: + recdblist.addCommonlogEX("Error", "search_keyword_auto_jbk(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + try: + recdb.reserveAutoKeyword(chtxtt, titlet, btimet, etimet) + except Exception, inst: + recdblist.addCommonlogEX("Error", "search_keyword(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) +def type_reserve(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxtfinal="" + if typetxt==recdblist.REC_RESERVE: + typetxtfinal=recdblist.REC_FINAL_RESERVE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if (dt < 58 * 60 and dt > 30 * 60): + bctypet = chdb.searchCHFromChtxt(chtxt)['bctype'] + chdatat = rec10d.rec10db.select_by_bctype_epg_ch(bctypet) + dt1 = bt - datetime.datetime.strptime(chdatat[0][5], "%Y-%m-%d %H:%M:%S") + dt1 = dt1.days * 24 * 60 * 60 + dt1.seconds + if dt1 < 60 * 60: + recdata = epgdb.searchTime(title, btime, "5", chtxt) + chtxtn = recdata[0] + titlen = recdata[1] + btimen = recdata[2] + etimen = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") + btimen = bt.strftime("%Y-%m-%d %H:%M:%S") + etimen = et.strftime("%Y-%m-%d %H:%M:%S") + if chtxt != "": + try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) + recdb.addRecLogProgram(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) + auto_rec.addKey(chtxt, titlen,exp+" "+longexp) + auto_rec.addKey("ALL", titlen,exp+" "+longexp) + recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) + except Exception, inst: + recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + else: + recdblist.printutf8(u"追いかけ機能エラー:番組データが見付かりません。") + else: + if rec10d.rec10db.select_by_bctype_epg_ch(bctypet)[0][6] != "0": + rec10d.rec10db.update_status_by_bctype_epg_ch(bctypet, "3") + sys.exit() + elif (dt <= 30 * 60 and dt > 20 * 60): + recdata = epgdb.searchTime(title, btime, "5", chtxt) + chtxtn = recdata[0] + titlen = recdata[1] + btimen = recdata[2] + etimen = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") + btimen = bt.strftime("%Y-%m-%d %H:%M:%S") + etimen = et.strftime("%Y-%m-%d %H:%M:%S") + if chtxt != "": + try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) + recdb.addRecLogProgram(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) + auto_rec.addKey(chtxt, titlen,exp+" "+longexp) + auto_rec.addKey("ALL", titlen,exp+" "+longexp) + #recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) + recdblist.addCommonlogEX(u"通常", "Oikake (timerec.py)",u"追いかけ機能実行中",u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen,log_level=500) + except Exception, inst: + recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + elif dt <= 20 * 60: + try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtfinal, title, chtxt, btime, etime, opt) + except Exception, inst: + recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) +def type_final(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxting="" + typetxtdecque="" + if typetxt==recdblist.REC_FINAL_RESERVE: + typetxting=recdblist.REC_TS_RECORDING + typetxtdecque=recdblist.REC_TS_DECODE_QUE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if dt < 6 * 60 and dt > 0: + newtitle=title + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + testpath=[os.path.join(recpath,title+".ts.b25")] + testpath.append(os.path.join(recpath,title+".ts")) + testpath.append(os.path.join(recpath,title+".avi")) + testpath.append(os.path.join(recpath,title+".mp4")) + testpath.append(os.path.join(recpath,title+".log")) + tcheck=0 + for ti in testpath: + if os.path.exists(ti): + tcheck=tcheck+1 + if re.search("N", opt) or tcheck>0: + iff="" + try: + iff=u"("+configreader.getConfEnv("iff")+u")_" + except: + iff="" + newtime=bt + newtitle=newtitle+u"_"+iff+newtime.strftime("%Y-%m-%dT%H-%M-%S") + recdb.reserveReckey(typetxting, newtitle, chtxt, btime, etime, opt) + recdblist.addCommonlogEX(u"通常","timerec.py",u"録画開始 "+newtitle+" "+btime+" "+etime,"",log_level=500) + tv2avi.timetv2b25(recpath + "/" + newtitle + ".avi", chtxt, btime, etime, opt) + recdb.deleteReckey(typetxting, newtitle, chtxt, btime) + if not re.search("R", opt): + tnow = datetime.datetime.now() + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + dt = tnow-bt + bt = tnow + datetime.timedelta(seconds=600) + et = et + dt + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtdecque, newtitle, chtxt, btime, etime, opt) + else: + try: + try: + shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".ts.b25"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + except Exception, inst: + recdblist.addCommonlogEX("Error", "Move option(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + recdb.reserveReckey(recdblist.REC_MOVE_END, newtitle, chtxt, btime, etime, opt) + sys.exit() +def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxtres="" + if typetxt==recdblist.REC_KEYWORD: + typetxtres=recdblist.REC_RESERVE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + recdblist.printutf8(str(dt), verbose_level=800) + if dt <= 90 * 60 and dt > 70 * 60: + recdata = epgdb.searchTime(title, btime, deltatime, chtxt) + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = bt.strftime("%Y-%m-%d %H:%M:%S") + etimet = et.strftime("%Y-%m-%d %H:%M:%S") + #try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtres, titlet, chtxt, btimet, etimet, opt) + recdb.addRecLogProgram(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category) + auto_rec.addKey(chtxt, titlet,exp+" "+longexp) + auto_rec.addKey("ALL", titlet,exp+" "+longexp) + recdblist.addCommonlogEX(u"通常","timerec.py",u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet,"",log_level=500) + #except Exception, inst: + # recdblist.printutf8("Error happened in REC_KEYWORD DB") + # recdblist.printutf8(type(inst)) + # recdblist.printutf8(inst) + else: + recdblist.printutf8("nothing match") + elif dt <= 70 * 60: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtres, title, chtxt, btime, etime, opt) + recdblist.addCommonlogEX(u"エラー","timerec.py",u"nothing match","",log_level=200) + recdblist.addCommonlogEX(u"エラー","timerec.py",u"key "+title+u" "+btime+u" "+etime,"",log_level=200) +def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday,counter): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + dd = datetime.timedelta(days=int(deltaday)) + if dtt.days < 0: + recdb.deleteReckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) + bt = bt + dd + et = et + dd + btxt = bt.strftime("%Y-%m-%d %H:%M:%S") + etxt = et.strftime("%Y-%m-%d %H:%M:%S") + if counter>0: + recdb.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday,counter-1) + elif counter==-1: + recdb.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday,-1) + elif dt < 120 * 60: + recdb.deleteReckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) + bt = bt + dd + et = et + dd + btxt = bt.strftime("%Y-%m-%d %H:%M:%S") + etxt = et.strftime("%Y-%m-%d %H:%M:%S") + if counter>0: + recdb.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday,counter-1) + elif counter==-1: + recdb.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday,-1) + recdata = epgdb.searchTime(title, btime, deltatime, chtxt) + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = bt.strftime("%Y-%m-%d %H:%M:%S") + etimet = et.strftime("%Y-%m-%d %H:%M:%S") + #try: + recdb.reserveKeyword(titlet, chtxt, btimet, etimet, deltatime, opt) + else: + recdb.reserveKeyword(title, chtxt, btime, etime, deltatime, opt) +def type_decode_que(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + typetxtnow=typetxt + typetxting="" + typetxtmiss="" + typetxtencque="" + if typetxt== recdblist.REC_TS_DECODE_QUE: + typetxting=recdblist.REC_TS_DECODING + typetxtmiss=recdblist.REC_MISS_DECODE + typetxtencque=recdblist.REC_ENCODE_QUE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if dt < 10 * 60: + if status.getB25Decoding() < 2: + pin = recpath + "/" + title + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxting, title, chtxt, btime, etime, opt) + tv2avi.b252ts(pin, chtxt, btime, etime, opt) + recdb.deleteReckey(typetxting, title, chtxt, btime) + if not os.access(recpath + "/" + title + ".ts", os.F_OK): + recdb.deleteReckey(typetxting, title, chtxt, btime) + recdb.reserveReckey(typetxtmiss, title, chtxt, btime, etime, opt) + else: + auto_process.deleteTmpFile(recpath, title, ".ts") + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + dt = et-bt + if not re.search("D", opt): + tnow = datetime.datetime.now() + bt = tnow + datetime.timedelta(seconds=600) + et = bt + dt + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtencque, title, chtxt, btime, etime, opt) + else: + try: + try: + shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".ts"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + time.sleep(5) + if os.path.getsize(os.path.join(recpath,title+".ts"))==os.path.getsize(os.path.join(movepath,title+".ts")): + os.remove(os.path.join(recpath,title+".ts")) + except Exception, inst: + errtxt1="move ts error.\n" + errtxt2=str(type(inst))+"\n" + errtxt2=errtxt2+str(inst) + recdblist.addCommonlogEX("Error", "type_decode_que(timerec.py)", errtxt1,errtxt2+traceback.format_exc(),log_level=200) + recdb.reserveReckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) + else: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + bt = bt + datetime.timedelta(seconds=600) + et = et + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtnow, title, chtxt, btime, etime, opt) + sys.exit() + +def type_encode_que(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + typetxtnow=typetxt + typetxting="" + typetxtfin="" + if typetxt==recdblist.REC_ENCODE_QUE: + typetxting=recdblist.REC_ENCODE_LOCAL + typetxtfin=recdblist.REC_FIN_LOCAL + if dt < 10 * 60: + if status.getEncoding() < int(configreader.getConfEnv("enc_max")): + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxting, title, chtxt, btime, etime, opt) + recdblist.printutf8(opt) + pin = recpath + "/" + title + ".ts" + if re.search("d", opt): + pin = recpath + "/" + title + ".m2v" + if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: + paac2 = recpath + "/" + title + "_2.aac" + pmp32 = recpath + "/" + title + "_2.mp3" + if not os.path.exists(paac2) and not os.path.exists(pmp32): + tv2audio.ts2dualaudio_BonTsDemux(os.path.join(recpath, title+".ts"),recdblist.BONTSDEMUX_DELAY,opt) + time.sleep(3) + elif re.search("5", opt): + pin = recpath + "/" + title + ".m2v" + if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: + paac2 = recpath + "/" + title + "_2.aac" + pmp32 = recpath + "/" + title + "_2.mp3" + if not os.path.exists(paac2) and not os.path.exists(pmp32): + tv2audio.ts2pentaaudio_BonTsDemux(os.path.join(recpath, title+".ts"), recdblist.BONTSDEMUX_DELAY, opt) + time.sleep(3) + elif re.search("b", opt): + pin = recpath + "/" + title + ".m2v" + if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: + paac2 = recpath + "/" + title + ".aac" + pmp32 = recpath + "/" + title + ".mp3" + if not os.path.exists(paac2) and not os.path.exists(pmp32): + tv2audio.ts2single_fp_BonTsDemux(os.path.join(recpath, title+".ts"),opt) + time.sleep(3) + makeMP4=0 + try: + if configreader.getConfEnv("make_mp4")=="1": + makeMP4=1 + except: + "" + if re.search("m", opt): + makeMP4=0 + if re.search("4", opt): + makeMP4=1 + recdblist.printutf8(pin) + if not re.search("0", opt): + if makeMP4==1: + pout = recpath + "/" + title + ".mp4" + tv2mp4.ts2mp4(pin, pout, opt) + else: + pout = recpath + "/" + title + ".mkv" + tv2mkv.ts2mkv(pin, pout, opt) + if re.search("1", opt) or re.search("2", opt): + optt=opt.replace("1","MW1") + optt=optt.replace("2","MW2") + poutt = recpath + "/" + "m_"+title + ".mp4" + if re.search("d", opt) or re.search("5", opt): + if os.path.exists(os.path.join(recpath, "m_"+title+".m2v")): + shutil.move(os.path.join(recpath, title+".m2v"),os.path.join(recpath, "m_"+title+".m2v")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.aac")): + shutil.move(os.path.join(recpath, title+"_1.aac"),os.path.join(recpath, "m_"+title+"_1.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.mp3")): + shutil.move(os.path.join(recpath, title+"_1.mp3"),os.path.join(recpath, "m_"+title+"_1.mp3")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.aac")): + shutil.move(os.path.join(recpath, title+"_2.aac"),os.path.join(recpath, "m_"+title+"_2.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.mp3")): + shutil.move(os.path.join(recpath, title+"_2.mp3"),os.path.join(recpath, "m_"+title+"_2.mp3")) + shutil.move(os.path.join(recpath, title+".ts"),os.path.join(recpath, "m_"+title+".ts")) + tv2mp4.ts2mp4(os.path.join(recpath, "m_"+title+".ts"), poutt, optt) + shutil.move(os.path.join(recpath, "m_"+title+".ts"),os.path.join(recpath, title+".ts")) + else: + optt=opt + poutt = recpath + "/" + "m_"+title + ".mp4" + shutil.move(os.path.join(recpath, title+".ts"),os.path.join(recpath, "m_"+title+".ts")) + if re.search("d", opt) or re.search("5", opt): + if os.path.exists(os.path.join(recpath, "m_"+title+".m2v")): + shutil.move(os.path.join(recpath, title+".m2v"),os.path.join(recpath, "m_"+title+".m2v")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.aac")): + shutil.move(os.path.join(recpath, title+"_1.aac"),os.path.join(recpath, "m_"+title+"_1.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.mp3")): + shutil.move(os.path.join(recpath, title+"_1.mp3"),os.path.join(recpath, "m_"+title+"_1.mp3")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.aac")): + shutil.move(os.path.join(recpath, title+"_2.aac"),os.path.join(recpath, "m_"+title+"_2.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.mp3")): + shutil.move(os.path.join(recpath, title+"_2.mp3"),os.path.join(recpath, "m_"+title+"_2.mp3")) + tv2mp4.ts2mp4(os.path.join(recpath, "m_"+title+".ts"), poutt, optt) + shutil.move(os.path.join(recpath, "m_"+title+".ts"),os.path.join(recpath, title+".ts")) + recdb.deleteReckey(typetxting, title, chtxt, btime) + time.sleep(10) + if re.search("E", opt): + try: + if os.path.exists(os.path.join(recpath,title+".mp4")): + try: + shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".mp4"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + elif os.path.exists(os.path.join(recpath,title+".mkv")): + try: + shutil.copy(os.path.join(recpath,title+".mkv"), os.path.join(movepath,title+".mkv")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".mkv"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + except Exception, inst: + errtxt1="move mkv/mp4 error." + errtxt2=str(type(inst))+"\n" + errtxt2=errtxt2+str(inst) + recdblist.addCommonlogEX("Error", "type_encode_que(timerec.py)", errtxt1,errtxt2+traceback.format_exc(),log_level=200) + recdb.reserveReckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) + recdb.reserveReckey(typetxtfin, title, chtxt, btime, etime, opt) + sys.exit() + else: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + bt = bt + datetime.timedelta(seconds=600) + et = et + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtnow, title, chtxt, btime, etime, opt) + sys.exit() diff --git a/rec10/ts2epg.py b/rec10/ts2epg.py new file mode 100644 index 0000000..ac01b9b --- /dev/null +++ b/rec10/ts2epg.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +#import sys # モジュール属性 argv を取得するため +import os +import re +import time +import commands + +import chdb +import configreader +import tv2ts +import recdblist + +def writeEpgXML(pout, ch): + """ + tsを取得してepgの入ったxmlとして書き出す + """ + timet = "90" + if re.search(u'CS', ch): + timet = "180" + elif len(ch)>2: + timet = "240" + writeEpgXMLTime(pout, ch ,timet) +def writeLogoEpgXML(pout, ch): + """ + tsを取得してepgの入ったxmlとして書き出す + """ + timet = "600" + if re.search(u'CS', ch): + timet = "10" + elif len(ch)>2: + timet = "1200" + writeEpgXMLTime(pout, ch ,timet,islogo=1) +def writeEpgXMLTime(pout, ch ,times,islogo=0): + """ + 指定された時間分tsを取得してepgの入ったxmlとして書き出す + """ + if islogo==0: + recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG XML書き出し処理開始" ,u"CH:"+ch,log_level=500) + elif islogo==1: + recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG LOGO : XML書き出し処理開始" ,u"CH:"+ch,log_level=500) + timet = times + if re.search(u'CS', ch): + mode = "/CS" + elif len(ch)>2: + mode = "/BS" + else: + mode = str(chdb.searchCHFromBctype(u'te' + ch)['ch']) + epgdump = configreader.getConfPath("epgdump") + if os.access(pout + ".ts", os.F_OK): + os.remove(pout + ".ts") + time.sleep(10) + tv2ts.tv2b25ts(pout+ ".ts", ch, times,"0") + logoopt="" + if islogo==1: + logoopt="/LOGO " + os.chmod(pout+".ts",0755) + exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " +logoopt+ mode + " " + pout + ".ts " + pout + recdblist.printutf8(exe) + recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py) "+str(ch), exe,"",log_level=500) + unicode(commands.getoutput(exe),'utf-8','ignore') + time.sleep(10) + if os.path.exists(pout+".ts"): + os.remove(pout+ ".ts") + diff --git a/rec10/ts2x264.py b/rec10/ts2x264.py new file mode 100644 index 0000000..d47e9aa --- /dev/null +++ b/rec10/ts2x264.py @@ -0,0 +1,556 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import commands +import configreader +import os +import os.path +import sys +import re +import random +import time +import traceback +import zip + +import recdblist +def ts2x264(pin, pout, opts):#sizeは"HD"か"SD" + """ + pinで指定されたファイルをpoutにx264でエンコードして書き出す + """ + dualpass = 0 + is24fps=0 + size="HD" + crf=18 + quality=4 + quality=int(configreader.getConfEnv("x264_preset")) + crf=int(configreader.getConfEnv("crf")) + deinterlace=1 + bluray=0 + sar=1 + if re.search("H", opts): + size = "HD" + if re.search("S", opts): + size = "WVGA" + if re.search("F", opts): + size = "FullHD" + if re.search("W",opts): + size = "WVGA" + if re.search("MW1",opts): + size = "QVGA_BASE" + crf=crf+4 + sar=0 + if re.search("MW2", opts): + size = "WVGA_BASE" + crf=crf+2 + sar=0 + if re.search("v", opts): + is24fps=1 + crf=int(configreader.getConfEnv("animation_crf")) + if re.search("a", opts): + is24fps=1 + crf=int(configreader.getConfEnv("animation_crf")) + if re.search("I", opts): + deinterlace=0 + if re.search("B", opts): + bluray=1 + sar=0 + if re.search("q",opts): + quality=quality-2 + if re.search("w",opts): + quality=quality-1 + if re.search("e",opts): + quality=quality+1 + if re.search("r",opts): + quality=quality+2 + if re.search("u",opts): + crf=crf+2 + if re.search("i",opts): + crf=crf+1 + if re.search("o",opts): + crf=crf-1 + if re.search("p",opts): + crf=crf-2 + if re.search("d",opts):#二カ国語放送の場合 + tm2v=pin.replace(".ts",".m2v") + encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) + elif re.search("5",opts):#5.1chの場合 + encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) + elif re.search("b",opts):#BonTsDemuxを使いたい場合 + tm2v=pin.replace(".ts",".m2v") + encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) + else: + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=1,usebluray=bluray,usesar=sar) + if os.path.exists(pout): + if not os.path.getsize(pout)>1*1000: + recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200) + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar) + except Exception, inst: + recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) + else: + recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200) + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar) + except Exception, inst: + recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) + except Exception, inst: + recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) +def encodeMencoderSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,uselavf=0,usebluray=0,usesar=1): + mencoder=configreader.getConfPath("mencoder") + tee=configreader.getConfPath("tee") + encvf="" + txt="" + encvf="-sws 9 -vf yadif=0,pp=l5" + harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" + ofps="-ofps 30000/1001" + fps="-fps 30000/1001" + x264fps="30000/1001 --keyint 30" + x264streamsize="" + x264preset="" + x264tune="" + x264_bitrate="5000" + x264interlaced=0 + x264sar="1:1" + tsar=getMoviePAR2(pin) + if usesar==1: + x264sar=str(tsar[0])+u":"+str(tsar[1]) + lavft="" + if is24fps==1: + ofps="-ofps 24000/1001" + fps="-fps 30000/1001" + x264fps="24000/1001 --keyint 24" + x264tune="--tune animation" + encvf="-sws 9 -vf pullup,softskip" + harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup" + if size == "HD": + tsize=getParSize(pin,720) + if usesar==1: + encvf = encvf + ",scale=-3:720::0:3"+harddup + x264streamsize=str(tsize[0])+u"x720" + else: + encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup + x264streamsize=u"1280x720" + x264_bitrate="2500" + elif size == "WVGA": + tsize=getParSize(pin,480) + if usesar==1: + encvf = encvf + ",scale=-3:480::0:3"+harddup + x264streamsize=str(tsize[0])+u"x480" + else: + encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup + x264streamsize=u"854x480" + x264_bitrate="1500" + elif size == "FullHD": + tsize=getParSize(pin,1080) + if usesar==1: + encvf = encvf + ",scale=-3:1080::0:3"+harddup + x264streamsize=str(tsize[0])+u"x1080" + else: + encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup + x264streamsize=u"1920x1080" + x264_bitrate="5000" + elif size == "QVGA_BASE": + tsize=getParSize(pin,240) + if usesar==1: + encvf = encvf + ",scale=-3:240::0:3"+harddup + x264streamsize=str(tsize[0])+u"x240" + else: + encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup + x264streamsize=u"320x240" + x264_bitrate="300" + elif size == "WVGA_BASE": + tsize=getParSize(pin,480) + if usesar==1: + encvf = encvf + ",scale=-3:480::0:3"+harddup + x264streamsize=str(tsize[0])+u"x480" + else: + encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup + x264streamsize=u"854x480" + x264_bitrate="1500" + else: + tsize=getParSize(pin,720) + if usesar==1: + encvf = encvf + ",scale=-3:720::0:3"+harddup + x264streamsize=str(tsize[0])+u"x720" + else: + encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup + x264streamsize=u"1280x720" + x264_bitrate="2500" + if deinterlace==0: + tsize=getMovieBaseSize2(pin) + ofps="-ofps 30000/1001" + #fps="-fps 30000/1001" + fps="" + x264fps="30000/1001 --keyint 30" + x264interlaced=1 + encvf="-vf hqdn3d=2:1:2" + harddup=",harddup" + encvf=encvf+harddup + x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) + if usebluray==1: + encvf = u"-sws 9 "+encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup + x264streamsize=u"1920x1080" + if tsize[0] <= 0 or tsize[1] <= 0: + encvf="-sws 9 -vf yadif=0,pp=l5" + harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" + ofps="-ofps 30000/1001" + fps="-fps 30000/1001" + x264fps="30000/1001 --keyint 30" + tsize=[1280,720] + encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup + x264streamsize=u"1280x720" + x264_bitrate="2500" + if quality==1: + x264preset=u"ultrafast" + elif quality==2: + x264preset=u"veryfast" + elif quality==3: + x264preset=u"fast" + elif quality==4: + x264preset=u"medium" + elif quality==5: + x264preset=u"slow" + elif quality==6: + x264preset=u"slower" + else: + x264preset=u"medium" + if size == "WVGA_BASE" or size == "QVGA_BASE": + x264profile=" --level 32 --profile baseline " + else: + x264profile=" --level 41 --profile high " + if uselavf==1: + lavft="-demuxer lavf " + x264crf=str(crf) + os.environ['LANG']="ja_JP.UTF-8" + random.seed(pin) + random.jumpahead(10) + temptime=int(time.time()) + temptime=temptime % 9697 + random.jumpahead(temptime) + streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999))) + unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore') + logmencoder=recdblist.getLogTitle(pin)+".mencoder.log" + logx264=recdblist.getLogTitle(pin)+".x264.log" + encexe=mencoder+u" \""+pin+u"\" -quiet -vfm ffmpeg "+lavft+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" 2>&1 | "+tee+" \""+logmencoder+"\" & " + encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray) + #encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize + encexe=u"nice -n 19 " +encexe+" 2>&1 | "+tee+" \""+logx264+"\"" + try: + recdblist.addCommandSelfLog(pin, encexe) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) + recdblist.printutf8(encexe) + txt="" + try: + txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore') + except: + "" + os.remove(streampath) + zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip") + zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip") + os.remove(logmencoder) + os.remove(logx264) + recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) +# recdblist.addCommandLogTar(pin,u"Mencoder","mencoder", encexe,txt) +def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,usebluray=0,usesar=1): + """ + + """ + ffmpeg=configreader.getConfPath("ffmpeg") + tee=configreader.getConfPath("tee") + fps=u"-r 29.970030 " + x264fps="30000/1001 --keyint 30" + x264streamsize="" + x264preset="" + x264tune="" + x264_bitrate="2500" + x264_thread="auto" + x264interlaced=0 + tsar=getMoviePAR2(pin) + filter="-deinterlace" + x264sar=str(tsar[0])+":"+str(tsar[1]) + if is24fps==1: + fps=u"-r 23.976023 " + x264fps="24000/1001 --keyint 24" + x264tune="--tune animation" + if size == "HD": + tsize=getParSize(pin,720) + s = "-s "+str(tsize[0])+"x720 " + x264streamsize=str(tsize[0])+u"x720" + x264_bitrate="2500" + elif size == "WVGA": + tsize=getParSize(pin,480) + s = "-s "+str(tsize[0])+"x480 " + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1500" + elif size == "FullHD": + tsize=getParSize(pin,1080) + s = "-s "+str(tsize[0])+"x1080 " + x264streamsize=str(tsize[0])+u"x1080" + x264_bitrate="5000" + elif size == "SD": + tsize=getParSize(pin,480) + s = "-s "+str(tsize[0])+"x480 " + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1250" + elif size == "QVGA_BASE": + tsize=getParSize(pin,240) + s = "-s "+str(tsize[0])+"x240 " + x264streamsize=str(tsize[0])+u"x240" + x264_bitrate="300" + elif size == "WVGA_BASE": + tsize=getParSize(pin,480) + s = "-s "+str(tsize[0])+"x480 " + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1500" + else: + tsize=getParSize(pin,720) + s = "-s "+str(tsize[0])+"x720 " + x264streamsize=str(tsize[0])+u"x720" + x264_bitrate="2500" + if deinterlace==0: + tsize=getMovieBaseSize2(pin) + fps="" + s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" " + x264fps="30000/1001 --keyint 30" + x264interlaced=1 + filter="" + x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) + if quality==1: + x264preset=u"ultrafast" + elif quality==2: + x264preset=u"veryfast" + elif quality==3: + x264preset=u"fast" + elif quality==4: + x264preset=u"medium" + elif quality==5: + x264preset=u"slow" + elif quality==6: + x264preset=u"slower" + else: + x264preset=u"medium" + if size == "WVGA_BASE" or size == "QVGA_BASE": + x264profile=" --level 32 --profile baseline " + else: + x264profile=" --level 41 --profile high " + x264crf=str(crf) + txt="" + os.environ['LANG']="ja_JP.UTF-8" + log_ffmpeg=recdblist.getLogTitle(pin)+".ffmpeg.log" + log_x264=recdblist.getLogTitle(pin)+".x264.log" + exe=ffmpeg+u" -y -i \""+pin+"\" -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - 2> \""+log_ffmpeg+"\" | " + exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray) + exe = "nice -n 19 " + exe+" 2>&1 | "+tee+" \""+log_x264+"\"" + txt="" + #recdblist.addCommandSelfLog(log_ffmpeg,recdblist.getLogTitle(pin)+".log.zip") + #recdblist.addCommandSelfLog(log_x264,recdblist.getLogTitle(pin)+".log.zip") + recdblist.printutf8(exe) + recdblist.addCommandSelfLog(pin,exe) + try: + txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + except: + "" + recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) + zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip")) + zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip")) + os.remove(log_ffmpeg) + os.remove(log_x264) +def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処 + ffmpeg=configreader.getConfPath("ffmpeg") + os.environ['LANG']="ja_JP.UTF-8" + exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1" + try: + recdblist.addCommandSelfLog(pin, exe) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") + rT2=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + sizeMaxY=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.search(t) + rM2=rT2.search(t) + if rM: + sizetxt=rM.group(1) + partxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(partxt.split(":")[0]) + tEY=int(partxt.split(":")[1]) + if sizeMaxX<tX: + sizeMaxX=tX + sizeMaxY=tY + if rM2: + sizetxt=rM2.group(1) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + if sizeMaxX<tX: + sizeMaxX=tX + sizeMaxY=tY + os.remove(pin+".size.ts") + return [sizeMaxX,sizeMaxY] +def getMoviePAR2(pin): + ffmpeg=configreader.getConfPath("ffmpeg") + os.environ['LANG']="ja_JP.UTF-8" + exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1" + try: + recdblist.addCommandSelfLog(pin, exe) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) + txts = unicode(commands.getoutput(exe.encode('utf-8')), 'utf-8', 'ignore') + rT = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") + rT2 = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX = 0 + parx = 0 + pary = 0 + txtls = txts.split("\n") + for t in txtls: + rM = rT.match(t) + rM2 = rT2.match(t) + if rM: + sizetxt = rM.group(1) + dartxt = rM.group(2) + tX = int(sizetxt.split("x")[0]) + tY = int(sizetxt.split("x")[1]) + tEX = int(dartxt.split(":")[0]) + tEY = int(dartxt.split(":")[1]) + if sizeMaxX < tX: + sizeMaxX = tX + if tX == 1920 and tY == 1080: + parx = 1 + pary = 1 + else: + parx = tEX + pary = tEY + rM = rT.match(t) + if rM2: + sizetxt = rM2.group(1) + sartxt = rM2.group(2) + dartxt = rM2.group(3) + tX = int(sizetxt.split("x")[0]) + tY = int(sizetxt.split("x")[1]) + tEX = int(dartxt.split(":")[0]) + tEY = int(dartxt.split(":")[1])##dar=sarxpar + tSX = int(sartxt.split(":")[0]) + tSY = int(sartxt.split(":")[1])##par=dar/sar= darx*pary*sary=dary*parx*sarx + if sizeMaxX < tX: + sizeMaxX = tX + if tX == 1920 and tY == 1080: + parx = 1 + pary = 1 + else: + if tEX * tSY == tEY * tSX: + parx = 1 + pary = 1 + elif tEX * tSY * 3 == tEY * tSX * 4: + parx = 4 + pary = 3 + elif tEX * tSY * 4 == tEY * tSX * 3: + parx = 3 + pary = 4 + elif tEX * tSY * 9 == tEY * tSX * 16: + parx = 16 + pary = 9 + elif tEX * tSY * 16 == tEY * tSX * 9: + parx = 9 + pary = 16 + os.remove(pin+".size.ts") + return [parx,pary] +def getParSize(pin,y): + tSize=getMovieBaseSize2(pin) + if tSize[1] != 0 : + tX=tSize[0]*10*y/tSize[1] + tY=y + if tX>int(tX/10)*10: + tX=tX/10+1 + else: + tX=tX/10 + else: + tX=-1 + tY=-1 + return [tX,tY] +def getX264CoreVersion(): + x264=configreader.getConfPath("x264") + #print x264 + t1=commands.getoutput(x264+" --help|grep core") + #print t1 + rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z") + rM=rT.match(t1) + v=-1 + if rM: + v=int(rM.group(1)) + return v +def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0,interlaced=0,bluray=0): + x264=configreader.getConfPath("x264") + os.environ['LANG']="ja_JP.UTF-8" + x264_sar="--sar "+sar + x264preset=u"--preset "+preset + x264fps="--fps "+fps + x264interlaced="" + x264bluray="" + x264_addline=configreader.getConfEnv("x264_addline") + if crf==-1: + x264bitrate=u"--bitrate "+str(bitrate) + else: + x264crf=u"--crf "+str(crf) + if interlaced==1: + x264interlaced="--tff --nal-hrd vbr" + if bluray==1: + if getX264CoreVersion()<115: + x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 " + x264_addline="" + if fps=="24000/1001 --keyint 24" or fps =="24000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 "+x264bluray + if x264streamsize=="1920x1080": + x264bluray=u"--ref 4 "+x264bluray + elif fps=="30000/1001 --keyint 30" or fps =="30000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 --pulldown double "+x264bluray + if x264streamsize=="1920x1080": + if interlaced==0: + x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray + else: + x264bluray=u"--ref 4 "+x264bluray + elif getX264CoreVersion()>=115: + x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 " + x264_addline="" + if fps=="24000/1001 --keyint 24" or fps =="24000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 "+x264bluray + if x264streamsize=="1920x1080": + x264bluray=u"--ref 4 "+x264bluray + elif fps=="30000/1001 --keyint 30" or fps =="30000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 --pulldown double "+x264bluray + if x264streamsize=="1920x1080": + if interlaced==0: + x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray + else: + x264bluray=u"--ref 4 "+x264bluray + x264_thread="auto" + try: + xtt=configreader.getConfEnv("x264_thread") + xtt=int(xtt) + if xtt>0: + x264_thread=str(xtt) + except: + x264_thread="auto" + x264_addline=configreader.getConfEnv("x264_addline") + if getX264CoreVersion()>103: + x264res=u"--input-res "+x264streamsize + exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin + else: + exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize + return exe diff --git a/rec10/tv2audio.py b/rec10/tv2audio.py new file mode 100644 index 0000000..a554451 --- /dev/null +++ b/rec10/tv2audio.py @@ -0,0 +1,286 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import commands +import os +import re +import shutil +import time +import os.path +import subprocess +import signal + +import configreader +import recdblist + +def wav2aac_nero(pin,pout): + os.environ['LANG']="ja_JP.UTF-8" + neroaac=configreader.getConfPath('NeroAAC') + exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\"" + try: + txt=commands.getoutput(exe.encode('utf-8')) + recdblist.addLog(pin, exe, u"Wav2aac_Neroログ-コマンド") + recdblist.addLog(pin, txt, u"Wav2aac_Neroログ-詳細") + except: + if not os.path.exists(pout): + lame="lame" + exe=lame+" -b 128 \""+pin+"\" \""+pout+"\"" + txt=commands.getoutput(exe.encode('utf-8')) + recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド") + recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細") +def wav2mp3_lame(pin,pout): + os.environ['LANG']="ja_JP.UTF-8" + lame=configreader.getConfPath('lame') + exe=lame+" -b 128 \""+pin+"\" \""+pout+"\"" + try: + txt=commands.getoutput(exe.encode('utf-8')) + except: + "" + recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド") + recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細") +def ts2single_audio(pts,opts): + paac=pts.replace(".ts",".aac") + ffmpeg=configreader.getConfPath("ffmpeg") + e0=ffmpeg+" -i \""+pts+"\" -y -vn -acodec copy \""+paac+"\"" + p0=subprocess.Popen(e0,shell=True) + os.waitpid(p0.pid, 0) + if p0.poll==None:#実行中 + if os.path.exists(paac): + if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + os.kill(p0.pid,signal.SIGKILL) + os.remove(paac) + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) + else: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + else: + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + try: + os.kill(p0.pid,signal.SIGKILL) + except: + "" + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) + else: + if os.path.exists(paac): + if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + os.remove(paac) + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) + else: + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + else: + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) +def ts2singlewav(pts,opts): + bontsdemux = configreader.getConfPath('bontsdemux') + bonpin = "Z:\\" + pts[1:] + outf = os.path.splitext(pts)[0] + bonpout = "Z:\\" + outf[1:] + delayt="" + exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" "+delayt+" -nd -sound 0 -o \"" + bonpout + "\"" + #recdblist.printutf8(exe) + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + recdblist.addCommandLog(pts, u"BonTsDemux 音声取り出し", exe, txt) +def ts2single_mp3_ffmpeg(pts): + pmp3=pts.replace(".ts",".mp3") + ffmpeg=configreader.getConfPath("ffmpeg") + e0=ffmpeg+" -i \""+pts+"\" -y -vn -ab 128k \""+pmp3+"\"" + p0=subprocess.Popen(e0,shell=True) + os.waitpid(p0.pid, 0) + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg_mp3音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg_mp3音声取り出しログ-詳細") + except: + "" +def ts2single_aac_ffmpeg(pts): + ts2singlewav(pts,opts) + aout=pts.replace(".ts",".aac") + ain=pts.replace(".ts",".wav") + wav2aac_ffmpeg(ain,aout) +def wav2aac_ffmpeg(pin,pout): + paac=pts.replace(".ts",".aac") + ffmpeg=configreader.getConfPath("ffmpeg") + e0=ffmpeg+" -i \""+pin+"\" -y \""+pout+"\"" + p0=subprocess.Popen(e0,shell=True) + os.waitpid(p0.pid, 0) + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg_wav2aac音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg_wav2aac音声取り出しログ-詳細") + except: + "" +def ts2single_fp_BonTsDemux(pts,opts): + useNero=0 + try: + if configreader.getConfPath("useNeroAAC")=="1" and os.path.exists(configreader.getConfPath("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ts2single_aac_BonTsDemux_Nero(pts,opts) + else: + ts2single_aac_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".aac")): + ts2single_mp3_BonTsDemux(pts,opts) +def ts2single_aac_BonTsDemux_Nero(pts,opts): + ts2singlewav(pts,opts) + aout=pts.replace(".ts",".aac") + ain=pts.replace(".ts",".wav") + wav2aac_nero(ain,aout) +def ts2single_mp3_BonTsDemux(pts,opts): + ts2singlewav(pts,opts) + aout=pts.replace(".ts",".mp3") + ain=pts.replace(".ts",".wav") + wav2mp3_lame(ain,aout) +def ts2dualaudio_BonTsDemux(pin, delay,opts): + """ + delay is string + """ + bontsdemux = configreader.getConfPath('bontsdemux') + wine = configreader.getConfPath('wine') + bonpin = "Z:\\" + pin[1:] + outf = os.path.splitext(pin)[0] + bonpout = "Z:\\" + outf[1:] + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux 第一音声取り出し", exe, txt) + except: + "" + ffpin = pin.replace(".ts", "") + ffpin1 = pin.replace("ts", "wav") + ffpin2 = pin.replace("ts", "m2v") + ffpout1 = ffpin + "_1.wav" + ffpout2 = ffpin + "_2.wav" + ffpout3 = ffpin + ".m2v" + shutil.move(ffpin1, ffpout1) + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux 第二音声取り出し", exe, txt) + except: + "" + #os.system(exe) + shutil.move(ffpin1, ffpout2) + shutil.move(ffpin2, ffpout3) + ffpout21=ffpout1.replace(".wav",".mp3") + ffpout22=ffpout2.replace(".wav",".mp3") + useNero=0 + try: + if os.path.exists(configreader.getConfPath("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ffpout21=ffpout1.replace(".wav",".aac") + ffpout22=ffpout2.replace(".wav",".aac") + wav2aac_nero(ffpout1, ffpout21) + wav2aac_nero(ffpout2, ffpout22) + else: + wav2mp3_lame(ffpout1, ffpout21) + wav2mp3_lame(ffpout2, ffpout22) + time.sleep(3) + os.remove(ffpout1) + os.remove(ffpout2) +def ts2pentaaudio_BonTsDemux(pin, delay,opts): + bontsdemux = configreader.getConfPath('bontsdemux') + wine = configreader.getConfPath('wine') + bonpin = "Z:\\" + pin[1:] + outf = os.path.splitext(pin)[0] + bonpout = "Z:\\" + outf[1:] + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 3 -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux5.1ch 第一音声取り出し", exe, txt) + except: + "" + ffpin = pin.replace(".ts", "") + ffpin1 = pin.replace("ts", "wav") + ffpin2 = pin.replace("ts", "m2v") + ffpout1 = ffpin + "_1.wav" + ffpout2 = ffpin + "_2.aac" + shutil.move(ffpin1, ffpout1) + exe = "ffmpeg -i '"+pin+"' -vn -f aac -acodec copy '"+ffpout2+"'" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"FFmpeg 5.1ch 第二音声(raw AAC)取り出し", exe, txt) + except: + "" + ffpout21=ffpout1.replace(".wav",".mp3") + useNero=0 + try: + if os.path.exists(configreader.getConfPath("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ffpout21=ffpout1.replace(".wav",".aac") + wav2aac_nero(ffpout1, ffpout21) + else: + wav2mp3_lame(ffpout1, ffpout21) + if not os.path.exists(ffpout21): + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 0 -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux 修正版第二音声(2chDownmix)取り出し", exe, txt) + except: + "" + shutil.move(ffpin1, ffpout1) + if useNero==1: + ffpout21=ffpout1.replace(".wav",".aac") + wav2aac_nero(ffpout1, ffpout21) + else: + wav2mp3_lame(ffpout1, ffpout21) + time.sleep(3) + ffpout21=ffpout1.replace(".wav",".aac") + if os.path.exists(ffpout21): + if os.path.getsize(ffpout21)>10*1000*1000: + os.remove(ffpout1) diff --git a/rec10/tv2avi.py b/rec10/tv2avi.py new file mode 100644 index 0000000..f441bee --- /dev/null +++ b/rec10/tv2avi.py @@ -0,0 +1,111 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import commands +import datetime +import os +import re +import shutil +import time +import os.path +import traceback + +import chdb +import configreader +import status +import ts2x264 +import tv2ts +import recdblist +import tv2audio + + +global Bitrate_SD +global Bitrate_HD +global Bitrate_FHD +global Bitrate_Short +global Bitrate_LowHD +Bitrate_SD = 1250 +Bitrate_HD = 3750 +Bitrate_LowHD = 2500 +Bitrate_FHD = 5000 +Bitrate_Short = 1250 +def timetv2b25(pout, chtxt, btime, etime, opt): + """ + poutはタイトル + """ + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + extt = os.path.splitext(pout) + tsout = extt[0] + tnow = datetime.datetime.now() + wt = bt-tnow + waitt = wt.seconds + if waitt>0: + time.sleep(waitt) + tnow = datetime.datetime.now() + dt = et-tnow + rectime = dt.seconds-5 + rectime = str(rectime) + tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.searchCHFromChtxt(chtxt)['ch'], rectime,chdb.searchCHFromChtxt(chtxt)['tsid']) +def b252ts(pout, chtxt, btime, etime, opt): + """ + poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。) + """ + #status.setB25Decoding(status.getB25Decoding() + 1) + status.changeB25Decoding(1) + try: + try: + chs=chdb.searchCHFromChtxt(chtxt) + ch=chs['ch'] + csch=chs['csch'] + #print [ch,csch,chtxt] + except: + ch="0" + csch="0" + tv2ts.b252ts(pout + ".ts", ch, csch) + tsout = pout + aviin = pout + ".ts" + dualaudio = 0 + pentaaudio = 0 + singleaudiosplit = 0 + if re.search("5", opt): + pentaaudio = 1 + if re.search("d", opt): + dualaudio = 1 + if re.search("b", opt): + singleaudiosplit = 1 + if re.search(u"\[二\]", pout): + dualaudio = 1 + elif re.search(u'(二)', pout): + dualaudio = 1 + elif re.search(u'\(二\)', pout): + dualaudio = 1 + if dualaudio == 1: + tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt) + if pentaaudio == 1: + tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt) + if singleaudiosplit == 1: + tv2audio.ts2single_fp_BonTsDemux(aviin, opt) + except Exception, inst: + recdblist.addCommonlogEX("Error", "b252ts(tv2avi.py)", str(type(inst))+traceback.format_exc(), str(inst)) + status.changeB25Decoding(-1) +def ts2avi(pin, pout, opt): + status.changeEncoding(1) + try: + ts2x264.ts2x264(pin, pout, opt) + except Exception, inst: + recdblist.printutf8("error occures in tv2avi.py ts2avi") + recdblist.printutf8(str(type(inst))) + recdblist.printutf8(str(inst)+traceback.format_exc()) + status.changeEncoding(-1) +def ts2raw(pin, pout, opt): + status.changeEncoding(1) + try: + ts2x264.ts2x264(pin, pout, opt) + except Exception, inst: + recdblist.printutf8("error occures in tv2avi.py ts2raw") + recdblist.printutf8(str(type(inst))) + recdblist.printutf8(str(inst)+traceback.format_exc()) + status.changeEncoding(-1) + diff --git a/rec10/tv2mkv.py b/rec10/tv2mkv.py new file mode 100644 index 0000000..1951a8f --- /dev/null +++ b/rec10/tv2mkv.py @@ -0,0 +1,21 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import os.path +import tv2mp4 +import configreader +import subprocess +import auto_process +def ts2mkv(pin, pout, opt): + tpout=pout.replace(".mkv",".mp4") + tv2mp4.ts2mp4(pin, tpout, opt) + mp42mkv(pout, tpout) + if os.path.exists(pout) and os.path.getsize(pout)>os.path.getsize(tpout)*0.9: + os.remove(tpout) +def mp42mkv(pmkv,pmp4): + exe = configreader.getConfPath("mkvmerge") + e1=exe +" -o \""+pmkv+u"\" \""+pmp4+"\"" + p=subprocess.Popen(e1,shell=True) + os.waitpid(p.pid, 0) diff --git a/rec10/tv2mp4.py b/rec10/tv2mp4.py new file mode 100644 index 0000000..57864bb --- /dev/null +++ b/rec10/tv2mp4.py @@ -0,0 +1,239 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import commands +import shutil +import auto_process +import os +import re +import os.path +import string +import base64 +import time +import subprocess +import traceback +import zip + +import tv2avi +import recdblist +import configreader +import status +import tv2audio +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +if not os.path.exists(tmppath): + os.mkdir(tmppath) +def ts2mp4(pin, pout, opt): + dir=os.path.split(pout)[0] + title=os.path.split(pout)[1] + title=os.path.splitext(title)[0] + tpraw=os.path.join(dir, title+".264") + tpmp4=os.path.join(dir, title+".mp4") + if os.path.isfile(pin) and os.path.getsize(pin)>10*1000: + tv2avi.ts2raw(pin, tpraw, opt) + time.sleep(10) + if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000: + raw2mp4(tpraw, tpmp4, opt) + time.sleep(10) + if os.path.exists(tpraw) and not re.search("B",opt): + os.remove(tpraw) + zip.addFile2FileZip(recdblist.getLogTitle(pin)+".command.log", recdblist.getLogTitle(pin)+".log.zip") + if os.path.exists(recdblist.getLogTitle(pin)+".command.log"): + os.remove(recdblist.getLogTitle(pin)+".command.log") +def raw2mp4(pin,pout,opt): + dir=os.path.split(pout)[0] + title=os.path.split(pout)[1] + title=os.path.splitext(title)[0] + duration="-fps 29.970030 " + if re.search("a",opt): + duration="-fps 23.976023 " + if re.search("I",opt): + duration="-fps 29.970030 " + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath + txt="" + os.environ['LANG']="ja_JP.UTF-8" + pints=pin.replace(".264",".ts") + e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" + execmp4box(pin, pout, e1) + addAudio(pints, pout, opt) + addCaption(pints, pout) + if status.getSettings_auto_del_tmp()==1: + if os.path.exists(pout): + if re.search("t",opt): + auto_process.deleteTmpFile(dir, title, ".264") + elif re.search("k",opt): + ""#削除しない + else: + auto_process.deleteTmpFile(dir, title, ".mp4") +def mkv2mp4(pin,pout): + exeb = configreader.getConfPath(u"mkvextract") + exe = configreader.getConfPath(u"mp4Box") + #dtsedit=configreader.getConfPath("DtsEdit") + wineexe=configreader.getConfPath("wine") + dir=os.path.split(pin)[0] + title=os.path.split(pin)[1] + title=os.path.splitext(title)[0] + etitle=base64.b16encode(title.encode('utf-8')) + audiopath=os.path.join(dir,etitle+u"_audio.aac") + videopath=os.path.join(dir,etitle+u"_video.264") + timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt") + tmpmp4=os.path.join(dir,etitle+u".tmp.mp4") + exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'" + exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'" + exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'" + exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'" + os.environ['LANG']="ja_JP.UTF-8" + txt="" + try: + txt=txt+execcomd(exe0)+"\n" + txt=txt+execcomd(exe1)+"\n" + txt=txt+execcomd(exe2)+"\n" + txt=txt+execcomd(exe3)+"\n" + except: + "" + recdblist.addLog(pin, txt, u"MKV2MP4-log") + txt = "\n####MKV2MP4-log####\n"+txt + time.sleep(10) + if status.getSettings_auto_del_tmp()==1: + if os.path.exists(pout): + auto_process.deleteTmpFile(dir, title, ".mp4") +def addCaption(pts,pmp4):##字幕の追加を試みる。 + wineexe=configreader.getConfPath("wine") + pincap=pts.replace(".ts",".srt") + try: + cap2ass=configreader.getConfPath("caption2ass") + except: + cap2ass="" + if os.path.isfile(cap2ass): + e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pts+"\" \"Z:\\"+pincap+"\"" + recdblist.printutf8(e0) + p0=subprocess.Popen(e0,shell=True,stdout=subprocess.PIPE) + time.sleep(100) + if p0.poll==None:#実行中 + #if os.path.getsize(pincap)<1000:#2mで1kb以下の場合自動で終了 + # os.kill(p0.pid,signal.SIGKILL) + #else: + os.waitpid(p0.pid, 0) + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, u"Captionログ-コマンド") + recdblist.addLog(pts,logt, u"Captionログ-詳細") + recdblist.addCommandLogZip(pts, "mp4box_caption", "mp4box_caption", e0, logt) + if os.path.exists(pincap): + if os.path.getsize(pincap)>1000: + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath + e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\"" + addmp4(pincap,pmp4,e1s) +def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath + if re.search("d",opts) or re.search("5",opts):#二カ国語放送/5.1ch放送の場合 + paac1=pts.replace(".ts","_1.aac") + paac2=pts.replace(".ts","_2.aac") + recdblist.printutf8(paac1) + e1a1=exe +u" -add \""+paac1+"\":mpeg4 \""+pmp4+"\"" + e1a2=exe +u" -add \""+paac2+"\":mpeg4 \""+pmp4+"\"" + if not os.path.exists(paac1): + paac1=pts.replace(".ts","_1.mp3") + e1a1=exe +u" -add \""+paac1+"\" \""+pmp4+"\"" + if not os.path.exists(paac2): + paac2=pts.replace(".ts","_2.mp3") + e1a1=exe +u" -add \""+paac2+"\" \""+pmp4+"\"" + if os.path.exists(paac1): + addmp4(paac1, pmp4, e1a1) + if os.path.exists(paac2): + addmp4(paac2, pmp4, e1a2) + elif re.search("b",opts):#BonTsDemuxを使って音声をスプリットした場合 + paac=pts.replace(".ts",".aac") + e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\"" + if not os.path.exists(paac): + paac=pts.replace(".ts",".mp3") + e1a1=exe +u" -add \""+paac+"\" \""+pmp4+"\"" + if os.path.exists(paac): + addmp4(paac, pmp4, e1a1) + else: + tv2audio.ts2single_audio(pts,opts) + pinaac=pts.replace(".ts",".aac") + e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\"" + if not os.path.exists(pinaac): + pinaac=pinaac.replace(".aac",".mp3") + e1a=exe +u" -add \""+pinaac+"\" \""+pmp4+"\"" + if os.path.exists(pinaac): + addmp4(pinaac, pmp4, e1a) +def execmp4box(pin,pout,cmd): + title=os.path.splitext(os.path.split(pin)[1])[0] + nt=base64.b16encode(title.encode('utf-8')) + if len(nt)>200: + nt=nt[:180] + ptin=os.path.join(os.path.dirname(pin),nt+".264") + recdblist.printutf8(ptin) + shutil.move(pin,ptin) + time.sleep(10) + ptout=os.path.join(os.path.dirname(pout),nt+".mp4") + cmdn=string.replace(cmd,pin,ptin) + cmdn=string.replace(cmdn,pout,ptout) + recdblist.printutf8(cmdn) + recdblist.addCommandSelfLog(pin, cmdn) + txt="" + try: + txt=execcomd(cmdn) + except Exception, inst: + txt= "error occures in execmp4box\n" + txt=txt+ str(type(inst))+"\n" + txt=txt+str(inst) + recdblist.addCommonlogEX("Error", "excecmp4box(tv2mp4.py)", str(type(inst)), str(inst)+traceback.format_exc(),verbose_level=200,log_level=200) + recdblist.addLog(pin, cmdn, u"MP4Boxログ-コマンド") + recdblist.addLog(pin, txt, u"MP4Boxログ-詳細") + recdblist.addCommandLogZip(pin, "MP4Box", "mp4box", cmdn,txt) + time.sleep(5) + shutil.move(ptin,pin) + shutil.move(ptout,pout) + time.sleep(5) +def addmp4(padd,pout,cmd):#without video + title=os.path.splitext(os.path.split(padd)[1])[0] + ext=os.path.splitext(os.path.split(padd)[1])[1] + nt=base64.b16encode(title.encode('utf-8')) + if len(nt)>200: + nt=nt[:180] + ptadd=os.path.join(os.path.dirname(padd),nt+ext) + ptoutb=os.path.join(os.path.dirname(pout),nt+"_b.mp4") + ptout=os.path.join(os.path.dirname(pout),nt+".mp4") + shutil.move(padd,ptadd) + if os.path.isfile(pout): + shutil.move(pout,ptoutb) + time.sleep(5) + cmdn=string.replace(cmd,padd,ptadd) + cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout) + cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout) + cmdn=string.replace(cmdn,pout,ptout) + recdblist.printutf8(cmdn) + txt="" + try: + txt=execcomd(cmdn) + except Exception, inst: + txt= "error occures in addmp4\n" + txt=txt+ str(type(inst))+"\n" + txt=txt+str(inst) + recdblist.addLog(pout, cmdn, u"MP4Box追加ログ-コマンド") + recdblist.addLog(pout, txt, u"MP4Box追加ログ-詳細") + recdblist.addCommandLogZip(pout, "MP4Box_add", "mp4box_add", cmdn, txt) + time.sleep(5) + shutil.move(ptadd,padd) + if os.path.exists(ptout): + shutil.move(ptout,pout) + os.remove(ptoutb) + else: + txtt=padd+u"のインポートエラー" + recdblist.addLog(pout, txtt, u"MP4Box追加ログ-コマンド") + shutil.move(ptoutb,pout) + time.sleep(5) +def execcomd(cmd): + txt="" + try: + txt=u"Cmd : "+cmd+"\n" + txt2=commands.getoutput(cmd.encode('utf-8')) + txt=txt+unicode(txt2,"utf-8")+"\n" + except: + "" + return txt diff --git a/rec10/tv2ts.py b/rec10/tv2ts.py new file mode 100644 index 0000000..bb87965 --- /dev/null +++ b/rec10/tv2ts.py @@ -0,0 +1,138 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +#import sys # モジュール属性 argv を取得するため +import commands +import os +import os.path +import time +import traceback + +import configreader +import status +import recdblist +import recording_earth_pt1 +mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/" +def tv2tsmix(pout, ch, time,tsid="0",getlog=0): + tv2b25ts(pout + ".b25", ch, time,tsid) + txt=b252tsmix(pout + ".b25", pout) + return txt + #if os.access(pout, os.F_OK): + # try: + # os.remove(pout + ".b25") + # except: + # "" +def tv2ts(pout, ch, csch, time,tsid): + if ch.replace(" ","").replace("CS","").isdigit(): + if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上 + status.changeBSCSRecording(1) + else: + status.changeTERecording(1) + try: + tv2b25ts(pout + ".b25", ch, time,tsid) + except Exception, inst: + recdblist.addCommonlogEX(u"Error",u"tv2ts(tv2ts.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上 + status.changeBSCSRecording(-1) + else: + status.changeTERecording(-1) + else: + ch="0" + csch="0" + b252tsmix(pout + ".b25", pout + ".tsmix") + tch="0" + if csch!=u"0": + tch=csch + elif ch==u"101": + tch="101" + elif ch==u"102": + tch="102" + #else: + # tch=ch + tsmix2ts(pout + ".tsmix", pout, tch) + if os.access(pout, os.F_OK): + try: + #os.remove(path + "/" + t + ext) + "" + except: + "" +def b252ts(pout, ch, csch): + b252tsmix(pout + ".b25", pout + ".tsmix") + tch=u"0" + if ch.replace(" ","").replace("CS","").isdigit(): + if csch!=u"0": + tch=csch + elif ch==u"101": + tch=u"101" + elif ch==u"102": + tch=u"102" + else: + tch="0" + tsmix2ts(pout + ".tsmix", pout, tch) +def tv2b25ts(pout, ch, time,tsid): + if recording_earth_pt1.useDVB()==0: + exe = configreader.getConfPath('recpt1') + if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上 + status.changeBSCSRecording(1) + else: + status.changeTERecording(1) + try: + doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\'' + recdblist.printutf8(doexe) + recdblist.addLog(pout, doexe, u"recpt1ログ-コマンド") + recdblist.addLog(pout, unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8'), u"recpt1ログ-詳細") + except Exception, inst: + recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst)) + if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上 + status.changeBSCSRecording(-1) + else: + status.changeTERecording(-1) + elif recording_earth_pt1.useDVB()==1: + if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上 + status.changeBSCSRecording(1) + else: + status.changeTERecording(1) + try: + recording_earth_pt1.record(ch,tsid,pout,time,0) + except Exception, inst: + recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst)) + if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上 + status.changeBSCSRecording(-1) + else: + status.changeTERecording(-1) + if os.path.exists(pout): + try: + os.chmod(pout,0755) + except: + "" +def b252tsmix(pin, pout): + if not (os.path.exists(pout) and os.path.getsize(pin)>os.path.getsize(pout)*0.95 and os.path.getsize(pin)<os.path.getsize(pout)*1.05): + exe="" + if configreader.getConfPath('b25_remote')=="1": + try: + exe = configreader.getConfPath('b25_env')+" && " + except: + inst=u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。" + recdblist.addCommonlogEX(u"Error",u"b252tsmix(tv2ts.py)", "",inst) + exe = exe + "nice -n 17 " + configreader.getConfPath('b25') + doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"' + recdblist.printutf8(doexe) + recdblist.addCommandSelfLog(pin,doexe) + txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8') + recdblist.addLog(pin, doexe, u"b25ログ-コマンド") + recdblist.addLog(pin, txt, u"b25ログ-詳細") + recdblist.addCommandLogZip(pin, "b25", "b25", doexe, txt) + return txt +def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない + tssplitterex=configreader.getConfPath("java")+" -jar "+configreader.getConfPath("jTsSplitter") + doexe =tssplitterex + " \""+ pin + "\" \""+ pout + "\" " + str(csch) + doexe = "nice -n 18 " + doexe + os.environ['LANG']="ja_JP.UTF-8" + txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8') + recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド") + recdblist.addLog(pin, txt, u"TsSplitログ-詳細") + time.sleep(1) + if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000: + os.remove(pin) + diff --git a/rec10/xml2db_dom.py b/rec10/xml2db_dom.py new file mode 100644 index 0000000..24c1da7 --- /dev/null +++ b/rec10/xml2db_dom.py @@ -0,0 +1,148 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import xml.dom.minidom +import datetime +import re +import traceback + +import zenhan +import chdb +import auto_rec +import recdb +import rec10d +import n_gram +import recdblist +import epgdb +import status +def getText(elm): + nodelist = elm.childNodes + rc = "" + # 全てのノードに対して + for node in nodelist: + # テキストノードなら値を取得 + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + return rc +def getText_item(obj): + rc="" + for o in obj: + rc=rc+getText(o) + return rc +def writeMultiTVDB(bctype,tvlists): + rec10d.rec10db.new_epg_timeline(bctype) + for channel,start,stop,title,desc,longdesc,category in tvlists: + rec10d.rec10db.add_epg_timeline(bctype, channel, start, stop, title, desc, longdesc, category) +def writeMultiCHDB(chlists): + for chtxt,dn in chlists: + rec10d.rec10db.update_chname_by_chtxt_epg_ch(chtxt,dn) + if dn==None: + chdb.changeCHShow(chtxt,"0") + else: + if len(dn)<1: + chdb.changeCHShow(chtxt,"0") +def writeMultiLogoDB(logolists): + #[type,sv,pngdata] + for type,sv,pngdata in logolists: + chtxt=chdb.searchCHFromCsch(sv)['chtxt'] + if len(chtxt)>0: + rec10d.rec10db.change_logodata_epg_ch(chtxt,type,pngdata) +def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る + dtb=datetime.datetime.now() + dom=xml.dom.minidom.parse(file(xmlpath)) + chlist=[] + tvlist=[] + bayes={} + rHisch=re.compile(u"『([^『]+)』(.+)\Z")##History CHのタイトル#01 exp:「#01説明」をタイトルに含める + for ch in dom.getElementsByTagName('channel'): + chtxtt=ch.getAttribute("id") + chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data + chlist.append([chtxtt,chname]) + for tv in dom.getElementsByTagName('programme'): + channel=zenhan.toHankaku_ABC123(tv.getAttribute("channel")) + start=tv.getAttribute("start").replace(" +0900", "") + stop=tv.getAttribute("stop").replace(" +0900", "") + title=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("title"))).replace(",", "_") + desc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("desc"))) + longdesc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("longdesc"))) + category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category"))) + title=addTitle_Subtitle(rHisch,1,title,desc) + tch=chdb.searchCHFromChtxt(channel) + if tch!=None: + if tch.get('bctype',"")==bctype and not tch['visible']==0: + bt=bayes.get(tch['chtxt'],["","",0]) + bt2=[bt[0]+title+" ",bt[1]+desc+" "+longdesc+" ",bt[2]+1] + bayes[tch['chtxt']]=bt2 + tvlist.append([channel,start,stop,title,desc,longdesc,category]) + p=auto_rec.calcKey(tch['chtxt'], title,desc+" "+longdesc) + if p>2000: + bttt=datetime.datetime.strptime(start,"%Y%m%d%H%M%S") + bttt=bttt-datetime.timedelta(seconds=1200) + bttime=bttt.strftime("%Y-%m-%d %H:%M:%S") + ettt=datetime.datetime.strptime(stop,"%Y%m%d%H%M%S") + ettt=ettt+datetime.timedelta(seconds=1200) + ettime=ettt.strftime("%Y-%m-%d %H:%M:%S") + chs=rec10d.rec10db.select_bytime_bychtxt_all_timeline(bttime,ettime,tch['chtxt']) + p2=0 + if len(chs)>0: + for ch in chs: + p2t=n_gram.trigram(ch['title'],title) + if p2t>p2: + p2=p2t + if p2<350: + if status.getSettings_auto_bayes()==1: + if p2<200: + maxnum=0 + if len(ch['ch'])>2: + maxnum=epgdb.count_schedule_timeline(bttime, ettime)[1] + maxnum=int(configreader.getConfEnv("bscs_max"))-maxnum + else: + maxnum=epgdb.count_schedule_timeline(bttime, ettime)[0] + maxnum=int(configreader.getConfEnv("te_max"))-maxnum + if maxnum>0: + topt=status.getSettings_auto_opt() + recdb.reserveReckey(recdblist.REC_RESERVE,title,tch['chtxt'], bttime, ettime,topt) + else: + recdb.addAutoBayesKeyword(tch['chtxt'],title,start,stop,p) + dom.unlink() + if len(chlist) > 0: + writeMultiCHDB(chlist) + chlist = [] + if len(tvlist) > 0: + writeMultiTVDB(bctype,tvlist) + tvlist = [] + for ct,list in bayes.items(): + auto_rec.updateRecall(ct,list[0],list[1],list[2]) + auto_rec.updateRecall("ALL",list[0],list[1],list[2]) + dtb=datetime.datetime.now()-dtb + recdblist.printutf8(bctype + u" epg取り出し終了") + recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .") +def xml2db_dom_logo(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る + dtb=datetime.datetime.now() + dom=xml.dom.minidom.parse(file(xmlpath)) + logolist=[] + for logo in dom.getElementsByTagName('logo'): + type=int(logo.getAttribute("type")) + sv=logo.getAttribute("sv") + pngdata=logo.childNodes[0].data + logolist.append([type,sv,pngdata]) + dom.unlink() + if len(logolist) > 0: + writeMultiLogoDB(logolist) + dtb=datetime.datetime.now()-dtb + recdblist.printutf8(bctype + u" epg取り出し終了") + recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating logo DB .") +def addTitle_Subtitle(recompiled,num,title,exp): + try: + tST=recompiled.match(exp) + newtitle=u"" + if tST: + newtitle=title+u"『"+tST.group(num)+u"』" + else: + newtitle=title + except Exception, inst: + recdblist.addCommonlogEX("Error", "addTitle_Subtitle(xml2db_dob.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + newtitle=title + return newtitle diff --git a/rec10/zenhan.py b/rec10/zenhan.py new file mode 100644 index 0000000..bb6135e --- /dev/null +++ b/rec10/zenhan.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import recdblist +global z_ascii +global h_ascii +global z_number +global h_number +z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 〜" +h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ -" +z_ascii_sp = unichr(0x2212)+unichr(0xff0e) +h_ascii_sp = unichr(0x002d)+unichr(0x002e) +z_number = u"0123456789" +h_number = u"0123456789" +z_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" +h_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" +def toHankaku(str): + retstr = u"" + for s in str: + i = z_ascii.find(s) + if (i != -1): + s = h_ascii[i] + i = z_ascii_sp.find(s) + if (i != -1): + s = h_ascii_sp[i] + i = z_number.find(s) + if (i != -1): + s = h_number[i] + retstr = retstr + s + return retstr +def toHankaku_ABC123(str): + retstr = u"" + for s in str: + i = z_alphabet.find(s) + if (i != -1): + s = h_alphabet[i] + i = z_ascii_sp.find(s) + if (i != -1): + s = h_ascii_sp[i] + i = z_number.find(s) + if (i != -1): + s = h_number[i] + retstr = retstr + s + return retstr +def checkCharacterType(character): + """ + return code is 1:Alphabet 2:Hiragana 3:Katakana 4:Kanji + """ + chcode=ord(character) + if chcode>=0x0000 and chcode<=0x007F: + return 1 + elif chcode>=0x3040 and chcode<=0x309F: + return 2 + elif chcode>=0x30A0 and chcode<=0x30FF: + return 3 + elif chcode>=0x4E00 and chcode<=0x9FFF: + return 4 diff --git a/rec10/zip.py b/rec10/zip.py new file mode 100644 index 0000000..7dc9ab5 --- /dev/null +++ b/rec10/zip.py @@ -0,0 +1,19 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import os +import os.path +import zipfile + +def addFile2FileZip(addfile,basefile): + th=0 + + if os.path.exists(basefile): + th=zipfile.ZipFile(basefile,'a',zipfile.ZIP_DEFLATED) + else: + th=zipfile.ZipFile(basefile,'w',zipfile.ZIP_DEFLATED) + if os.path.exists(addfile): + th.write(addfile,os.path.basename(addfile)) + th.close() diff --git a/rec10Manual0.9.9.pdf b/rec10Manual0.9.9.pdf new file mode 100755 index 0000000..3e503ed Binary files /dev/null and b/rec10Manual0.9.9.pdf differ diff --git a/tstools/BonTsDemux/src.zip b/tstools/BonTsDemux/src.zip new file mode 100755 index 0000000..a7893cd Binary files /dev/null and b/tstools/BonTsDemux/src.zip differ diff --git a/tstools/epgdump/bit.c b/tstools/epgdump/bit.c new file mode 100644 index 0000000..0646624 --- /dev/null +++ b/tstools/epgdump/bit.c @@ -0,0 +1,133 @@ +// -*- tab-width:4 -*- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "bit.h" + +// 2-STD-B10v4_6.pdf p89 (101/399) +int parseBIThead(unsigned char *data, BIThead *head) { + int boff = 0; + + memset(head, 0, sizeof(BIThead)); + + head->table_id = getBit(data, &boff, 8); + head->section_syntax_indicator = getBit(data, &boff, 1); + head->reserved_future_use1 = getBit(data, &boff, 1); + head->reserved1 = getBit(data, &boff, 2); + head->section_length = getBit(data, &boff, 12); + head->original_network_id = getBit(data, &boff, 16); + head->reserved2 = getBit(data, &boff, 2); + head->version_number = getBit(data, &boff, 5); + head->current_next_indicator = getBit(data, &boff, 1); + head->section_number = getBit(data, &boff, 8); + head->last_section_number = getBit(data, &boff, 8); + head->reserved_future_use2 = getBit(data, &boff, 3); + head->broadcast_view_propriety = getBit(data, &boff, 1); + head->first_descriptors_length = getBit(data, &boff, 12); + return 10 + head->first_descriptors_length; +} + +// 4-TR-B14v4_3-2p3.pdf p4-254 (276/543) +int parseBITloop(unsigned char *data, BITloop *loop) { + int boff = 0; + + memset(loop, 0, sizeof(BITloop)); + + loop->broadcaster_id = getBit(data, &boff, 8); + loop->reserved_future_use = getBit(data, &boff, 4); + loop->broadcaster_descriptors_length = getBit(data, &boff, 12); + + return 3; +} + +// SI伝送パラメータ記述子 +int parseBITdesc(unsigned char *data, BITdesc *desc) { + int boff = 0; + + memset(desc, 0, sizeof(BITdesc)); + + desc->descriptor_tag = getBit(data, &boff, 8); + desc->descriptor_length = getBit(data, &boff, 8); + desc->parameter_version = getBit(data, &boff, 8); + desc->update_time = getBit(data, &boff,16); + + return 5; +} + +int parseBITtable(unsigned char *data, BITtable *table) { + int boff = 0; + + memset(table, 0, sizeof(BITtable)); + + table->table_id = getBit(data, &boff, 8); + table->table_description_length = getBit(data, &boff, 8); + table->table_cycle = getBit(data, &boff, 16); + + return table->table_description_length + 2; +} + +void dumpBIT(unsigned char *ptr) +{ + BIThead bith; + BITloop bitl; + BITdesc bitd; + BITtable bitt; + + int len = 0; + int loop_len = 0; + int desc_len = 0; + int table_len = 0; + + /* BIT */ + len = parseBIThead(ptr, &bith); + ptr += len; + loop_len = bith.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC + + while(loop_len > 0) { + len = parseBITloop(ptr, &bitl); + ptr += len; + loop_len -= len; + + desc_len = bitl.broadcaster_descriptors_length; + loop_len -= desc_len; + + while(desc_len > 0) { + len = parseBITdesc(ptr, &bitd); + ptr += len; + desc_len -= len; + + table_len = bitd.descriptor_length - 3; + desc_len -= table_len; + + if ( bitd.descriptor_tag != 0xD7 ) { + ptr += table_len; + continue; + } + + while(table_len > 0) { + len = parseBITtable(ptr, &bitt); + ptr += len; + table_len -= len; + + /* + 0x4E (M-EIT,L-EIT) + 0x50(各局伝送パラメータ運用部分の H-EIT[schedule basic]) + 0x58 (各局伝送パラメータ運用部分の H-EIT[schedule extended]) + 0xC3(SDTT) + 0xC8(CDT) + */ + + if (0) printf("BIT=(%d)%d:%d:%d:%d|0x%x:%d:%d=BCD(%d)\n", + bitl.broadcaster_id, bitd.descriptor_tag, bitd.descriptor_length, + bitd.parameter_version, bitd.update_time, + bitt.table_id, bitt.table_description_length, + bitt.table_cycle, BCD(bitt.table_cycle)); + } + } + } + + return; +} + diff --git a/tstools/epgdump/bit.h b/tstools/epgdump/bit.h new file mode 100644 index 0000000..fd964ce --- /dev/null +++ b/tstools/epgdump/bit.h @@ -0,0 +1,57 @@ +#ifndef BIT_H +#define BIT_H 1 + +#include "util.h" +#include "ts_ctl.h" + +typedef struct _BIThead { + unsigned char table_id; + int section_syntax_indicator; + int reserved_future_use1; + int reserved1; + int section_length; + int original_network_id; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; + int reserved_future_use2; + int broadcast_view_propriety; + int first_descriptors_length; + // first_descriptors skipped +} BIThead; + +typedef struct _BITloop { + int broadcaster_id; + int reserved_future_use; + int broadcaster_descriptors_length; +} BITloop; + +typedef struct _BITdesc { + int descriptor_tag; + int descriptor_length; + int parameter_version; + int update_time; +} BITdesc; + +typedef struct _BITtable { + int table_id; + int table_description_length; + int table_cycle; +} BITtable; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parseBIThead(unsigned char *data, BIThead *head); + int parseBITdesc(unsigned char *data, BITdesc *desc); + void dumpBIT(unsigned char *ptr); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/tstools/epgdump/cdt.c b/tstools/epgdump/cdt.c new file mode 100644 index 0000000..a55acbd --- /dev/null +++ b/tstools/epgdump/cdt.c @@ -0,0 +1,131 @@ +// -*- tab-width:4 -*- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "cdt.h" +#include "ts_ctl.h" +#include "clt2png.h" + +int parseCDThead(unsigned char *data, CDThead *h) { + int boff = 0; + + memset(h, 0, sizeof(CDThead)); + + h->table_id = getBit(data, &boff, 8); + h->section_syntax_indicator = getBit(data, &boff, 1); + h->reserved_future_use1 = getBit(data, &boff, 1); + h->reserved1 = getBit(data, &boff, 2); + h->section_length = getBit(data, &boff, 12); + h->download_data_id = getBit(data, &boff, 16); + h->reserved2 = getBit(data, &boff, 2); + h->version_number = getBit(data, &boff, 5); + h->current_next_indicator = getBit(data, &boff, 1); + h->section_number = getBit(data, &boff, 8); + h->last_section_number = getBit(data, &boff, 8); + h->original_network_id = getBit(data, &boff, 16); + h->data_type = getBit(data, &boff, 8); + h->reserved_future_use2 = getBit(data, &boff, 4); + h->descriptors_loop_length = getBit(data, &boff, 12); + + return 13; +} + +int parseCDTdesc(unsigned char *data, CDTdesc *desc) { +// ほとんど呼ばれることはない + int boff = 0; + + memset(desc, 0, sizeof(CDTdesc)); + + desc->descriptor_tag = getBit(data, &boff, 8); + desc->descriptor_length = getBit(data, &boff, 8); + + return desc->descriptor_length + 2; +} + +int parseCDTdata(unsigned char *data, CDTdata *cdtd) { + int boff = 0; + + memset(cdtd, 0, sizeof(CDTdata)); + + cdtd->logo_type = getBit(data, &boff, 8); + cdtd->reserved_future_use1 = getBit(data, &boff, 7); + cdtd->logo_id = getBit(data, &boff, 9); + cdtd->reserved_future_use2 = getBit(data, &boff, 4); + cdtd->logo_version = getBit(data, &boff, 12); + cdtd->data_size = getBit(data, &boff, 16); + cdtd->data = calloc(1, cdtd->data_size); + memcpy(cdtd->data, data + boff / 8, cdtd->data_size); + //boff += cdtd->data_size * 8; + + return cdtd->data_size + 7; +} + +void dumpCDT(unsigned char *ptr, STATION *station, int station_count) +{ + CDThead cdth; + CDTdesc desc; + CDTdata cdtd; + LOGO * pLogo; + + int len = 0; + int loop_len = 0; + int desc_len = 0; + int i = 0; + + /* CDT */ + len = parseCDThead(ptr, &cdth); + ptr += len; + loop_len = cdth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC + + desc_len = cdth.descriptors_loop_length; + while(desc_len > 0) { + len = parseCDTdesc(ptr, &desc); + ptr += len; + desc_len -= len; + } + + while(loop_len > 0) { + /* + logo_type + 0x00 24x48 864 SD4:3 スモール + 0x01 24x36 648 SD16:9 スモール + 0x02 27x48 972 HD スモール + 0x03 36x72 1296 SD4:3 ラージ + 0x04 36x54 972 SD16:9 ラージ + 0x05 36x64 1152 HD ラージ + */ + len = parseCDTdata(ptr, &cdtd); + ptr += len; + loop_len -= len; +/* + char fname[16]; + sprintf(fname,"%d_%d.png",cdth.download_data_id,cdtd.logo_type); + FILE* png = fopen(fname,"wb"); + void* mem_png = NULL; + int size_png; + clt2png(cdtd.data,&mem_png, &size_png); + fwrite(mem_png, 1, size_png, png); + fclose(png); +*/ +#if 0 + printf("CDT=(%d:%d:%d:%d:%d:%dbyte:desc%dbyte)%d,%d,%d,%d\n", + cdth.table_id, cdth.download_data_id, cdth.version_number, + cdth.original_network_id, cdth.data_type, + cdth.section_length, cdth.descriptors_loop_length, + + cdtd.logo_type, cdtd.logo_id, cdtd.logo_version, + cdtd.data_size); +#endif + for ( i = 0; i < station_count; i++ ) { + pLogo = &station[i].logo_array[cdtd.logo_type]; + if ( station[i].logo_download_data_id == cdth.download_data_id ) { + pLogo->logo = NULL; + clt2png(cdtd.data, &pLogo->logo, &pLogo->logo_size); + } + } + } + return; +} + diff --git a/tstools/epgdump/cdt.h b/tstools/epgdump/cdt.h new file mode 100644 index 0000000..9d39bf6 --- /dev/null +++ b/tstools/epgdump/cdt.h @@ -0,0 +1,56 @@ +#ifndef CDT_H +#define CDT_H 1 + +#include <stdio.h> +#include <stdlib.h> + +#include "sdt.h" +#include "util.h" +#include "ts_ctl.h" + +typedef struct _CDThead { + unsigned char table_id; + int section_syntax_indicator; + int reserved_future_use1; + int reserved1; + int section_length; + int download_data_id; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; + int original_network_id; + int reserved_future_use2; + int data_type; + int descriptors_loop_length; +} CDThead; + +typedef struct _CDTdesc { + unsigned char descriptor_tag; + int descriptor_length; +} CDTdesc; + +typedef struct _CDTdata { + int logo_type; + int reserved_future_use1; + int logo_id; + int reserved_future_use2; + int logo_version; + int data_size; + void *data; +} CDTdata; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parseCDThead(unsigned char *data, CDThead *h); + int parseCDTdesc(unsigned char *data, CDTdesc *desc); + void dumpCDT(unsigned char *ptr, STATION *station, int station_count); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/tstools/epgdump/clt2png.c b/tstools/epgdump/clt2png.c new file mode 100644 index 0000000..fecc5c7 --- /dev/null +++ b/tstools/epgdump/clt2png.c @@ -0,0 +1,465 @@ +// ƒf[ƒ^•ú‘——pƒvƒƒOƒ‰ƒ€‹l‚ߍ‡‚킹 ‚»‚Ì2‚æ‚è—¬—p +// ƒJƒ‰[ƒ}ƒbƒvƒf[ƒ^‚ðPNG‚É“K—p‚·‚é + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define bool char +#define true 1 +#define false 0 +#define inline + +typedef unsigned char byte; +typedef unsigned short uint16; +typedef unsigned long uint32; + +typedef struct _rgb_color { + byte r; + byte g; + byte b; + byte a; +} rgb_color; + +typedef struct _color_map_data { + byte clut_type; + byte depth; + byte region_flag; + byte start_end_flag; + byte reserved_future_use; + uint16 top_left_x; + uint16 top_left_y; + uint16 bottom_right_x; + uint16 bottom_right_y; + uint16 start_index; + uint16 end_index; + rgb_color color_map[0x10000]; +} color_map_data; + +static const rgb_color default_colormap[128] = { + { 0, 0, 0, 255}, + {255, 0, 0, 255}, + { 0, 255, 0, 255}, + {255, 255, 0, 255}, + { 0, 0, 0, 255}, + {255, 0, 255, 255}, + { 0, 255, 255, 255}, + {255, 255, 255, 255}, + { 0, 0, 0, 0}, + {170, 0, 0, 255}, + { 0, 170, 0, 255}, + {170, 170, 0, 255}, + { 0, 0, 170, 255}, + {170, 0, 170, 255}, + { 0, 170, 170, 255}, + {170, 170, 170, 255}, + { 0, 0, 85, 255}, + { 0, 85, 0, 255}, + { 0, 85, 85, 255}, + { 0, 85, 170, 255}, + { 0, 85, 255, 255}, + { 0, 170, 85, 255}, + { 0, 170, 255, 255}, + { 0, 255, 85, 255}, + { 0, 255, 170, 255}, + { 85, 0, 0, 255}, + { 85, 0, 85, 255}, + { 85, 0, 170, 255}, + { 85, 0, 255, 255}, + { 85, 85, 0, 255}, + { 85, 85, 85, 255}, + { 85, 85, 170, 255}, + { 85, 85, 255, 255}, + { 85, 170, 0, 255}, + { 85, 170, 85, 255}, + { 85, 170, 170, 255}, + { 85, 170, 255, 255}, + { 85, 255, 0, 255}, + { 85, 255, 85, 255}, + { 85, 255, 170, 255}, + { 85, 255, 255, 255}, + {170, 0, 85, 255}, + {170, 0, 255, 255}, + {170, 85, 0, 255}, + {170, 85, 85, 255}, + {170, 85, 170, 255}, + {170, 85, 255, 255}, + {170, 170, 85, 255}, + {170, 170, 255, 255}, + {170, 255, 0, 255}, + {170, 255, 85, 255}, + {170, 255, 170, 255}, + {170, 255, 255, 255}, + {255, 0, 85, 255}, + {255, 0, 170, 255}, + {255, 85, 0, 255}, + {255, 85, 85, 255}, + {255, 85, 170, 255}, + {255, 85, 255, 255}, + {255, 170, 0, 255}, + {255, 170, 85, 255}, + {255, 170, 170, 255}, + {255, 170, 255, 255}, + {255, 225, 85, 255}, + {225, 225, 170, 255}, + { 0, 0, 0, 128}, + {255, 0, 0, 128}, + { 0, 255, 0, 128}, + {255, 255, 0, 128}, + { 0, 0, 255, 128}, + {255, 0, 255, 128}, + { 0, 255, 255, 128}, + {255, 255, 255, 128}, + {170, 0, 0, 128}, + { 0, 170, 0, 128}, + {170, 170, 0, 128}, + { 0, 0, 170, 128}, + {170, 0, 170, 128}, + { 0, 170, 170, 128}, + {170, 170, 170, 128}, + { 0, 0, 85, 128}, + { 0, 85, 0, 128}, + { 0, 85, 85, 128}, + { 0, 85, 170, 128}, + { 0, 85, 255, 128}, + { 0, 170, 85, 128}, + { 0, 170, 255, 128}, + { 0, 255, 85, 128}, + { 0, 255, 170, 128}, + { 85, 0, 0, 128}, + { 85, 0, 85, 128}, + { 85, 0, 170, 128}, + { 85, 0, 255, 128}, + { 85, 85, 0, 128}, + { 85, 85, 85, 128}, + { 85, 85, 170, 128}, + { 85, 85, 255, 128}, + { 85, 170, 0, 128}, + { 85, 170, 85, 128}, + { 85, 170, 170, 128}, + { 85, 170, 255, 128}, + { 85, 255, 0, 128}, + { 85, 255, 85, 128}, + { 85, 255, 170, 128}, + { 85, 255, 255, 128}, + {170, 0, 85, 128}, + {170, 0, 255, 128}, + {170, 85, 0, 128}, + {170, 85, 85, 128}, + {170, 85, 170, 128}, + {170, 85, 255, 128}, + {170, 170, 85, 128}, + {170, 170, 255, 128}, + {170, 255, 0, 128}, + {170, 255, 85, 128}, + {170, 255, 170, 128}, + {170, 255, 255, 128}, + {255, 0, 85, 128}, + {255, 0, 170, 128}, + {255, 85, 0, 128}, + {255, 85, 85, 128}, + {255, 85, 170, 128}, + {255, 85, 255, 128}, + {255, 170, 0, 128}, + {255, 170, 85, 128}, + {255, 170, 170, 128}, + {255, 170, 255, 128}, + {255, 255, 85, 128}, +}; + + +/* + Y = 0.2126 * R + 0.7152 * G + 0.0722 * B + Cb = -(0.2126/1.8556)*(224/219) * R -(0.7152/1.8556)*(224/219) * G 0.5*(224/219) * B + Cr = 0.5*(224/219) * R -(0.7152/1.5748)*(224/219) * G -(0.0722/1.5748)*(224/219) * B +*/ + +inline byte ycbcr_to_r(int y,int cb,int cr) +{ + int r=(76309*(y-16)+104597*(cr-128)+32768)/65536; + return (byte)(r<0?0:r>255?255:r); +} + +inline byte ycbcr_to_g(int y,int cb,int cr) +{ + int g=(76309*(y-16)-25675*(cb-128)-53279*(cr-128)+32768)/65536; + return (byte)(g<0?0:g>255?255:g); +} + +inline byte ycbcr_to_b(int y,int cb,int cr) +{ + int b=(76309*(y-16)+132201*(cb-128)+32768)/65536; + return (byte)(b<0?0:b>255?255:b); +} + + +byte read_byte(void *fp, int *index_fp) +{ + int data = *((unsigned char*)fp + *index_fp++); + return (byte)data; +} + + +uint16 read_word(void *fp, int *index_fp) +{ + byte data=read_byte(fp, index_fp); + + return ((uint16)data<<8)|(uint16)read_byte(fp, index_fp); +} + + +uint32 read_dword(void *fp, int *index_fp) +{ + byte data1=read_byte(fp, index_fp); + byte data2=read_byte(fp, index_fp); + byte data3=read_byte(fp, index_fp); + byte data4=read_byte(fp, index_fp); + + return ((uint32)data1<<24)|((uint32)data2<<16)|((uint32)data3<<8)|(uint32)data4; +} + + +void read_data(void *fp,int *index_fp,void *data,size_t size) +{ + memcpy(data,fp + *index_fp, size); + *index_fp += size; +} + + +void write_dword(void **fp, int *index_fp,uint32 value) +{ + byte data[4]; + + data[0]=(byte)(value>>24); + data[1]=(byte)((value>>16)&0xFF); + data[2]=(byte)((value>>8)&0xFF); + data[3]=(byte)(value&0xFF); + *fp = realloc(*fp, *index_fp + 4); + memcpy(*fp + *index_fp, data, 4); + *index_fp += 4; +} + + +void write_data(void **fp,int *index_fp,void *data,size_t size) +{ + *fp = realloc(*fp, *index_fp + size); + memcpy(*fp + *index_fp, data, size); + *index_fp += size; +} + + +uint32 calc_crc(const byte *data,size_t size) +{ + static const uint32 crc_table[256] = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, + 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, + 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, + 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, + 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, + 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, + 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, + 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, + 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, + 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, + 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, + 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, + 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, + 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, + 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, + 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, + 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, + 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, + }; + uint32 crc; + + crc=0xFFFFFFFFUL; + for (size_t i=0;i<size;i++) + crc=(crc>>8)^crc_table[(crc^data[i])&0x000000FFUL]; + return ~crc; +} + + +int clt2png(void* input, void** output, int* output_size) +{ + int input_index = 0, output_index = 0; + + color_map_data colormap; + memset(colormap.color_map,0,sizeof(colormap.color_map)); + memcpy(colormap.color_map,default_colormap,sizeof(default_colormap)); + + if (input!=NULL) { + // Parse color_map_data + byte b=read_byte(input, &input_index); + colormap.clut_type=(b&0x80)>>7; + colormap.depth=(b&0x60)>>5; + if (colormap.depth==3) { + printf("Error : Unknown depth (%d)\n",colormap.depth); + return 1; + } + colormap.region_flag=(b&0x10)>>4; + colormap.start_end_flag=(b&0x08)>>3; + colormap.reserved_future_use=b&0x07; + if (colormap.region_flag) { + colormap.top_left_x=read_word(input, &input_index); + colormap.top_left_y=read_word(input, &input_index); + colormap.bottom_right_x=read_word(input, &input_index); + colormap.bottom_right_y=read_word(input, &input_index); + } + if (colormap.start_end_flag) { + if (colormap.depth==0) { + b=read_byte(input, &input_index); + colormap.start_index=b>>4; + colormap.end_index=b&0x0F; + } else if (colormap.depth==1) { + colormap.start_index=read_byte(input, &input_index); + colormap.end_index=read_byte(input, &input_index); + } else if (colormap.depth==2) { + colormap.start_index=read_word(input, &input_index); + colormap.end_index=read_word(input, &input_index); + } + } else { + colormap.start_index=0; + switch (colormap.depth) { + case 0: colormap.end_index=15; break; + case 1: colormap.end_index=255; break; + case 2: colormap.end_index=65535; break; + } + } + for (uint16 i=colormap.start_index;i<=colormap.end_index;i++) { + if (colormap.clut_type==0) { + int y,cb,cr; + y=read_byte(input, &input_index); + cb=read_byte(input, &input_index); + cr=read_byte(input, &input_index); + colormap.color_map[i].r=ycbcr_to_r(y,cb,cr); + colormap.color_map[i].g=ycbcr_to_g(y,cb,cr); + colormap.color_map[i].b=ycbcr_to_b(y,cb,cr); + } else { + colormap.color_map[i].r=read_byte(input, &input_index); + colormap.color_map[i].g=read_byte(input, &input_index); + colormap.color_map[i].b=read_byte(input, &input_index); + } + colormap.color_map[i].a=read_byte(input, &input_index); + } + input_index = 0; + } + + // Open PNG file + + byte buffer[8]; + read_data(input,&input_index,buffer,8); + if (memcmp(buffer,"\x89PNG\r\n\x1A\n",8)!=0) { + printf("Error : Not a PNG format\n"); + return 1; + } + write_data(output,&output_index,buffer,8); + int bit_depth=0,color_type=-1; + bool has_palette=false; + while (true) { + read_data(input,&input_index,buffer,8); + uint32 data_size=((uint32)buffer[0]<<24)|((uint32)buffer[1]<<16)|((uint32)buffer[2]<<8)|(uint32)buffer[3]; + if (memcmp(buffer+4,"IHDR",4)==0) { + byte header[13]; + read_data(input,&input_index,header,13); + bit_depth=header[8]; + color_type=header[9]; + input_index -= 13; + } else if (memcmp(buffer+4,"PLTE",4)==0) { + has_palette=true; + } else if (memcmp(buffer+4,"IDAT",4)==0) { + if (!has_palette && bit_depth<=8 && color_type==3) { + int num_colors=1<<bit_depth; + byte data[4+256*3]; + int i; + uint32 crc; + + // tRNS + for (i=0;i<num_colors;i++) { + if (colormap.color_map[i].a<255) + break; + } + if (i<num_colors) { + write_dword(output,&output_index,num_colors); + memcpy(data,"tRNS",4); + for (int i=0;i<num_colors;i++) + data[4+i]=colormap.color_map[i].a; + write_data(output,&output_index,data,4+num_colors); + crc=calc_crc(data,4+num_colors); + write_dword(output,&output_index,crc); + } + + // Generate PLTE chunk + uint32 palette_size=num_colors*3; + write_dword(output,&output_index,palette_size); + memcpy(data,"PLTE",4); + for (i=0;i<num_colors;i++) { + data[4+i*3+0]=colormap.color_map[i].r; + data[4+i*3+1]=colormap.color_map[i].g; + data[4+i*3+2]=colormap.color_map[i].b; + } + write_data(output,&output_index,data,4+palette_size); + crc=calc_crc(data,4+palette_size); + write_dword(output,&output_index,crc); + } + } + // Copy chunk + write_data(output,&output_index,buffer,8); + void *data = malloc(data_size+4); + read_data(input,&input_index,data,data_size+4); + write_data(output,&output_index,data,data_size+4); + free(data); + if (memcmp(buffer+4,"IEND",4)==0) + break; + } + + *output_size = output_index; + + return 0; +} + diff --git a/tstools/epgdump/clt2png.h b/tstools/epgdump/clt2png.h new file mode 100644 index 0000000..b3dbbde --- /dev/null +++ b/tstools/epgdump/clt2png.h @@ -0,0 +1,10 @@ +// ƒf[ƒ^•ú‘——pƒvƒƒOƒ‰ƒ€‹l‚ߍ‡‚킹 ‚»‚Ì2‚æ‚è—¬—p +// ƒJƒ‰[ƒ}ƒbƒvƒf[ƒ^‚ðPNG‚É“K—p‚·‚é + +#ifndef __CLT2PNG_H__ +#define __CLT2PNG_H__ + +int clt2png(void* input, void** output, int* output_size); + +#endif + diff --git a/tstools/epgdump/dsmcc.c b/tstools/epgdump/dsmcc.c new file mode 100644 index 0000000..7924935 --- /dev/null +++ b/tstools/epgdump/dsmcc.c @@ -0,0 +1,258 @@ +// -*- tab-width:4 -*- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "dsmcc.h" +#include "ts_ctl.h" +#include "clt2png.h" + +// STD-B21 p130 (144) +// a_90-with-att.pdf p24 (29/99) +int parseDSMCChead(unsigned char *data, DSMCChead *dsmh) { + int boff = 0; + + memset(dsmh, 0, sizeof(DSMCChead)); + + dsmh->table_id = getBit(data, &boff, 8); + dsmh->section_syntax_indicator = getBit(data, &boff, 1); + dsmh->complement_indicator = getBit(data, &boff,1); + dsmh->reserved1 = getBit(data, &boff, 2); + dsmh->section_length = getBit(data, &boff, 12); + dsmh->table_id_extension = getBit(data, &boff, 16); + dsmh->reserved2 = getBit(data, &boff, 2); + dsmh->version_number = getBit(data, &boff, 5); + dsmh->current_next_indicator = getBit(data, &boff, 1); + dsmh->section_number = getBit(data, &boff, 8); + dsmh->last_section_number = getBit(data, &boff, 8); + + return 8; +} + +// a_90-with-att.pdf p29 (34/99) +// 2-STD-B24v5_4-3p3.pdf p16 (30/125) +int parseDSMCCbodyDII(unsigned char *data, DSMCCbodyDII *dsmbdii) { + int boff = 0, i; + DSMCCbodyDIIModule *module; + + memset(dsmbdii, 0, sizeof(DSMCCbodyDII)); + + // header + dsmbdii->protocolDiscriminator = getBit(data, &boff, 8); + dsmbdii->dsmccType = getBit(data, &boff, 8); + dsmbdii->messageId = getBit(data, &boff, 16); + dsmbdii->transaction_id = getBit(data, &boff, 32); + dsmbdii->reserved = getBit(data, &boff, 8); + dsmbdii->adaptationLength = getBit(data, &boff, 8); + dsmbdii->messageLength = getBit(data, &boff, 16); + if ( dsmbdii->adaptationLength > 0 ) { + dsmbdii->dsmccAdaptationHeader = allocCopy(data, &boff, dsmbdii->adaptationLength); + } + + // body + dsmbdii->downloadId = getBit(data, &boff, 32); + dsmbdii->blockSize = getBit(data, &boff, 16); + dsmbdii->windowSize = getBit(data, &boff, 8); + dsmbdii->ackPeriod = getBit(data, &boff, 8); + dsmbdii->tCDownloadWindow = getBit(data, &boff, 32); + dsmbdii->tCDownloadScenario = getBit(data, &boff, 32); + dsmbdii->compatibilityDescriptor = getBit(data, &boff, 16); +/* + see http://www.atsc.org/cms/standards/a_90-with-att.pdf + + compatibilityDescriptorLength 16 + descriptorCount 16 + for(i=0;i<descriptorCount;i++) { + descriptorType 8 + descriptorLength 8 + specifierType 8 + specifierData 24 + model 16 + version 16 + subDescriptorCount 8 + for(j=0;j<subDescriptorCount;j++) { + subDescriptor() { + subDescriptorType 8 + subDescriptorLength 8 + for(k=0;k<subDescriptorLength;k++) { + additionalInformation 8 + } + } +*/ + boff += dsmbdii->compatibilityDescriptor * 8; + dsmbdii->numberOfModules = getBit(data, &boff, 16); + + if ( dsmbdii->numberOfModules > 0 ) { + dsmbdii->modules = calloc(1, sizeof(DSMCCbodyDIIModule) * dsmbdii->numberOfModules + 1000); + + for (i=0; i<dsmbdii->numberOfModules; i++) { + module = dsmbdii->modules + sizeof(DSMCCbodyDIIModule) * i; + module->moduleId = getBit(data, &boff, 16); + module->moduleSize = getBit(data, &boff, 32); + module->moduleVersion = getBit(data, &boff, 8); + module->moduleInfoLength = getBit(data, &boff, 8); + + if ( *(data + boff / 8) == 0x01 ) { + /* Type 記述子 モジュールの型(MIME 形式等) */ + module->descriptor_tag = getBit(data, &boff, 8); + module->descriptor_length = getBit(data, &boff, 8); + module->Type = allocCopy(data, &boff, module->descriptor_length + 1); + module->Type[module->descriptor_length] = '\0'; + // +1 byte for null-terminated + } + else if ( *(data + boff / 8) == 0x02 ) { + /* Name 記述子 モジュール名(ファイル名) */ + module->descriptor_tag = getBit(data, &boff, 8); + module->descriptor_length = getBit(data, &boff, 8); + module->Name = allocCopy(data, &boff, module->descriptor_length + 1); + module->Name[module->descriptor_length] = '\0'; + } + else if ( *(data + boff / 8) == 0x03 ) { + /* Info 記述子 モジュール情報(文字型) */ + module->descriptor_tag = getBit(data, &boff, 8); + module->descriptor_length = getBit(data, &boff, 8); + boff += 24; // ISO_639_language_code + module->Info = allocCopy(data, &boff, module->descriptor_length - 3 + 1); + module->Info[module->descriptor_length] = '\0'; + } + else { + module->moduleInfo = allocCopy(data, &boff, module->moduleInfoLength); + } + } + } + + dsmbdii->privateDataLength = getBit(data, &boff, 8); + dsmbdii->privateData = allocCopy(data, &boff, dsmbdii->privateDataLength); + + return boff / 8; +} + +// a_90-with-att.pdf p35 (40/99) +int parseDSMCCbodyDDB(unsigned char *data, DSMCCbodyDDB *dsmbddb) { + int boff = 0; + + memset(dsmbddb, 0, sizeof(DSMCCbodyDDB)); + + // header + dsmbddb->protocolDiscriminator = getBit(data, &boff, 8); + dsmbddb->dsmccType = getBit(data, &boff, 8); + dsmbddb->messageId = getBit(data, &boff, 16); + dsmbddb->downloadId = getBit(data, &boff, 32); + dsmbddb->reserved1 = getBit(data, &boff, 8); + dsmbddb->adaptationLength = getBit(data, &boff, 8); + dsmbddb->messageLength = getBit(data, &boff, 16); + if ( dsmbddb->adaptationLength > 0 ) { + dsmbddb->dsmccAdaptationHeader = allocCopy(data, &boff, dsmbddb->adaptationLength); + } + + // body + dsmbddb->moduleId = getBit(data, &boff, 16); + dsmbddb->moduleVersion = getBit(data, &boff, 8); + dsmbddb->reserved2 = getBit(data, &boff, 8); + dsmbddb->blockNumber = getBit(data, &boff, 16); + dsmbddb->blockData = allocCopy(data, &boff, dsmbddb->messageLength); + + return boff / 8; +} + +void dumpDSMCC(unsigned char *ptr, int * downloadDataId, DSM_CONTROL *dsmctl) +{ + DSMCChead dsmh; + DSMCCbodyDII dsmbdii; + DSMCCbodyDDB dsmbddb; + DSMCCbodyDIIModule *module; + + int len = 0; + int i = 0; + + /* DSMCC */ + len = parseDSMCChead(ptr, &dsmh); + ptr += len; + //loop_len = dsmh.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC +/* + printf("DSMCChead=(%d:%d:%d:%d)\n", + dsmh.table_id, dsmh.section_length, + dsmh.table_id_extension, dsmh.section_number); +*/ + if ( dsmh.table_id == 0x3B ) { + len = parseDSMCCbodyDII(ptr, &dsmbdii); +#if 0 + printf("DSMCCbDII=(%d:%d:%d:%d:%d:%d) (%d:%d:%d:%d)\n", + dsmbdii.protocolDiscriminator, dsmbdii.dsmccType, + dsmbdii.messageId, dsmbdii.transaction_id, + dsmbdii.adaptationLength, dsmbdii.messageLength, + + dsmbdii.downloadId , dsmbdii.blockSize , dsmbdii.compatibilityDescriptor , + dsmbdii.numberOfModules); +#endif + for (i=0; i<dsmbdii.numberOfModules; i++) { + module = dsmbdii.modules + sizeof(DSMCCbodyDIIModule) * i; + // 0x01 Type 記述子 + // 0x02 Name 記述子 + // 0x03 Info 記述子 + if ( module->descriptor_tag == 0x01 ) { + //printf("1 %s\n", module->Type); + } + else if ( module->descriptor_tag == 0x02 ) { + //printf("2 %s\n", module->Name); + // is_bs_cs == 1 && + if ( !strncmp( module->Name, "LOGO", 4 ) ) { + //printf("%s(%d) : id = %d\n", module->Name, is_bs_cs, dsmbdii.downloadId); + *downloadDataId = dsmbdii.downloadId; + } + // なぜかBSにCSのロゴも載ってるため + // is_bs_cs == 2 && + else if ( !strncmp( module->Name, "CS_LOGO", 7 ) ) { + //printf("%s(%d) : id = %d\n", module->Name, is_bs_cs, dsmbdii.downloadId); + *downloadDataId = dsmbdii.downloadId; + } + } + else if ( module->descriptor_tag == 0x03 ) { + //printf("3 %s\n", module->Info); + } + } + } + else if ( dsmh.table_id == 0x3C ) { + len = parseDSMCCbodyDDB(ptr, &dsmbddb); + if ( *downloadDataId == dsmbddb.downloadId ) { +// if ( 33882368 == dsmbddb.downloadId ) { +// { +#if 0 + printf("DSMCCbDDB=(%d:%d:%d:%d:%d:%d) (%d:%d:%d)\n", + dsmbddb.protocolDiscriminator, dsmbddb.dsmccType, + dsmbddb.messageId, dsmbddb.downloadId, + dsmbddb.adaptationLength, dsmbddb.messageLength, + + dsmbddb.moduleId , dsmbddb.moduleVersion , dsmbddb.blockNumber); +#endif + + for (i = 0; i < 1024; i++) { + if ( dsmctl[i].isUsed == 0 ) { + // リストの終端まで来たので + //printf("moduleId=%d as dsmctl[%d]\n", dsmbddb.moduleId, i); + dsmctl[i].moduleId = dsmbddb.moduleId; + dsmctl[i].lastBlockNumber = -1; + dsmctl[i].isUsed = 1; + } + if ( dsmctl[i].moduleId == dsmbddb.moduleId ) { + if ( dsmctl[i].lastBlockNumber + 1 == dsmbddb.blockNumber ) { + dsmbddb.messageLength -= 6; // length of moduleId, moduleVersion, reserved, blockNumber + //printf("moduleId=%d as dsmctl[%d] size %d += %d\n", dsmbddb.moduleId, i, dsmctl[i].blockSize, dsmbddb.messageLength); + dsmctl[i].blockData = realloc( dsmctl[i].blockData, dsmctl[i].blockSize + dsmbddb.messageLength ); + memcpy( dsmctl[i].blockData + dsmctl[i].blockSize, dsmbddb.blockData, dsmbddb.messageLength ); + dsmctl[i].blockSize += dsmbddb.messageLength; + dsmctl[i].lastBlockNumber++; + } + else { + //printf("ignoring %d(max %d)\n", dsmbddb.blockNumber, dsmctl[i].lastBlockNumber); + } + break; + } + } + } + } + + return; +} + diff --git a/tstools/epgdump/dsmcc.h b/tstools/epgdump/dsmcc.h new file mode 100644 index 0000000..edd174d --- /dev/null +++ b/tstools/epgdump/dsmcc.h @@ -0,0 +1,103 @@ +#ifndef DSMCC_H +#define DSMCC_H 1 + +#include <stdio.h> +#include <stdlib.h> + +#include "sdt.h" +#include "util.h" +#include "ts_ctl.h" + +typedef struct _DSMCChead { + int table_id; + int section_syntax_indicator; + int complement_indicator; + int reserved1; + int section_length; + int table_id_extension; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; +} DSMCChead; +/* +typedef struct _DSMCCmsghead { + int protocolDiscriminator; + int dsmccType; + int messageId; + int transaction_id; + int reserved; + int adaptationLength; + int messageLength; + void *dsmccAdaptationHeader; +} DSMCCmsghead; +*/ +typedef struct _DSMCCbodyDIIModule { + int moduleId; + int moduleSize; + int moduleVersion; + int moduleInfoLength; + unsigned char *moduleInfo; + + int descriptor_tag; + int descriptor_length; + char *Type; + char *Name; + char *Info; +} DSMCCbodyDIIModule; + +typedef struct _DSMCCbodyDII { + int protocolDiscriminator; + int dsmccType; + int messageId; + int transaction_id; + int reserved; + int adaptationLength; + int messageLength; + void *dsmccAdaptationHeader; + + int downloadId; + int blockSize; + int windowSize; + int ackPeriod; + int tCDownloadWindow; + int tCDownloadScenario; + int compatibilityDescriptor; + int numberOfModules; + void *modules; + int privateDataLength; + void *privateData; +} DSMCCbodyDII; + +typedef struct _DSMCCbodyDDB { + int protocolDiscriminator; + int dsmccType; + int messageId; + unsigned int downloadId; + int reserved1; + int adaptationLength; + int messageLength; + void *dsmccAdaptationHeader; + + int moduleId; + int moduleVersion; + int reserved2; + int blockNumber; + void *blockData; +} DSMCCbodyDDB; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parseDSMCChead(unsigned char *data, DSMCChead *h); + int parseDSMCCbodyDDB(unsigned char *data, DSMCCbodyDDB *dsmbddb); + void dumpDSMCC(unsigned char *ptr, int *downloadDataId, DSM_CONTROL *dsmctl); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/tstools/epgdump/psi.c b/tstools/epgdump/psi.c new file mode 100644 index 0000000..c6a43ee --- /dev/null +++ b/tstools/epgdump/psi.c @@ -0,0 +1,206 @@ +// -*- tab-width:4 -*- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "psi.h" + +// 2-STD-B10v4_6.pdf p178 (190/399) +int parsePAThead(unsigned char *data, PAThead *path) { + int boff = 0; + + memset(path, 0, sizeof(PAThead)); + + path->table_id = getBit(data, &boff, 8); + path->section_syntax_indicator = getBit(data, &boff, 1); + path->zero = getBit(data, &boff, 1); + path->reserved1 = getBit(data, &boff, 2); + path->section_length = getBit(data, &boff, 12); + path->transport_stream_id = getBit(data, &boff, 16); + path->reserved2 = getBit(data, &boff, 2); + path->version_number = getBit(data, &boff, 5); + path->current_next_indicator = getBit(data, &boff, 1); + path->section_number = getBit(data, &boff, 8); + path->last_section_number = getBit(data, &boff, 8); + + return 8; +} + +int parsePATbody(unsigned char *data, PATbody *patb) { + int boff = 0; + + memset(patb, 0, sizeof(PATbody)); + + patb->program_number = getBit(data, &boff, 16); + patb->reserved = getBit(data, &boff, 3); + if ( patb->program_number == 0 ) { + patb->network_PID = getBit(data, &boff, 13); + } + else { + patb->program_map_PID = getBit(data, &boff, 13); + } + + return 4; +} + +void dumpPAT(unsigned char *ptr, SECcache *secs, int count, int *pmtpids) +{ + int len = 0; + int loop_len = 0; + int i; + + PAThead path; + PATbody patb; + + /* PAT */ + len = parsePAThead(ptr, &path); + ptr += len; + + // printf("PAT=()\n"); + + loop_len = path.section_length; + while ( loop_len > 0 ) { + len = parsePATbody(ptr, &patb); + ptr += len; + loop_len -= len; + + if ( patb.program_number != 0 ) { + for ( i = 1; i < count; i++ ) { + if ( secs[i].pid == patb.program_map_PID ) { + break; + } + if ( secs[i].pid == 0 ) { + // printf("PAT: Adding PID(0x%04x) to secs[%d]\n", patb.program_map_PID, i); + secs[i].pid = patb.program_map_PID; + break; + } + } + for ( i = 0; i < count; i++ ) { + if ( pmtpids[i] == patb.program_map_PID ) { + break; + } + if ( pmtpids[i] == 0 ) { + // printf("PAT: Adding PID(0x%04x) to pmtpids[%d]\n", patb.program_map_PID, i); + pmtpids[i] = patb.program_map_PID; + break; + } + } + } + } + + return; +} + +// 2-STD-B10v4_6.pdf p180 (192/399( +int parsePMThead(unsigned char *data, PMThead *pmth) { + int boff = 0; + + memset(pmth, 0, sizeof(PMThead)); + + pmth->table_id = getBit(data, &boff, 8); + pmth->section_syntax_indicator = getBit(data, &boff, 1); + pmth->zero = getBit(data, &boff, 1); + pmth->reserved1 = getBit(data, &boff, 2); + pmth->section_length = getBit(data, &boff, 12); + pmth->program_number = getBit(data, &boff, 16); + pmth->reserved2 = getBit(data, &boff, 2); + pmth->version_number = getBit(data, &boff, 5); + pmth->current_next_indicator = getBit(data, &boff, 1); + pmth->section_number = getBit(data, &boff, 8); + pmth->last_section_number = getBit(data, &boff, 8); + pmth->reserved3 = getBit(data, &boff, 3); + pmth->PCR_PID = getBit(data, &boff, 13); + pmth->reserved4 = getBit(data, &boff, 4); + pmth->program_info_length = getBit(data, &boff, 12); + + return 12; +} + +int parsePMTbody(unsigned char *data, PMTbody *pmtb) { + int boff = 0; + + memset(pmtb, 0, sizeof(PMTbody)); + + pmtb->stream_type = getBit(data, &boff, 8); + pmtb->reserved1 = getBit(data, &boff, 3); + pmtb->elementary_PID = getBit(data, &boff, 13); + pmtb->reserved2 = getBit(data, &boff, 4); + pmtb->ES_info_length = getBit(data, &boff, 12); + + return 5; +} + +void dumpPMT(unsigned char *ptr, SECcache *secs, int count, int *dsmccpids) +{ + int len = 0; + int loop_len = 0; + int desc_len = 0; + int i; + + PMThead pmth; + PMTbody pmtb; + + /* PMT */ + len = parsePMThead(ptr, &pmth); + ptr += len; +/* + printf("PMT=(%d:%d:%d:%d:%d:%d:%d:%d)\n", + pmth.table_id, pmth.section_length , + pmth.program_number , pmth.version_number , + pmth.section_number , pmth.last_section_number , + pmth.PCR_PID , pmth.program_info_length); +*/ + loop_len = pmth.program_info_length; + while ( loop_len > 0 ) { + len = parseOTHERdesc(ptr); + ptr += len; + loop_len -= len; + } + + loop_len = pmth.section_length - pmth.program_info_length - 13;// 9はヘッダ長 4はCRC + while ( loop_len > 0 ) { + len = parsePMTbody(ptr, &pmtb); + ptr += len; + loop_len -= len; +/* + printf("PMTb=(0x%x:%d:%d)\n", + pmtb.stream_type , pmtb.elementary_PID , pmtb.ES_info_length); +*/ + // 2-STD-B24v5_4-3p3.pdf p11 (25/125) + if ( pmtb.stream_type == 0x0B || pmtb.stream_type == 0x0D ) { + for ( i = 1; i < count; i++ ) { + if ( secs[i].pid == pmtb.elementary_PID ) { + break; + } + if ( secs[i].pid == 0 ) { + //printf("PMT: Adding PID(0x%04x) to secs[%d]\n", pmtb.elementary_PID, i); + secs[i].pid = pmtb.elementary_PID; + break; + } + } + for ( i = 0; i < count; i++ ) { + if ( dsmccpids[i] == pmtb.elementary_PID ) { + break; + } + if ( dsmccpids[i] == 0 ) { + //printf("PMT: Adding PID(0x%04x) to dsmccpids[%d]\n", pmtb.elementary_PID, i); + dsmccpids[i] = pmtb.elementary_PID; + break; + } + } + } + + desc_len = pmtb.ES_info_length; + loop_len -= desc_len; + + while ( desc_len > 0 ) { + len = parseOTHERdesc(ptr); + ptr += len; + desc_len -= len; + } + } + + return; +} + diff --git a/tstools/epgdump/psi.h b/tstools/epgdump/psi.h new file mode 100644 index 0000000..fa00c1d --- /dev/null +++ b/tstools/epgdump/psi.h @@ -0,0 +1,71 @@ +#ifndef PSI_H +#define PSI_H 1 + +#include <stdio.h> +#include <stdlib.h> + +#include "ts.h" +#include "util.h" + +typedef struct _PAThead { + unsigned char table_id; + int section_syntax_indicator; + int zero; + int reserved1; + int section_length; + int transport_stream_id; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; +} PAThead; + +typedef struct _PATbody { + int program_number; + int reserved; + int network_PID; + int program_map_PID; +} PATbody; + +typedef struct _PMThead { + int table_id; + int section_syntax_indicator; + int zero; + int reserved1; + int section_length; + int program_number; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; + int reserved3; + int PCR_PID; + int reserved4; + int program_info_length; +} PMThead; + +typedef struct _PMTbody { + int stream_type; + int reserved1; + int elementary_PID; + int reserved2; + int ES_info_length; +} PMTbody; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parsePAThead(unsigned char *data, PAThead *path); + int parsePATbody(unsigned char *data, PATbody *patb); + void dumpPAT(unsigned char *ptr, SECcache *secs, int count, int *pmtpids); + void dumpPMT(unsigned char *ptr, SECcache *secs, int count, int *dsmccpids); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/tstools/epgdump/sdtt.c b/tstools/epgdump/sdtt.c new file mode 100644 index 0000000..eeeecbd --- /dev/null +++ b/tstools/epgdump/sdtt.c @@ -0,0 +1,290 @@ +// -*- tab-width:4 -*- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "sdtt.h" +#include "ts_ctl.h" +#include "clt2png.h" + +// STD-B21 p130 (144) +int parseSDTThead(unsigned char *data, SDTThead *h) { + int boff = 0; + + memset(h, 0, sizeof(SDTThead)); + + h->table_id = getBit(data, &boff, 8); + h->section_syntax_indicator = getBit(data, &boff, 1); + h->reserved_future_use1 = getBit(data, &boff, 1); + h->reserved1 = getBit(data, &boff, 2); + h->section_length = getBit(data, &boff, 12); + h->maker_id = getBit(data, &boff, 8); + h->model_id = getBit(data, &boff, 8); + // boff -= 16; + // h->table_id_ext = getBit(data, &boff, 16); + h->reserved2 = getBit(data, &boff, 2); + h->version_number = getBit(data, &boff, 5); + h->current_next_indicator = getBit(data, &boff, 1); + h->section_number = getBit(data, &boff, 8); + h->last_section_number = getBit(data, &boff, 8); + h->transport_stream_id = getBit(data, &boff, 16); + h->original_network_id = getBit(data, &boff, 16); + h->service_id = getBit(data, &boff, 16); + h->num_of_contents = getBit(data, &boff, 8); + + return 15; +} + +// STD-B21 p130 (144) +int parseSDTTcont(unsigned char *data, SDTTcont *sdtc) { + int boff = 0; + + memset(sdtc, 0, sizeof(SDTTcont)); + sdtc->group = getBit(data, &boff, 4); + sdtc->target_version = getBit(data, &boff, 12); + sdtc->new_version = getBit(data, &boff, 12); + sdtc->download_level = getBit(data, &boff, 2); + sdtc->version_indicator = getBit(data, &boff, 2); + sdtc->content_description_length = getBit(data, &boff, 12); + sdtc->reserved1 = getBit(data, &boff, 4); + sdtc->schedule_description_length = getBit(data, &boff, 12); + sdtc->schedule_timeshift_information = getBit(data, &boff, 4); + /* + for (i=0; i<sdtc->schedule_description_length / 8; i++) { + sdtc->start_time = getBit(data, &boff, 40); + sdtc->duration = getBit(data, &boff, 24); + } + */ + + return sdtc->schedule_description_length + 8; + //return sdtc->content_description_length + 8; +} + +// STD-B21 p132 (146) +int parseSDTTdesc(unsigned char *data, SDTTdesc *sdts) { +// 0xC9(201) + int boff = 0; + int i = 0; + SDTTdescModule *module; + + memset(sdts, 0, sizeof(SDTTdesc)); + sdts->descriptor_tag = getBit(data, &boff, 8); + sdts->descriptor_length = getBit(data, &boff, 8); + sdts->reboot = getBit(data, &boff, 1); + sdts->add_on = getBit(data, &boff, 1); + sdts->compatibility_flag = getBit(data, &boff, 1); + sdts->module_info_flag = getBit(data, &boff, 1); + sdts->text_info_flag = getBit(data, &boff, 1); + sdts->reserved1 = getBit(data, &boff, 3); + sdts->component_size = getBit(data, &boff, 32); + sdts->download_id = getBit(data, &boff, 32); + sdts->time_out_value_DII = getBit(data, &boff, 32); + sdts->leak_rate = getBit(data, &boff, 22); + sdts->reserved2 = getBit(data, &boff,2); + sdts->component_tag = getBit(data, &boff, 8); + + if ( sdts->compatibility_flag == 1) { + sdts->compatibility_length = getBit(data, &boff, 16); + boff += sdts->compatibility_length * 8; + } + if ( sdts->module_info_flag == 1) { + sdts->num_of_modules = getBit(data, &boff, 16); + + if ( sdts->num_of_modules > 0 ) + sdts->modules = calloc(1, sizeof(SDTTdescModule) * ( sdts->num_of_modules + 1 )); + + for (i=0; i<sdts->num_of_modules; i++) { + module = sdts->modules + sizeof(SDTTdescModule) * i;// &sdts->modules[i]; + module->module_id = getBit(data, &boff, 16); + module->module_size = getBit(data, &boff, 32); + module->module_info_length = getBit(data, &boff, 8); + if ( *(data + boff / 8) == 0x01 ) { + /* Type 記述子 モジュールの型(MIME 形式等) */ + module->descriptor_tag = getBit(data, &boff, 8); + module->descriptor_length = getBit(data, &boff, 8); + module->Type = allocCopy(data, &boff, module->descriptor_length); + module->Type[module->descriptor_length] = '\0'; + // +1 byte for null-terminated + } + else if ( *(data + boff / 8) == 0x02 ) { + /* Name 記述子 モジュール名(ファイル名) */ + module->descriptor_tag = getBit(data, &boff, 8); + module->descriptor_length = getBit(data, &boff, 8); + module->Name = allocCopy(data, &boff, module->descriptor_length); + module->Name[module->descriptor_length] = '\0'; + } + else if ( *(data + boff / 8) == 0x03 ) { + /* Info 記述子 モジュール情報(文字型) */ + module->descriptor_tag = getBit(data, &boff, 8); + module->descriptor_length = getBit(data, &boff, 8); + boff += 24; // ISO_639_language_code + module->Info = allocCopy(data, &boff, module->descriptor_length - 3); + module->Info[module->descriptor_length] = '\0'; + } + else { + module->module_info_byte = allocCopy(data, &boff, module->module_info_length); + } + } + } + sdts->private_data_length = getBit(data, &boff, 8); + sdts->private_data_byte = allocCopy(data, &boff, sdts->private_data_length); + if ( sdts->text_info_flag == 1) { + sdts->ISO_639_language_code = getBit(data, &boff, 24); + sdts->text_length = getBit(data, &boff, 8); + getStr(sdts->text_char, data, &boff, sdts->text_length); + //sdts->text_char = allocCopy(data, &boff, sdts->text_length); + } + + return boff / 8; +} + +// STD-B21 p193 (209) +int parseSDTTdata(unsigned char *data, SDTTdata *sdtd) { + int boff = 0, i, j; + SDTTdataLoop *loop; + SDTTdataService *service; + + memset(sdtd, 0, sizeof(SDTTdata)); + + sdtd->logo_type = getBit(data, &boff, 8); + sdtd->number_of_loop = getBit(data, &boff, 16); + sdtd->loop = calloc(1, ( sizeof(SDTTdataLoop) + 5000 ) * sdtd->number_of_loop); + + for (i=0; i<sdtd->number_of_loop; i++) { + loop = sdtd->loop + sizeof(SDTTdataLoop) * i; + + loop->reserved_future_use1 = getBit(data, &boff, 7); + loop->logo_id = getBit(data, &boff, 9); + loop->number_of_services = getBit(data, &boff, 8); + loop->services = calloc(1, ( sizeof(SDTTdataService) + 5000 )* loop->number_of_services); + + for (j=0; j<loop->number_of_services; j++) { + service = loop->services + sizeof(SDTTdataService) * j; + service->original_network_id = getBit(data, &boff, 16); + service->transport_stream_id = getBit(data, &boff, 16); + service->service_id = getBit(data, &boff, 16); + } + loop->data_size = getBit(data, &boff, 16); + loop->data = allocCopy(data, &boff, loop->data_size); + } + + return boff / 8; +} + +void dumpSDTT(unsigned char *ptr, STATION *station, int station_count) +{ + SDTThead sdth; + SDTTcont sdtc; + SDTTdesc sdts; + SDTTdata sdtd; + SDTTdescModule *module; + + int len = 0; + int loop_len = 0; + int desc_len = 0; + int i, j; + + /* SDTT */ + len = parseSDTThead(ptr, &sdth); + ptr += len; + loop_len = sdth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC + + /* + printf("SDTT=(%d:%d:%d:%d:%d:%d:%d:%d:%d:%d)\n", + sdth.table_id, sdth.section_number, sdth.version_number, + sdth.maker_id, sdth.model_id, + sdth.transport_stream_id, sdth.original_network_id, + sdth.service_id, sdth.num_of_contents, sdth.section_length); + */ + + if ( sdth.maker_id == 0xff && sdth.model_id == 0xfe ) + printf("BS FOUND\n"); + + if ( sdth.maker_id == 0xff && sdth.model_id == 0xfc ) + printf("BS/広帯域 CS FOUND\n"); + + if ( ! ( sdth.maker_id == 0xff && ( sdth.model_id == 0xfc || sdth.model_id == 0xfe ) ) ) + return; + + while(loop_len > 0) { + /* + logo_type + 0x00 24x48 864 SD4:3 スモール + 0x01 24x36 648 SD16:9 スモール + 0x02 27x48 972 HD スモール + 0x03 36x72 1296 SD4:3 ラージ + 0x04 36x54 972 SD16:9 ラージ + 0x05 36x64 1152 HD ラージ + */ + + for (i=0; i<sdth.num_of_contents; i++) { + len = parseSDTTcont(ptr, &sdtc); + ptr += len; + loop_len -= len; + + desc_len = sdtc.content_description_length - sdtc.schedule_description_length; + loop_len -= desc_len; + + while(desc_len > 0) { + if ( *ptr != 0xC9 ) { + len = parseOTHERdesc(ptr); + ptr += len; + desc_len -= len; + continue; + } + + len = parseSDTTdesc(ptr, &sdts); + ptr += len; + desc_len -= len; +#if 0 + printf("SDTTdesc %d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%s\n", + sdts.descriptor_tag, sdts.descriptor_length, + sdts.reboot, sdts.add_on, + sdts.compatibility_flag, sdts.module_info_flag, sdts.text_info_flag, + sdts.component_size, sdts.download_id, sdts.time_out_value_DII, + sdts.leak_rate, sdts.component_tag, + sdts.text_info_flag ? sdts.text_char : ""); +#endif + for (i=0; i<sdts.num_of_modules; i++) { + module = sdts.modules + sizeof(SDTTdescModule) * i; + if ( module->descriptor_tag == 0x01 ) { + printf("sdts.Type %s id:%d\n", module->Type, sdts.download_id); + } + else if ( module->descriptor_tag == 0x02 ) { + printf("sdts.Name %s id:%d\n", module->Name, sdts.download_id); + + if ( strstr( module->Name, "CS_LOGO" ) ) { + //station[0].logo_download_data_id = sdts.download_id; + } + else if ( strstr( module->Name, "LOGO" ) ) { + station[0].logo_download_data_id = sdts.download_id; + } + } + else if ( module->descriptor_tag == 0x03 ) { + printf("sdts.Info %s id:%d\n", module->Info, sdts.download_id); + } + else { + printf("MIB: %s\n", module->module_info_byte); + } + } +/* + len = parseSDTTdata(ptr, &sdtd); + ptr += len; + desc_len -= len; +*/ +#if 0 + printf("SDTT=(%d:%d:%d:%d:%d:%dbyte:desc%dbyte)%d,%d,%d,%d\n", + cdth.table_id, cdth.download_data_id, cdth.version_number, + cdth.original_network_id, cdth.data_type, + cdth.section_length, cdth.descriptors_loop_length, + + sdtdte.logo_type, sdtdte.logo_id, sdtdte.logo_version, + sdtdte.data_size); +#endif + } + } + } + return; +} + diff --git a/tstools/epgdump/sdtt.h b/tstools/epgdump/sdtt.h new file mode 100644 index 0000000..65eaad9 --- /dev/null +++ b/tstools/epgdump/sdtt.h @@ -0,0 +1,115 @@ +#ifndef SDTT_H +#define SDTT_H 1 + +#include <stdio.h> +#include <stdlib.h> + +#include "sdt.h" +#include "util.h" +#include "ts_ctl.h" + +typedef struct _SDTThead { + unsigned char table_id; + int section_syntax_indicator; + int reserved_future_use1; + int reserved1; + int section_length; + int maker_id; + int model_id; +// int table_id_ext; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; + int transport_stream_id; + int original_network_id; + int service_id; + int num_of_contents; +} SDTThead; + +typedef struct _SDTTcont { + int group; + int target_version; + int new_version; + int download_level; + int version_indicator; + int content_description_length; + int reserved1; + int schedule_description_length; + int schedule_timeshift_information; +} SDTTcont; + +typedef struct _SDTTdescModule { + int module_id; + int module_size; + int module_info_length; + void *module_info_byte; + int descriptor_tag; + int descriptor_length; + char *Type; + char *Name; + char *Info; +} SDTTdescModule; + +typedef struct _SDTTdesc { + int descriptor_tag; + int descriptor_length; + int reboot; + int add_on; + int compatibility_flag; + int compatibility_length; + int module_info_flag; + int text_info_flag; + int reserved1; + int component_size; + unsigned int download_id; + int time_out_value_DII; + int leak_rate; + int reserved2; + int component_tag; + int num_of_modules; + void *modules; + int private_data_length; + void *private_data_byte; + int ISO_639_language_code; + int text_length; + //void *text_char; + char text_char; +} SDTTdesc; + +typedef struct _SDTTdataService { + int original_network_id; + int transport_stream_id; + int service_id; +} SDTTdataService; + +typedef struct _SDTTdataLoop { + int reserved_future_use1; + int logo_id; + int number_of_services; + SDTTdataService *services; + int data_size; + void *data; +} SDTTdataLoop; + +typedef struct _SDTTdataBC { + int logo_type; + int number_of_loop; + SDTTdataLoop *loop; +} SDTTdata; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parseSDTThead(unsigned char *data, SDTThead *h); + int parseSDTTdesc(unsigned char *data, SDTTdesc *sdts); + void dumpSDTT(unsigned char *ptr, STATION *station, int station_count); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/tstools/epgdump/tags b/tstools/epgdump/tags new file mode 100644 index 0000000..5f87182 --- /dev/null +++ b/tstools/epgdump/tags @@ -0,0 +1,113 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.7 // +AribToString aribstr.c /^int AribToString($/;" f +AribToStringInternal aribstr.c /^const DWORD AribToStringInternal(TCHAR *lpszDst, $/;" f +BYTE aribstr.c 28;" d file: +CAT_COUNT epgdump.c 18;" d file: +CODE_ADDITIONAL_SYMBOLS aribstr.c 24;" d file: +CODE_ALPHANUMERIC aribstr.c 11;" d file: +CODE_HIRAGANA aribstr.c 12;" d file: +CODE_JIS_KANJI_PLANE_1 aribstr.c 22;" d file: +CODE_JIS_KANJI_PLANE_2 aribstr.c 23;" d file: +CODE_JIS_X0201_KATAKANA aribstr.c 21;" d file: +CODE_KANJI aribstr.c 10;" d file: +CODE_KATAKANA aribstr.c 13;" d file: +CODE_MOSAIC_A aribstr.c 14;" d file: +CODE_MOSAIC_B aribstr.c 15;" d file: +CODE_MOSAIC_C aribstr.c 16;" d file: +CODE_MOSAIC_D aribstr.c 17;" d file: +CODE_PROP_ALPHANUMERIC aribstr.c 18;" d file: +CODE_PROP_HIRAGANA aribstr.c 19;" d file: +CODE_PROP_KATAKANA aribstr.c 20;" d file: +CODE_SET aribstr.c 36;" d file: +CODE_UNKNOWN aribstr.c 9;" d file: +CONTENT_TYPE epgdump.c /^}CONTENT_TYPE;$/;" t typeref:struct:_ContentTYPE file: +CalcCrc ts.c /^unsigned int CalcCrc(unsigned int crc, unsigned char *buf, int len) {$/;" f +Category epgdump.c /^char Category[1024];$/;" v +ContentCatList epgdump.c /^static CONTENT_TYPE ContentCatList[CAT_COUNT] = {$/;" v file: +DWORD aribstr.c 30;" d file: +DesignationDRCS aribstr.c /^const bool DesignationDRCS(const BYTE byIndexG, const BYTE byCode)$/;" f +DesignationGSET aribstr.c /^const bool DesignationGSET(const BYTE byIndexG, const BYTE byCode)$/;" f +GetEIT epgdump.c /^void GetEIT(FILE *infile, FILE *outfile, SVT_CONTROL *svtcur, SECcache *secs, int count)$/;" f +GetSDT epgdump.c /^void GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, int count)$/;" f +LockingShiftGL aribstr.c /^void LockingShiftGL(const BYTE byIndexG)$/;" f +LockingShiftGR aribstr.c /^void LockingShiftGR(const BYTE byIndexG)$/;" f +ProcessCharCode aribstr.c /^const DWORD ProcessCharCode(TCHAR *lpszDst, const WORD wCode, const CODE_SET CodeSet)$/;" f +ProcessEscapeSeq aribstr.c /^void ProcessEscapeSeq(const BYTE byCode)$/;" f +PutAlphanumericChar aribstr.c /^const DWORD PutAlphanumericChar(TCHAR *lpszDst, const WORD wCode)$/;" f +PutHiraganaChar aribstr.c /^const DWORD PutHiraganaChar(TCHAR *lpszDst, const WORD wCode)$/;" f +PutJisKatakanaChar aribstr.c /^const DWORD PutJisKatakanaChar(TCHAR *lpszDst, const WORD wCode)$/;" f +PutKanjiChar aribstr.c /^const DWORD PutKanjiChar(TCHAR *lpszDst, const WORD wCode)$/;" f +PutKatakanaChar aribstr.c /^const DWORD PutKatakanaChar(TCHAR *lpszDst, const WORD wCode)$/;" f +PutSymbolsChar aribstr.c /^const DWORD PutSymbolsChar(TCHAR *lpszDst, const WORD wCode)$/;" f +SECCOUNT epgdump.c 140;" d file: +STATION epgdump.c /^} STATION;$/;" t typeref:struct:_TAG_STATION file: +ServiceName epgdump.c /^char ServiceName[1024];$/;" v +SingleShiftGL aribstr.c /^void SingleShiftGL(const BYTE byIndexG)$/;" f +TCHAR aribstr.c 27;" d file: +TEXT aribstr.c 34;" d file: +WORD aribstr.c 29;" d file: +_ContentTYPE epgdump.c /^typedef struct _ContentTYPE{$/;" s file: +_T aribstr.c 35;" d file: +_TAG_STATION epgdump.c /^typedef struct _TAG_STATION$/;" s file: +abCharSizeTable aribstr.c /^static const bool abCharSizeTable[] =$/;" v file: +bool aribstr.c 31;" d file: +bsSta epgdump.c /^static STATION bsSta[] = {$/;" v file: +bsSta xmldata.c /^static STATION bsSta[] = {$/;" v file: +bsStaCount epgdump.c /^static int bsStaCount = sizeof(bsSta) \/ sizeof (STATION);$/;" v file: +bsStaCount xmldata.c /^static int bsStaCount = sizeof(bsSta) \/ sizeof (STATION);$/;" v file: +cd epgdump.c /^iconv_t cd ;$/;" v +checkEEVTDitem eit.c /^int checkEEVTDitem(EEVTDitem *save, EEVTDitem *new, int descriptor_number) {$/;" f +checkcrc ts.c /^int checkcrc(SECcache *secs) {$/;" f +convertjis aribstr.c /^WORD convertjis(DWORD jiscode) {$/;" f +csSta epgdump.c /^static STATION csSta[] = {$/;" v file: +csSta xmldata.c /^static STATION csSta[] = {$/;" v file: +csStaCount epgdump.c /^static int csStaCount = sizeof(csSta) \/ sizeof (STATION);$/;" v file: +csStaCount xmldata.c /^static int csStaCount = sizeof(csSta) \/ sizeof (STATION);$/;" v file: +dumpEIT eit.c /^void dumpEIT(unsigned char *ptr, int serv_id, int original_network_id, int transport_stream_id, EIT_CONTROL *eittop)$/;" f +dumpSDT sdt.c /^void dumpSDT(unsigned char *ptr, SVT_CONTROL *top)$/;" f +english epgdump.c /^ char *english ;$/;" m struct:_ContentTYPE file: +enqueue eit.c /^void enqueue(EIT_CONTROL *top, EIT_CONTROL *eitptr)$/;" f +enqueue_sdt sdt.c /^void enqueue_sdt(SVT_CONTROL *top, SVT_CONTROL *sdtptr)$/;" f +false aribstr.c 33;" d file: +getBit util.c /^int getBit(unsigned char *byte, int *pbit, int gbit) {$/;" f +getStr util.c /^void getStr(char *tostr, unsigned char *byte, int *pbit, int len) {$/;" f +japanese epgdump.c /^ char *japanese ;$/;" m struct:_ContentTYPE file: +m_CodeG aribstr.c /^static int m_CodeG[4];$/;" v file: +m_bIsEscSeqDrcs aribstr.c /^static bool m_bIsEscSeqDrcs;$/;" v file: +m_byEscSeqCount aribstr.c /^static BYTE m_byEscSeqCount;$/;" v file: +m_byEscSeqIndex aribstr.c /^static BYTE m_byEscSeqIndex;$/;" v file: +m_pLockingGL aribstr.c /^static int *m_pLockingGL;$/;" v file: +m_pLockingGR aribstr.c /^static int *m_pLockingGR;$/;" v file: +m_pSingleGL aribstr.c /^static int *m_pSingleGL;$/;" v file: +main epgdump.c /^int main(int argc, char *argv[])$/;" f +name epgdump.c /^ char *name;$/;" m struct:_TAG_STATION file: +onId epgdump.c /^ int onId; \/\/ TransportStreamID$/;" m struct:_TAG_STATION file: +ontv epgdump.c /^ char *ontv;$/;" m struct:_TAG_STATION file: +parseContentDesc eit.c /^int parseContentDesc(unsigned char *data, ContentDesc *desc) {$/;" f +parseEEVTDhead eit.c /^int parseEEVTDhead(unsigned char *data, EEVTDhead *desc) {$/;" f +parseEEVTDitem eit.c /^int parseEEVTDitem(unsigned char *data, EEVTDitem *desc) {$/;" f +parseEEVTDtail eit.c /^int parseEEVTDtail(unsigned char *data, EEVTDtail *desc) {$/;" f +parseEITbody eit.c /^int parseEITbody(unsigned char *data, EITbody *b) {$/;" f +parseEIThead eit.c /^int parseEIThead(unsigned char *data, EIThead *h) {$/;" f +parseOTHERdesc util.c /^int parseOTHERdesc(unsigned char *data) {$/;" f +parseSDTbody sdt.c /^int parseSDTbody(unsigned char *data, SDTbody *b) {$/;" f +parseSDThead sdt.c /^int parseSDThead(unsigned char *data, SDThead *h) {$/;" f +parseSEVTdesc eit.c /^int parseSEVTdesc(unsigned char *data, SEVTdesc *desc) {$/;" f +parseSVCdesc sdt.c /^int parseSVCdesc(unsigned char *data, SVCdesc *desc) {$/;" f +parseSeriesDesc eit.c /^int parseSeriesDesc(unsigned char *data, SeriesDesc *desc) {$/;" f +readTS ts.c /^SECcache *readTS(FILE *in, SECcache secs[], int size) {$/;" f +searcheit eit.c /^EIT_CONTROL *searcheit(EIT_CONTROL *top, int servid, int eventid)$/;" f +serachid sdt.c /^int serachid(SVT_CONTROL *top, int service_id)$/;" f +subtitle epgdump.c /^char subtitle[1024];$/;" v +svId epgdump.c /^ int svId; \/\/ ServiceID$/;" m struct:_TAG_STATION file: +svttop epgdump.c /^SVT_CONTROL *svttop = NULL;$/;" v +timecmp eit.c /^void timecmp(int *thh, int *tmm, int *tss,$/;" f +title epgdump.c /^char title[1024];$/;" v +true aribstr.c 32;" d file: +tsId epgdump.c /^ int tsId; \/\/ OriginalNetworkID$/;" m struct:_TAG_STATION file: +xmlspecialchars epgdump.c /^void xmlspecialchars(char *str)$/;" f diff --git a/tstools/epgdump/tot.c b/tstools/epgdump/tot.c new file mode 100644 index 0000000..a0d5948 --- /dev/null +++ b/tstools/epgdump/tot.c @@ -0,0 +1,69 @@ +// -*- tab-width:4 -*- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "tot.h" +#include "ts_ctl.h" + +int parseTOThead(unsigned char *data, TOThead *toth) { + int boff = 0; + + memset(toth, 0, sizeof(TOThead)); + + toth->table_id = getBit(data, &boff, 8); + toth->section_syntax_indicator = getBit(data, &boff, 1); + toth->reserved_future_use1 = getBit(data, &boff, 1); + toth->reserved1 = getBit(data, &boff, 2); + toth->section_length = getBit(data, &boff, 12); + memcpy(toth->JST_time, data + boff / 8, 5); + boff += 40; + // toth->JST_time = getBit(data, &boff, 40); + toth->reserved2 = getBit(data, &boff, 4); + toth->descriptors_loop_length = getBit(data, &boff, 12); + + return 10; +} + +int parseTOTdesc(unsigned char *data, TOTdesc *totd) { + int boff = 0; + + memset(totd, 0, sizeof(TOTdesc)); + + totd->descriptor_tag = getBit(data, &boff, 8); + totd->descriptor_length = getBit(data, &boff, 8); + + return totd->descriptor_length + 2; +} + +void dumpTOT(unsigned char *ptr) +{ + TOThead toth; + TOTdesc totd; + + int len = 0; + int loop_len = 0; + int desc_len = 0; + time_t tot; + + /* TOT */ + len = parseTOThead(ptr, &toth); + ptr += len; + loop_len = toth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC + + tot = parseMJD( toth.JST_time ); + printf("TOT diff:%d[秒] %s", + (int)difftime( time(NULL), tot ), ctime(&tot)); + //ptm = localtime(time(NULL)); +/* + desc_len = toth.descriptors_loop_length; + while(desc_len > 0) { + len = parseTOTdesc(ptr, &totd); + ptr += len; + desc_len -= len; + } +*/ + return; +} + diff --git a/tstools/epgdump/tot.h b/tstools/epgdump/tot.h new file mode 100644 index 0000000..4699370 --- /dev/null +++ b/tstools/epgdump/tot.h @@ -0,0 +1,38 @@ +#ifndef TOT_H +#define TOT_H 1 + +#include <stdio.h> +#include <stdlib.h> + +#include "util.h" +#include "ts_ctl.h" + +typedef struct _TOThead { + unsigned char table_id; + int section_syntax_indicator; + int reserved_future_use1; + int reserved1; + int section_length; + unsigned char JST_time[5]; + int reserved2; + int descriptors_loop_length; +} TOThead; + +typedef struct _TOTdesc { + unsigned char descriptor_tag; + int descriptor_length; +} TOTdesc; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parseTOThead(unsigned char *data, TOThead *toth); + int parseTOTdesc(unsigned char *data, TOTdesc *totd); + void dumpTOT(unsigned char *ptr); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif