|
@@ -0,0 +1,78 @@
|
|
|
+import csv
|
|
|
+import requests
|
|
|
+import subprocess
|
|
|
+
|
|
|
+
|
|
|
+def get_filesize(url):
|
|
|
+ try:
|
|
|
+ response = requests.head(url, allow_redirects=True)
|
|
|
+ if response.status_code == 200:
|
|
|
+ content_length = response.headers.get('Content-Length')
|
|
|
+ return int(content_length) if content_length else None
|
|
|
+ print(f"Error: HTTP {response.status_code} for {url}")
|
|
|
+ return None
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error getting filesize for {url}: {e}")
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
+def get_bitrate(url):
|
|
|
+ try:
|
|
|
+ cmd = [
|
|
|
+ 'ffprobe',
|
|
|
+ '-v', 'error',
|
|
|
+ '-select_streams', 'v:0',
|
|
|
+ '-show_entries', 'stream=bit_rate',
|
|
|
+ '-of', 'default=noprint_wrappers=1:nokey=1',
|
|
|
+ url
|
|
|
+ ]
|
|
|
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, timeout=30)
|
|
|
+ bit_rate = output.decode().strip()
|
|
|
+ return int(bit_rate) if bit_rate else None
|
|
|
+ except subprocess.CalledProcessError as e:
|
|
|
+ print(f"ffprobe error for {url}: {e.output.decode().strip()}")
|
|
|
+ return None
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error getting bitrate for {url}: {e}")
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
+def process_csv(csv_file):
|
|
|
+ bitrate_counter = 0
|
|
|
+ filesize_counter = 0
|
|
|
+
|
|
|
+ with open(csv_file, 'r') as file:
|
|
|
+ reader = csv.DictReader(file)
|
|
|
+ for row in reader:
|
|
|
+ url1, url2 = row['path_264'], row['path_265']
|
|
|
+
|
|
|
+ url1 = "http://visionularcdn.yishihui.com/" + url1
|
|
|
+ url2 = "http://vcdn.yishihui.com/" + url2
|
|
|
+
|
|
|
+ # 获取文件大小
|
|
|
+ size1, size2 = get_filesize(url1), get_filesize(url2)
|
|
|
+ if None in (size1, size2):
|
|
|
+ continue
|
|
|
+
|
|
|
+ # 获取码率
|
|
|
+ bitrate1, bitrate2 = get_bitrate(url1), get_bitrate(url2)
|
|
|
+ if None in (bitrate1, bitrate2):
|
|
|
+ continue
|
|
|
+
|
|
|
+ # 比较并计数
|
|
|
+ if bitrate1 > bitrate2:
|
|
|
+ bitrate_counter += 1
|
|
|
+ if size1 > size2:
|
|
|
+ filesize_counter += 1
|
|
|
+
|
|
|
+ print(f"码率大于次数: {bitrate_counter}")
|
|
|
+ print(f"文件大小大于次数: {filesize_counter}")
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ import sys
|
|
|
+
|
|
|
+ if len(sys.argv) != 2:
|
|
|
+ print("使用方法: python script.py input.csv")
|
|
|
+ sys.exit(1)
|
|
|
+ process_csv(sys.argv[1])
|