fork download
  1. import re
  2. import sys
  3.  
  4. def convert_iframe_code(input_code):
  5. # print(f"Received iframe code: {input_code}") # 打印接收到的 iframe 代码,用于调试
  6.  
  7. # 更新正则表达式,允许匹配多种 iframe 格式
  8. pattern = r'<iframe.*?src=["\']\/\/player\.bilibili\.com\/player\.html\?isOutside=true&aid=(\d+)&bvid=(\w+)&cid=(\d+)&p=(\d+).*?["\'].*?>.*?<\/iframe>'
  9. match = re.search(pattern, input_code)
  10.  
  11. if match:
  12. aid = match.group(1)
  13. bvid = match.group(2)
  14. cid = match.group(3)
  15. p = match.group(4)
  16.  
  17. # 构造新的 iframe 代码
  18. new_code = f'<iframe src="http://p...content-available-to-author-only...i.com/player.html?isOutside=true&aid={aid}&bvid={bvid}&cid={cid}&p={p}&autoplay=false" ' \
  19. f'scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" ' \
  20. f'style="width: 640px; height: 430px; max-width: 100%"></iframe>'
  21. return new_code
  22. else:
  23. raise ValueError("Invalid iframe code")
  24.  
  25. # 从命令行参数中获取输入
  26. if __name__ == '__main__':
  27. if len(sys.argv) > 1:
  28. input_code = sys.argv[1]
  29. try:
  30. output_code = convert_iframe_code(input_code)
  31. print(output_code)
  32. except ValueError as e:
  33. print(e)
  34. else:
  35. print("Please provide the iframe code as an argument.")
Success #stdin #stdout 0.03s 9484KB
stdin
Standard input is empty
stdout
Please provide the iframe code as an argument.