Results 1 to 10 of 10

Thread: a code question regarding music file extensions

  1. #1
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    a code question regarding music file extensions

    if one wishes to contract this


    Code:
    nvlc */./*flac *ape *wv *shn *aac *m4a *mp3

    so as to say all music but music files only is there a way to do that to simplify the line; so as to not have to write every single xtension
    Last edited by shantiq; June 18th, 2012 at 09:17 PM.
    Linux is Latin for off-the-beaten-track
    ShanArt XmmsPurple Piper

  2. #2
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,635
    Distro
    Ubuntu

    Re: a code question regarding music file extensions

    Wht not make an alias

    Code:
    alias tunes='nvlc */./*flac *ape *wv *shn *aac *m4a *mp3'
    put that at the end of ~/.bashrc then source bashrc

    Code:
    . ~/.bashrc
    Now you just have to type
    Code:
    tunes
    of course, it doesn't have to be "tunes" you can call it watermelon if you like

    Code:
    alias watermelon='nvlc */./*flac *ape *wv *shn *aac *m4a *mp3'

  3. #3
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: a code question regarding music file extensions

    I don't think you can do that directly, but you could cheat:

    Code:
    export MUSIC=*flac *ape...
    nvlc $MUSIC
    I don't know if this reduces typing in your situation?

    Edit: heh, nothingspecial, great minds think alike.

  4. #4
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,148
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: a code question regarding music file extensions

    Hi shantiq.

    It is very difficult to keep track of all music extensions. For example, you can put that command on a script, but if you get some ogg files, they will be ignored.

    I don't always use command line music players, but when I do (that sounded familiar ) I load whole directories. It has the undesired side effect off also loading some text files, and pics, but it is so much easier.

    For example:
    Code:
    nvlc Music
    or
    Code:
    nvlc /path/to/musiclib1 /path/to/musiclib2 /path/to/musiclib3
    Just some thoughts.
    Regards.

  5. #5
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: a code question regarding music file extensions

    ok guys thanx
    It has the undesired side effect off also loading some text files, and pics, but it is so much easier.

    is my reason for asking i want to filter out all else that is NOT a music file

    and was wondering whether there is a "generic" piece of code that would "know" that
    Last edited by shantiq; June 18th, 2012 at 09:17 PM.
    Linux is Latin for off-the-beaten-track
    ShanArt XmmsPurple Piper

  6. #6
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: a code question regarding music file extensions

    Quote Originally Posted by nothingspecial View Post
    Wht not make an alias

    Code:
    alias tunes='nvlc */./*flac *ape *wv *shn *aac *m4a *mp3'
    put that at the end of ~/.bashrc then source bashrc

    Code:
    . ~/.bashrc
    Now you just have to type
    Code:
    tunes
    of course, it doesn't have to be "tunes" you can call it watermelon if you like

    Code:
    alias watermelon='nvlc */./*flac *ape *wv *shn *aac *m4a *mp3'


    WOW Nothingspecial that is a good one never knew thanx a lot



    works a dream


    just wrote


    alias musica='cd ~/Music && nvlc */./*flac *ape *wv *shn *aac *m4a *mp3 *cue'



    now the word "musica" is my quickest TERMINAL player ever simply click r once started for random


    one key to open guake/2 keys mu /upward arrow/ musica appears/return/hit r for random get on with things nice one:]

    added bonus also easy way to have hotkeys to pause/play and go to next track can be set in vlc global preferences and will work with nvlc too [thanx Mc4man for info on this]


    Makes an invisible self-designed radio station..

    ====================
    Last edited by shantiq; June 20th, 2012 at 10:00 PM.
    Linux is Latin for off-the-beaten-track
    ShanArt XmmsPurple Piper

  7. #7
    Join Date
    Mar 2009
    Location
    Western Hemisphere.
    Beans
    136
    Distro
    Ubuntu

    Re: a code question regarding music file extensions

    For what it's worth, you can use the file command to check the mime-type of a given file.

    Specifically

    Code:
    file -b --mime-type filename
    should output audio/mpeg, or audio/flac or something like that for audio files.

    In principle you can then construct a list of files that have an audio mime-type in the folder and pass that to nvlc. If you're looking to write a script, this would let you get all relevant audio formats without having to list them, though the end result is probably more total code than the solutions others have proposed!

  8. #8
    Join Date
    Aug 2007
    Location
    Sweden
    Beans
    197
    Distro
    Xubuntu 10.04 Lucid Lynx

    Re: a code question regarding music file extensions

    1) What does syntax */./* mean? Is it vlc specific or a new bash?

    2) List audio files in current dir based on file name extension
    Code:
    shopt -s nocaseglob nullglob
    ls -d *.{mp3,wav,riff,wma,au,ogg,flac,m4a,aac}
    Add more extensions as you wish. The nocaseglob option makes bash ignore case in file name expansion. That is, it will match both mp3 and MP3. The nullglob option makes bash ignore file name patterns that does not match anything. That is, if there is no *.flac files there won't be an error "no such file *.flac".

    3) List audio files in current dir by identifying their headers
    Code:
    file -Lr0 --mime-type * | awk -F\0 '$2~"audio/"{print $1}'
    No matter if an mp3 file is called "Madonna.mp3", "Madonna.musicfile" or just "Madonna", if will be recognized as an audio file. This does not work for ogg files.

    The above can be extended to search folders recursively and the result passed to a music player.

  9. #9
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,148
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: a code question regarding music file extensions

    This is probably beyond the OP's concern but...

    The command 'file' would be great, if it covered all cases. Since it's fast enough, you could generate the music list at the moment of launching the player.

    However, the problem that I have with it is that for a considerable media files it just returns:
    Code:
    application/octet-stream
    And that could be an mp3, mkv, audio flv, video flv, etc.

    I guess you could 'repair' those files if your music collection if not to big, but it could be a lot of work for a medium to big amount of media files.

    What I've used in the past is 'mediainfo'. Here's how to install it, and here's an example on how to make a script with it.

    The only problem with mediainfo is not practical to create the music list at the moment of launching the player. It is not fast enough since it really reads more that just the "magic bits". A method using this tool would work better if you separate the functionality of creating and updating the music list from the launch of the player.

    Nevertheless, this method does not have the problem of using simple file extensions: if get new music files that were not consider on the alias or script, they won't be included on the list. For instance:
    Code:
    flv ogg f4a
    Just a few thoughts. I hope that didn't bore anybody.
    Kind Regards.

  10. #10
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: a code question regarding music file extensions

    ----------
    Last edited by shantiq; June 20th, 2012 at 10:10 PM.
    Linux is Latin for off-the-beaten-track
    ShanArt XmmsPurple Piper

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •