Skip to content

Commit

Permalink
优化 #23 ,如果未开播就等待几分钟后重试
Browse files Browse the repository at this point in the history
  • Loading branch information
nICEnnnnnnnLee committed Jan 25, 2020
1 parent 230a964 commit a2a3e6c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ Go go go, Bilibili Pikachu!
| splitScriptTags || 校准文件时是否分割ScriptTag。默认false |
| fileName || 文件命名规则,默认`{name}-{shortId} 的{liver}直播{startTime}-{seq}` |
| timeFormat || 文件命名中{startTime}和{endTime}的格式,默认`yyyy-MM-dd HH.mm` |
| saveFolder || 文件保存路径 |
| saveFolder || 源文件保存路径 |
| saveFolderAfterCheck || FLV文件校准后的保存路径,check为true时有效。默认为空,此时与`saveFolder`等同 |
| retryIfLiveOff || 当目标不在直播时,是否继续重试。默认false |
| maxRetryIfLiveOff || 当目标不在直播时,继续重试的次数。默认0,此时会一直进行尝试,直到主播上线 |
| retryAfterMinutes || 当目标不在直播时,每次获取直播间信息的时间间隔,单位分钟。默认`5.0` |


+ 各直播源解析情况

Expand Down
4 changes: 4 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 更新
+ V2.6.1
* 修复一个bug #20 ,该bug导致主播正常下播时无法自动重命名{endTime}参数;
* 优化 #22 ,如果FLV自动校准,且传入了自定义参数saveFolderAfterCheck,校准后的文件将保存在参数对应目录中
* 优化 #23 ,如果未开播就等待几分钟后重试
+ V2.6.0
* 优化[issue #19](/~https://github.com/nICEnnnnnnnLee/BilibiliLiveRecorder/issues/19) 当快手cookie失效无法获取用户信息时,以默认值代替。此时,直播录制仍可进行
* 优化[issue #20](/~https://github.com/nICEnnnnnnnLee/BilibiliLiveRecorder/issues/20) 文件名支持结束时间{endTime},且支持自定义日期格式,参见参数`timeFormat`
Expand Down
49 changes: 43 additions & 6 deletions src/main/java/nicelee/bilibili/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class Main {
static String[] qnPriority;
static int maxFailCnt;
static int failCnt;

static boolean retryIfLiveOff;
static int maxRetryIfLiveOff;
static double retryAfterMinutes;

static long splitFileSize;
static long splitRecordPeriod;
Expand All @@ -55,7 +59,7 @@ public class Main {
public static void main(String[] args) throws IOException {
// args = new String[]{"debug=false&liver=bili&id=221602&qn=10000&delete=false&check=false"}; // 清晰度全部可选,可不需要cookie
// args = new String[] {
// "debug=false&check=true&liver=douyu&qnPri=高清>蓝光4M>超清>蓝光>流畅&qn=-1&id=35954&saveFolder=D:\\Workspace&fileName=测试{liver}-{name}-{startTime}-{endTime}-{seq}&saveFolderAfterCheck=D:\\Workspace\\live-test" }; // 清晰度全部可选,但部分高清需要cookie
// "debug=false&check=true&retryAfterMinutes=0.5&retryIfLiveOff=true&liver=douyu&qnPri=高清>蓝光4M>超清>蓝光>流畅&qn=-1&id=233233&saveFolder=D:\\Workspace&fileName=测试{liver}-{name}-{startTime}-{endTime}-{seq}&saveFolderAfterCheck=D:\\Workspace\\live-test" }; // 清晰度全部可选,但部分高清需要cookie
// args = new String[] { "debug=true&check=true&liver=kuaishou&id=mianf666&qn=0&delete=false&fileName=测试{liver}-{name}-{startTime}-{endTime}-{seq}&timeFormat=yyyyMMddHHmm" }; // 清晰度全部可选,可不需要cookie
// asd199895
// args = new String[]{"debug=true&check=false&liver=huya&id=660137"}; // 清晰度全部可选,可不需要cookie
Expand All @@ -74,6 +78,9 @@ public static void main(String[] args) throws IOException {
splitRecordPeriod = 0;
flagSplit = false;
flagZip = false;
retryIfLiveOff = false;
maxRetryIfLiveOff = 0;
retryAfterMinutes = 5;
// 根据参数初始化值
if (args != null && args.length >= 1) {
String value = getValue(args[0], "check");
Expand All @@ -96,6 +103,18 @@ public static void main(String[] args) throws IOException {
if ("true".equals(value)) {
flagZip = true;
}
value = getValue(args[0], "retryIfLiveOff");
if ("true".equals(value)) {
retryIfLiveOff = true;
}
value = getValue(args[0], "maxRetryIfLiveOff");
if (value != null && !value.isEmpty()) {
maxRetryIfLiveOff = Integer.parseInt(value);
}
value = getValue(args[0], "retryAfterMinutes");
if (value != null && !value.isEmpty()) {
retryAfterMinutes = Double.parseDouble(value);
}
value = getValue(args[0], "liver");
if (value != null && !value.isEmpty()) {
liver = value;
Expand Down Expand Up @@ -198,17 +217,35 @@ public static void main(String[] args) throws IOException {
roomDealer.setCookie(cookie);
}
// 获取房间信息
RoomInfo roomInfo = roomDealer.getRoomInfo(shortId);
RoomInfo rroomInfo = roomDealer.getRoomInfo(shortId);

if (roomInfo == null) {
if (rroomInfo == null) {
System.err.println("解析失败!!");
System.exit(-2);
}
// 查看是否在线
if (roomInfo.getLiveStatus() != 1) {
if (rroomInfo.getLiveStatus() != 1) {
System.out.println("当前没有在直播");
System.exit(3);
int retryCntLiveOff = 0;
if(retryIfLiveOff) {
while(rroomInfo.getLiveStatus() != 1 && (maxRetryIfLiveOff == 0 || maxRetryIfLiveOff > retryCntLiveOff)) {
retryCntLiveOff++;
try {
System.out.println(retryAfterMinutes + "分钟左右后重试");
Thread.sleep((long) (retryAfterMinutes*60000));
} catch (InterruptedException e) {
}
rroomInfo = roomDealer.getRoomInfo(shortId);
if (rroomInfo == null) {
System.err.println("解析失败!!");
System.exit(-2);
}
}
}else {
System.exit(3);
}
}

RoomInfo roomInfo = rroomInfo;
// 清晰度获取
// 先使用预设的优先级获取
if (qnPriority != null) {
Expand Down

0 comments on commit a2a3e6c

Please sign in to comment.