Kethsar / ytarchive

Garbage Youtube livestream downloader
MIT License
1.01k stars 83 forks source link

Issue about "--temporary-dir" #189

Open 08jingles opened 2 months ago

08jingles commented 2 months ago

I'm thinking since the --temporary-dir option specifies the working directory, shouldn't it default to completing muxing in this location before moving to the output directory? Additionally, os.rename will cause Invalid cross-device link (when I'm using rclone mount) (and this will also cause merging issue if muxing is doing in the output directory), so I'm wondering if it can be modified.

Regarding os.rename, I temporarily change it to as follows, which barely runs normally.

func TryMove(srcFile, dstFile string) error {
    // Open the source file for reading
    src, err := os.Open(srcFile)
    if err != nil {
        return err
    }
    defer src.Close()

    // Create the destination file
    dst, err := os.Create(dstFile)
    if err != nil {
        return err
    }
    defer dst.Close()

    // Copy the contents of the source file to the destination file
    _, err = io.Copy(dst, src)
    if err != nil {
        return err
    }

    // Close the destination file
    if err := dst.Close(); err != nil {
        return err
    }

    // Remove the source file
    if err := os.Remove(srcFile); err != nil {
        return err
    }

    return nil
}

But a lot of log info is missing

2024/04/25 21:52:18 INFO: Deleting file /home/user/ytarchive-cache/FQ8hNToAtgw.f140.state
2024/04/25 21:52:18 INFO: Deleting file /home/user/ytarchive-cache/FQ8hNToAtgw.f299.state

2024/04/25 21:52:18 Download Finished
2024/04/25 21:52:23 Muxing final file...
2024/04/25 21:52:23 DEBUG: Executing command: ffmpeg ffmpeg -hide_banner -nostdin -loglevel fatal -stats -seekable 0 -thread_queue_size 1024 -i '/home/user/mount/rieru/[FQ8hNToAtgw].f140.ts' -seekable 0 -thread_queue_size 1024 -i '/home/user/mount/rieru/[FQ8hNToAtgw].f299.ts' -movflags faststart -c copy '/home/user/mount/rieru/[FQ8hNToAtgw].mp4'
frame=140118 fps=7123 q=-1.0 Lsize=  758557kB time=00:38:55.32 bitrate=2660.9kbits/s speed= 119x
2024/04/25 21:52:43 ERROR: At least one error occurred when moving files. Will not delete them.
2024/04/25 21:52:43 INFO: Deleting file /home/user/mount/rieru/[FQ8hNToAtgw].ffmpeg.txt
2024/04/25 21:52:43 INFO: Deleting file /home/user/mount/rieru/[FQ8hNToAtgw].f140.ts
2024/04/25 21:52:44 INFO: Deleting file /home/user/mount/rieru/[FQ8hNToAtgw].f299.ts
2024/04/25 21:52:44
Final file: /home/user/mount/rieru/[FQ8hNToAtgw].mp4

In between, there's a gap that missing something like

2024/04/25 21:10:42 INFO: Moving file /home/user/ytarchive-cache/QPULkVHVCic__3028340527/[QPULkVHVCic].f140.ts to /home/user/mount/rieru/[QPULkVHVCic].f140.ts
2024/04/25 21:10:42 INFO: Moving file /home/user/ytarchive-cache/QPULkVHVCic__3028340527/[QPULkVHVCic].f299.ts to /home/user/mount/rieru/[QPULkVHVCic].f299.ts
2024/04/25 21:10:42 INFO: Moving file /home/user/ytarchive-cache/QPULkVHVCic__3028340527/[QPULkVHVCic].ffmpeg.txt to /home/user/mount/rieru/[QPULkVHVCic].ffmpeg.txt

Also, this part clearly has something wrong

2024/04/25 21:52:43 ERROR: At least one error occurred when moving files. Will not delete them.
2024/04/25 21:52:43 INFO: Deleting file /home/user/mount/rieru/[FQ8hNToAtgw].ffmpeg.txt
2024/04/25 21:52:43 INFO: Deleting file /home/user/mount/rieru/[FQ8hNToAtgw].f140.ts
2024/04/25 21:52:44 INFO: Deleting file /home/user/mount/rieru/[FQ8hNToAtgw].f299.ts