Skip to content

Instantly share code, notes, and snippets.

@ranlix
ranlix / DRM_live.py
Last active August 29, 2015 13:57
将包含一个DRM视频文件转换为live流(播放列表无限循环)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Created on 2013-4-23
@author: xweiyan
@modify by Ran
version 2.0
main change:
1.add counter
2.sequence automatic increase
@ranlix
ranlix / DRM_nts.py
Last active August 29, 2015 13:57
当前的nts脚本无法满足内网所需现有的DRM streaming转化成nts流的需求,因为key的结构不一样,所以在原有的脚本基础上添加了提取key的函数(txt2keyList),更新将key写入m3u8文件的算法
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import sys
import shutil
import string
import tempfile
import time
from hls import load, parser
@ranlix
ranlix / threading_demo.py
Created March 14, 2014 09:41
初尝多线程:目标成果:打印a,b,c ——sleep(1)——打印a,b,c——sleep(1)——打印a,b,c……当前的结果还是有问题的
import threading
import time
# x = 0
def write(text):
# global x
lock.acquire()
while 1:
@ranlix
ranlix / YearMonthDay.py
Created March 5, 2014 03:05
datetime 和calendar 模块里没有直接可以查询到某一个月份总天数等,就写了一个YearMonthDay的class,方便以后调用
# -*- coding:utf-8 -*-
#!/usr/bin/python
import re
import math
import time
import os
import csv
import sys
import datetime
@ranlix
ranlix / combineTS.py
Last active July 15, 2018 09:45
将同一目录下所有.ts文件合并到一个新的.ts文件(PS: .ts文件是可以直接合并的视频文件,因此可以这样合并)
# -*-coding: utf-8 -*-
import sys
import os
num = sys.argv[1] # num is the amount of *.ts files
def add(x):
"""'x' is the amount of *.ts
This function should add all other .ts combined into '1.ts'
@ranlix
ranlix / log2csv.py
Last active December 31, 2015 05:49
同事要处理一个较大数据的log,提取里面的关键字,生成一个csv文件,来进行视频切换时候播放器的性能是否达标,每行的数据依次为:Stop | Close | Open | Run | VideoRenderStart | VideoStopBuff.
# -*- coding:utf-8 -*-
import re
import os
import csv
import sys
log_file = sys.argv[1]
# log_file = r"csv.log"
# csv_content = []
@ranlix
ranlix / RepeatAll.py
Last active December 31, 2015 00:29
因为要将一个hls文件的本地文件给做出live(类似于播放列表.m3u8无限循环)的效果, 就用一个list来demo一下
# -*-coding:utf-8 -*-
import time
def ListRepeat(list, duration):
"""
call ListRepeat(list, duration), result should be like below:
['0', '1', '2', '3', '4', '5']
['1', '2', '3', '4', '5', '6']
['2', '3', '4', '5', '6', '7']
@ranlix
ranlix / hevc_get.py
Created December 3, 2013 08:11
一个外网的hls文件(.m3u8), 现在需要把其中包含的所有的url的ts文件全部下下来,顺便重命名,并且创建本地的播放列表(m3u8),里面的绝对路径的url替换成刚刚下载的新的本地的ts文件名
# -*- coding:utf-8 -*-
import os
url_counter = 1
file_will_opened = sys.argv[1]
m3u8_content = open(file_will_opened, "r")
new_file = open("hevc.m3u8", "wb")
@ranlix
ranlix / cfg_create.py
Last active December 28, 2015 18:28
工作需要,每个库文件都需要生成单独的cfg文件,并且需要筛选目录下存在的库文件,对比文档里的库文件对应的id,生成内容为“id,4(level)”的cfg文件。 注:这次是在sublime Text2里添加了PEP8的插件,从此开始注重编码规范
# -*-coding:utf-8 -*-
import os
path = r"C:\Users\alex\Desktop\debug"
original_file = open(r"module.txt", "r") # read file
content = original_file.readlines()
def lib_list_without_so(yourdir):
""" Create a list which contains all the libs without '.so'
@ranlix
ranlix / Guess_the_number.py
Last active December 27, 2015 18:39
An Introduction to Interactive Programming in Python ——Guess the number!
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
import simplegui
import random
import math
# initialize global variables used in your code
num_range = 0
num_guess = 0