Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Unable to open file for write error #197

Open
marc0der opened this issue Feb 3, 2022 · 9 comments
Open

Unable to open file for write error #197

marc0der opened this issue Feb 3, 2022 · 9 comments

Comments

@marc0der
Copy link

marc0der commented Feb 3, 2022

Hi there,

Firstly, thanks for the great tool. I love using this to free my audiobooks but have recently run into an issue with the latest source from the master branch. Everything seems to work fine until the combined file is to be written as m4a. Here is my console dump.

AAXtoMP3/AAXtoMP3 -e:m4a -c -A 6a793a0b AtomicHabitsAnEasyandProvenWaytoBuildGoodHabitsandBreakBadOnes_ep7.mp4            

----Decoding---Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones--6a793a0b--
Source: AtomicHabitsAnEasyandProvenWaytoBuildGoodHabitsandBreakBadOnes_ep7.mp4
Total length: 05:35:20
size=  311845kB time=05:35:20.20 bitrate= 127.0kbits/s speed=1.7e+03x     
Created ./Audiobook/James Clear/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones.m4a.
Creating PlayList Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones.m3u
Extracting 23 chapter files from ./Audiobook/James Clear/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones.m4a...
Chapter splitting: |####################| 100% (23/23 chapters)
Adding cover art
adding ./Audiobook/James Clear/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones/cover.jpg -> ./Audiobook/James Clear/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones.m4a
Open: open(./Audiobook/James Clear/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones.m4a) failed (src/mp4file.cpp,400)
ERROR: unable to open for write: ./Audiobook/James Clear/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones/Atomic Habits: An Easy and Proven Way to Build Good Habits and Break Bad Ones.m4a

Neofetch dump:

                  -`                    marco@anubis 
                  .o+`                   ------------ 
                 `ooo/                   OS: Arch Linux x86_64 
                `+oooo:                  Host: XPS 13 9300 
               `+oooooo:                 Kernel: 5.15.19-1-lts 
               -+oooooo+:                Uptime: 18 hours, 37 mins 
             `/:-:++oooo+:               Packages: 973 (pacman), 20 (flatpak), 15 (snap) 
            `/++++/+++++++:              Shell: zsh 5.8 
           `/++++++++++++++:             Resolution: 3840x2400 
          `/+++ooooooooooooo/`           DE: Regolith 
         ./ooosssso++osssssso+`          WM: i3 
        .oossssso-````/ossssss+`         Theme: Adwaita [GTK2] 
       -osssssso.      :ssssssso.        Icons: Adwaita [GTK2] 
      :osssssss/        osssso+++.       Terminal: gnome-terminal 
     /ossssssss/        +ssssooo/-       CPU: Intel i7-1065G7 (8) @ 1.300GHz 
   `/ossssso+/:-        -:/+osssso+-     GPU: Intel Iris Plus Graphics G7 
  `+sso+:-`                 `.-/+oso:    Memory: 7832MiB / 31686MiB 
 `++:.                           `-/+/
 .`                                 `/ 

Please shout if you need any other details from me or if I can help in any other way.

@KrumpetPirate
Copy link
Owner

Try again with most recent push.

@JulianOestreich90
Copy link

JulianOestreich90 commented Feb 28, 2022

I'm having the same problem and i'm using the recent push.

@dkbast
Copy link

dkbast commented Mar 2, 2022

Edit: FIX: Just run it a couple of times - the chapter files should be written eventually, the error is meaningless. It looks like it tries to access the "complete" file which was not written because auf the chapter flag. So even though it looks like it fails it should actually work.

Update2: looks like the meta data is not written completely and the playlist is not complete either


I get the same error - what's interesting is, that the file which causes the error is not even supposed to be created, at least I don't see that in the other folders -> './Audiobook/AUTHOR/ALBUM/ALBUM.m4a' - since it should be chaptered there should not be a file with just the album name, should there?

AAXtoMP3 -a -A fa756506 -c --use-audible-cli-data FILENAME.aaxc
...
Open: open(./Audiobook/AUTHOR/ALBUM/ALBUM.m4a) failed (src/mp4file.cpp,398)
ERROR: unable to open for write: ./Audiobook/AUTHOR/ALBUM/ALBUM.m4a

@Maloupi
Copy link

Maloupi commented Jul 25, 2022

I got the same error, each time :

AAXtoMP3 --authcode 12345678 --no-clobber --target_dir '/home/nausicaa/mp3' -e:m4b --chaptered --dir-naming-scheme '$artist - $title' --chapter-naming-scheme '$title - $(printf %0${#chaptercount}d $chapternum) - $chapter' --use-audible-cli-data --audible-cli-library-file '/home/nausicaa/.audible/library.tsv' /home/nausicaa/aax/book.aaxc

Open: open(/home/nausicaa/mp3/book.m4b) failed (src/mp4file.cpp,399)
ERROR: unable to open for write: /home/nausicaa/mp3/book.m4b

@carwin
Copy link

carwin commented Sep 21, 2022

Also running into this issue.

@carwin
Copy link

carwin commented Sep 21, 2022

Adding some details, I'm on the master branch:

Total length: 07:42:15
size=  429879kB time=07:42:15.77 bitrate= 127.0kbits/s speed= 403x
Created ./Audiobook/Author/MyBook.m4b.
Creating PlayList MyBook.m3u
Extracting 78 chapter files from ./Audiobook/Author/MyBook.m4b...
Chapter splitting: |####################| 100% (78/78 chapters)
Adding cover art
adding ./Audiobook/Author/MyBook/cover.jpg -> ./Audiobook/Author/MyBook.m4b
Open: open(./Audiobook/Author/MyBook/MyBook.m4b) failed (src/mp4file.cpp,426)
ERROR: unable to open for write: ./Audiobook/Author/MyBook/MyBook.m4b
                  -`                    carwin@guts
                 .o+`                   -----------
                `ooo/                   OS: Arch Linux x86_64
               `+oooo:                  Kernel: 5.19.9-arch1-1
              `+oooooo:                 Uptime: 14 hours, 9 mins
              -+oooooo+:                Packages: 1206 (pacman)
            `/:-:++oooo+:               Shell: zsh 5.9
           `/++++/+++++++:              Resolution: 5120x1440
          `/++++++++++++++:             WM: i3
         `/+++ooooooooooooo/`           Theme: Adwaita [GTK2/3]
        ./ooosssso++osssssso+`          Icons: Adwaita [GTK2/3]
       .oossssso-````/ossssss+`         Terminal: alacritty
      -osssssso.      :ssssssso.        CPU: AMD Ryzen 7 3700X (16) @ 3.600GHz
     :osssssss/        osssso+++.       GPU: NVIDIA GeForce RTX 3090
    /ossssssss/        +ssssooo/-       Memory: 6099MiB / 31981MiB
  `/ossssso+/:-        -:/+osssso+-
 `+sso+:-`                 `.-/+oso:
`++:.                           `-/+/
.`                                 `/

Just for grins, I decided to try running this as root, since the original error seemed like a permission related problem and the output was slightly different. The file which previously could not be opened for write, was written, but the next process (creating the playlist) threw an error referring to the fact that the .m3u couldn't be overwritten.

...

Created ./Audiobook/Author/MyBook/MyBook.m4b.
Creating PlayList MyBook.m3u
/path/to/AAXtoMP3/AAXtoMP3: line 831: ./Audiobook/Author/MyBook/MyBook.m3u: cannot overwrite existing file

The error seems to come from this section of the main executable:

  # If mode=chaptered, split the big converted file by chapter and remove it afterwards.
  # Not all audio encodings make sense with multiple chapter outputs (see options section)
  if [ "${mode}" == "chaptered" ]; then
    # Playlist m3u support
    playlist_file="${output_directory}/${currentFileNameScheme}.m3u"
    if [ "${continue}" == "0" ]; then
      if [ "$((${loglevel} > 0))" == "1" ]; then
        log "Creating PlayList ${currentFileNameScheme}.m3u"
      fi
      echo '#EXTM3U' > "${playlist_file}"
    fi
    
    ...

@dkbast I think that explains why that file "just-album-name" file is there, looks like it's temporary and meant to be deleted after the processing is finished.

@fabh2o
Copy link
Contributor

fabh2o commented Sep 21, 2022

@carwin Can you try to modify

echo '#EXTM3U' > "${playlist_file}"
by adding | after >? Like this: echo '#EXTM3U' >| "${playlist_file}"
Explanation: https://mywiki.wooledge.org/NoClobber

@carwin
Copy link

carwin commented Sep 22, 2022

No change. Just for fun I tried appending to the file instead (>>) with the same outcome.

I think the playlist file may be a red herring, the core issue seems like it's to do with attempting action on the m4b file.

@Maloupi
Copy link

Maloupi commented Nov 28, 2022

Hi,

The problem occurs when the book is chaptered. It tries to add image cover to the main file, which did not exist anymore because it was splitted in chapter files and then deleted.

As a very very quick fix, you can add this around the add cover if (line 970) :

if [ "${mode}" != "chaptered" ]; then

and

fi

after at line 997
So this part will not be ran if in chaptered mode

then put this in on line 942, just after chapternum=$((chapternum + 1 ))

        if [ -f "${cover_file}" ]; then
          log "Adding cover art"
          # FFMPEG does not support MPEG-4 containers fully #
          if [ "${container}" == "mp4" ] ; then
            mp4art --add "${cover_file}" "${chapter_file}"
          # FFMPEG for everything else #
          else
            # Create temporary output file name - ensure extention matches previous appropriate output file to keep ffmpeg happy
            cover_output_file="${output_file%.*}.cover.${output_file##*.}"
            # Copy audio stream from current output, and video stream from cover file, setting appropriate metadata
            </dev/null "$FFMPEG" -loglevel quiet \
              -nostats \
              -i v \
              -i "${cover_file}" \
              -map 0:a:0 \
              -map 1:v:0 \
              -acodec copy \
              -vcodec copy \
              -id3v2_version 3 \
              -metadata:s:v title="Album cover" \
              -metadata:s:v comment="Cover (front)" \
              "${cover_output_file}"
              # Replace original output file with version including cover
              mv "${cover_output_file}" "${chapter_file}"
          fi
        fi

So it will add the cover to every chapter file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants