Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom
Commits
6842a7e9
Commit
6842a7e9
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
use ioutil.TempFile, not our obsolete replacement
parent
736912e2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/actions/encode_mp3.go
+11
-7
11 additions, 7 deletions
server/actions/encode_mp3.go
util/fingerprinting/fingerprint.go
+14
-6
14 additions, 6 deletions
util/fingerprinting/fingerprint.go
with
25 additions
and
13 deletions
server/actions/encode_mp3.go
+
11
−
7
View file @
6842a7e9
...
...
@@ -4,11 +4,11 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"git.autistici.org/ale/djrandom/api"
"git.autistici.org/ale/djrandom/services"
"git.autistici.org/ale/djrandom/util"
"git.autistici.org/ale/djrandom/util/ffmpeg"
"git.autistici.org/ale/djrandom/util/metadata_extraction"
)
...
...
@@ -48,8 +48,12 @@ func (a *EncodeMp3Action) HandleSong(session services.Session, song *api.Song, l
}
// Generate a temporary file to save the encoded mp3 locally.
tmpf
:=
util
.
TempName
(
"ffmpeg-mp3-"
,
".mp3"
)
defer
os
.
Remove
(
tmpf
)
tmpf
,
err
:=
ioutil
.
TempFile
(
""
,
"djrandom-mp3-"
)
if
err
!=
nil
{
return
err
}
tmpf
.
Close
()
defer
os
.
Remove
(
tmpf
.
Name
())
// Download file and pipe it directly into ffmpeg.
file
,
err
:=
a
.
Storage
.
Open
(
audioFileId
)
...
...
@@ -65,7 +69,7 @@ func (a *EncodeMp3Action) HandleSong(session services.Session, song *api.Song, l
"-acodec"
,
"libmp3lame"
,
"-b:a"
,
"320k"
,
"-f"
,
"mp3"
,
tmpf
,
tmpf
.
Name
()
,
}
fmt
.
Fprintf
(
log
,
"running ffmpeg: %v
\n
"
,
ffmpegArgs
)
output
,
err
:=
ffmpeg
.
Run
(
file
,
ffmpegArgs
)
...
...
@@ -77,16 +81,16 @@ func (a *EncodeMp3Action) HandleSong(session services.Session, song *api.Song, l
}
// Update the db with the new file!
af
,
_
,
err
:=
metadata_extraction
.
GetMetadata
(
tmpf
,
api
.
MIMETYPE_MP3
)
af
,
_
,
err
:=
metadata_extraction
.
GetMetadata
(
tmpf
.
Name
()
,
api
.
MIMETYPE_MP3
)
if
err
!=
nil
{
fmt
.
Fprintf
(
log
,
"error reading meta: %s
\n
"
,
err
)
return
err
}
// Add the file to the song, and upload it to remote storage.
outfile
,
err
:=
os
.
Open
(
tmpf
)
outfile
,
err
:=
os
.
Open
(
tmpf
.
Name
()
)
if
err
!=
nil
{
fmt
.
Fprintf
(
log
,
"unexpected error re-opening file %s: %s
\n
"
,
tmpf
,
err
)
fmt
.
Fprintf
(
log
,
"unexpected error re-opening file %s: %s
\n
"
,
tmpf
.
Name
()
,
err
)
return
err
}
defer
outfile
.
Close
()
...
...
This diff is collapsed.
Click to expand it.
util/fingerprinting/fingerprint.go
+
14
−
6
View file @
6842a7e9
...
...
@@ -11,10 +11,11 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"strconv"
"git.autistici.org/ale/djrandom/api"
"git.autistici.org/ale/djrandom/services"
"git.autistici.org/ale/djrandom/util"
"git.autistici.org/ale/djrandom/util/ffmpeg"
)
...
...
@@ -33,7 +34,7 @@ var (
func
RunCodegen
(
tempName
string
)
(
string
,
string
,
error
)
{
cmd
:=
exec
.
Command
(
*
codegenBinary
,
tempName
,
"0"
,
fmt
.
Sprintf
(
"%d"
,
fingerprintSampleTime
))
strconv
.
Itoa
(
fingerprintSampleTime
))
log
.
Printf
(
"Exec: %v"
,
cmd
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
...
...
@@ -105,14 +106,21 @@ func GetSongFingerprint(song *api.Song, db services.Database, storage services.S
defer
file
.
Close
()
// Pipe it to ffmpeg to extract a WAV sample of the audio.
tmpName
:=
util
.
TempName
(
"djrandom-fingerprint-"
,
".wav"
)
defer
os
.
Remove
(
tmpName
)
// This is just so that hopefully we don't have to download
// the entire file, as ffmpeg should close stdin as soon as it
// has decoded the time slice it needs.
tmpDir
,
err
:=
ioutil
.
TempDir
(
""
,
"djrandom-fingerprint-"
)
if
err
!=
nil
{
return
""
,
""
,
err
}
defer
os
.
RemoveAll
(
tmpDir
)
tmpName
:=
filepath
.
Join
(
tmpDir
,
"fp.wav"
)
ffmpegArgs
:=
[]
string
{
"-f"
,
api
.
GetFfmpegFormatForMimeType
(
af
.
MimeType
),
"-i"
,
"-"
,
"-t"
,
fmt
.
Sprintf
(
"%d"
,
fingerprintSampleTime
),
"-ss"
,
fmt
.
Sprintf
(
"%d"
,
fingerprintSampleOffset
),
"-t"
,
strconv
.
Itoa
(
fingerprintSampleTime
),
"-ss"
,
strconv
.
Itoa
(
fingerprintSampleOffset
),
tmpName
,
}
output
,
err
:=
ffmpeg
.
Run
(
file
,
ffmpegArgs
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment