1. Are you ready for the Galaxy S20? Here is everything we know so far!

The "Linux questions (and other stuff)" thread

Discussion in 'Computers' started by MoodyBlues, Jan 17, 2013.

  1. GameTheory

    GameTheory Android Expert

    https://androidforums.com/threads/resolved-file-manager-manage-files-based-on-id3-tags.1314378/
    Continuing from the thread linked above^. Moved here as per Moody's suggestion. A little more code...

    Code (Bash):
    1. #!/bin/bash
    2.  
    3. base_dir=$(pwd)
    4. files=$(find $base_dir -iname "*.mp3" -exec basename {} \;)
    5. tool=mediainfo
    6.  
    7. for i in $files; do
    8.   mp3_dir=$base_dir/$($tool $i | grep -i 'genre.*:' | sed 's/^.*: //' | sed 's/\(.*\)/\L\1/' | sed 's/[,;:-/_=.~|].*//')
    9.   if [ ! -d "$mp3_dir" ]; then
    10.     mkdir "$mp3_dir"
    11.   fi
    12.   mv "$i" "$mp3_dir" > /dev/null 2>&1
    13. done
    What this does:
    • Searches its working directory for all mp3 files.
    • Checks genre for the files and creates genre folder if doesn't exist in its working directory. For multi-genre files it chooses the first main genre. (first genre is the main)
    • Moves mp3 files to their respective genre folder.
    • Ignores files with no genre (usually unofficial).
    This is nothing final and can still be spruced up and expanded with more logic. Awk can make this more elegant. However, in its current state it will organize your files neatly by genre.

    Note:
    Since my music is on Spotify, I didn't have proper mp3 files to test with. So I had to assume that the delimiter is a comma which is common for string separation. Open a multi-genre mp3 in VLC and go to "tools > media info" and tell me what the genres are separated with and I'll adjust.

    Edit:
    Now compensates for all delimiters.
     

    Advertisement

    #3051 GameTheory, Sep 30, 2019
    Last edited: Oct 1, 2019
    MoodyBlues likes this.
  2. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    Since I can't be of much help currently in terms of coding, and since @GameTheory doesn't have MP3 files to play with, here's something I can contribute.

    This is what an example directory would look like; on my computers, all media files are stored on the /data partition, under their appropriate subdirectory. So here's a sample listing:

    Code (Text):
    1.  
    2. $ pwd
    3. /data/media/sounds/MoodyBlues/EveryGoodBoyDeservesFavour
    4. $ ls -1
    5. 01 - Procession.mp3
    6. 02 - The Story In Your Eyes.mp3
    7. 03 - Our Guessing Game.mp3
    8. 04 - Emily's Song.mp3
    9. 05 - After You Came.mp3
    10. 06 - One More Time To Live.mp3
    11. 07 - Nice To Be Here.mp3
    12. 08 - You Can Never Go Home.mp3
    13. 09 - My Song.mp3
    And here's the output of mediainfo for the first song:

    Code (Text):
    1.  
    2. $ mediainfo 01*
    3. General
    4. Complete name                            : 01 - Procession.mp3
    5. Format                                   : MPEG Audio
    6. File size                                : 8.75 MiB
    7. Duration                                 : 4mn 40s
    8. Overall bit rate mode                    : Constant
    9. Overall bit rate                         : 256 Kbps
    10. Album                                    : Every Good Boy Deserves Favour
    11. Album/Performer                          : The Moody Blues
    12. Part/Position                            : 1
    13. Part/Total                               : 1
    14. Track name                               : Procession
    15. Track name/Position                      : 1
    16. Track name/Total                         : 9
    17. Performer                                : The Moody Blues
    18. Composer                                 : Michael Pinder
    19. Genre                                    : Rock
    20. Recorded date                            : 1997
    21. Copyright                                : (C) 1997 Decca Music Group Limited
    22. Cover                                    : Yes
    23. Cover type                               : Cover (front)
    24. Cover MIME                               : image/jpeg
    25. Comment                                  : Amazon.com Song ID: 208803264
    26.  
    27. Audio
    28. Format                                   : MPEG Audio
    29. Format version                           : Version 1
    30. Format profile                           : Layer 3
    31. Duration                                 : 4mn 40s
    32. Bit rate mode                            : Constant
    33. Bit rate                                 : 256 Kbps
    34. Channel(s)                               : 2 channels
    35. Sampling rate                            : 44.1 KHz
    36. Compression mode                         : Lossy
    37. Stream size                              : 8.57 MiB (98%)
    For the project at hand, we're just looking for the 'Genre' line, which in this case only contains one entry. So let's look somewhere else...

    Code (Text):
    1.  
    2. $ pwd
    3. /data/media/sounds/T.Rex_MarcBolan/TheSlider
    4. $ ls -1
    5. 01 - Metal Guru.mp3
    6. 02 - Mystic Lady.mp3
    7. 03 - Rock On.mp3
    8. 04 - The Slider.mp3
    9. 05 - Baby Boomerang.mp3
    10. 06 - Spaceball Ricochet.mp3
    11. 07 - Buick Mackane.mp3
    12. 08 - Telegram Sam.mp3
    13. 09 - Rabbit Fighter.mp3
    14. 10 - Baby Strange.mp3
    15. 11 - Ballrooms Of Mars.mp3
    16. 12 - Chariot Choogle.mp3
    17. 13 - Main Man.mp3
    18. $ mediainfo 01*
    19. General
    20. Complete name                            : 01 - Metal Guru.mp3
    21. Format                                   : MPEG Audio
    22. File size                                : 5.14 MiB
    23. Duration                                 : 2mn 31s
    24. Overall bit rate mode                    : Variable
    25. Overall bit rate                         : 273 Kbps
    26. Album                                    : The Slider
    27. Album/Performer                          : T. Rex
    28. Part/Position                            : 1
    29. Part/Total                               : 1
    30. Track name                               : Metal Guru
    31. Track name/Position                      : 1
    32. Track name/Total                         : 13
    33. Performer                                : T. Rex
    34. Composer                                 : Marc Bolan
    35. Genre                                    : Classic Rock
    36. Recorded date                            : 2010
    37. Writing library                          : LAME3.97
    38. Copyright                                : 2010 Fat Possum
    39. Cover                                    : Yes
    40. Cover type                               : Cover (front)
    41. Cover MIME                               : image/jpeg
    42. Comment                                  : Amazon.com Song ID: 218940199
    43.  
    44. Audio
    45. Format                                   : MPEG Audio
    46. Format version                           : Version 1
    47. Format profile                           : Layer 3
    48. Mode                                     : Joint stereo
    49. Duration                                 : 2mn 31s
    50. Bit rate mode                            : Variable
    51. Bit rate                                 : 273 Kbps
    52. Minimum bit rate                         : 32.0 Kbps
    53. Channel(s)                               : 2 channels
    54. Sampling rate                            : 44.1 KHz
    55. Compression mode                         : Lossy
    56. Stream size                              : 4.94 MiB (96%)
    57. Writing library                          : LAME3.97
    58. Encoding settings                        : -m j -V 0 -q 3 -lowpass 19.5 --vbr-old -b 32
    It's also one entry, but with two words. :thinking:

    When we first started talking about this, I looked at several MP3s' info, and I *swear* I saw some whose genre field contained more than one type, such as 'rock' and 'pop'--but now that I'm actually LOOKING for them, I can't find a single one. So, if anyone can post the output of mediainfo, or just grep and print the genre line, containing more than one type, that would be great. What we need is to determine its field delimiter, which we're pretty sure is comma.
     
    GameTheory likes this.
  3. GameTheory

    GameTheory Android Expert

    Moody you got me thinking, so I went on google images just to see what delimiters are being used for multi genre files. It turns out that it's these (, ; : -). So I made the change to compensate for all and threw a bunch others for good measure.

    Updated code:
    Code (Bash):
    1. #!/bin/bash
    2.  
    3. base_dir=$(pwd)
    4. files=$(find $base_dir -iname "*.mp3" -exec basename {} \;)
    5. tool=mediainfo
    6.  
    7. for i in $files; do
    8.   mp3_dir=$base_dir/$($tool $i | grep -i 'genre.*:' | sed 's/^.*: //' | sed 's/\(.*\)/\L\1/' | sed 's/[,;:-/_=.~|].*//')
    9.   if [ ! -d "$mp3_dir" ]; then
    10.     mkdir "$mp3_dir"
    11.   fi
    12.   mv "$i" "$mp3_dir" > /dev/null 2>&1
    13. done
    The change is in this particular sed:
    Code (Bash):
    1. sed 's/[,;:-/_=.~|].*//'
    The delimiters are all within the square brackets.
     
    #3053 GameTheory, Oct 1, 2019
    Last edited: Oct 1, 2019
    mikedt and MoodyBlues like this.
  4. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    Looking good! Very good. :)

    I think the one thing that could be a little hurdle is 'space' used as a delimiter. Say that we have "rock pop" instead of "rock, pop" or some other character. How do we know that that refers to two genres, as compared to "classic rock" or "country western" and such, which are clearly referring to one genre?

    Also, it seems trivial/obvious enough to use the first word encountered in 'genre' as the directory destination genre, but what happens when we have "rock pop" and "pop rock" (not Pop Rocks!), without a delimiter? (Yeah, I -know- I'm seriously overthinking this, but it's good for my brain. :D)

    Aside from hard-coding every conceivable combination--which defeats the whole point of letting Linux 'decide' and do it automatically--I think going with the first discrete word is probably best, as you've said.
     
    GameTheory and mikedt like this.
  5. mikedt

    mikedt 你好

    I've just had another look at vmall.com for the Deepin Linux Matebooks, and they're all listed as OUT OF STOCK, with no indication of when they're going to be available again. Really, did Huawei discontinue them that quickly?
     
  6. GameTheory

    GameTheory Android Expert

    Hey thanks. :)

    Spaces in genre are handled by the last sed. If you have an mp3 with multi genres like this; "Soft Rock; Country Rock", it will create a folder called "soft rock" in lowercase and place respective files in it.

    Spaces as delimiters will only be found in unofficially obtained media, as only a fool would use spaces to delimit. Even then, I doubt someone would be foolish enough to do that. Imagine a file with 4 multi word genres arranged like words in a sentence. A program cannot handle that, and a human would get confused. So this is for official mp3s only.

    Next I'll probably just add a "choose directory prompt" and a bash type GUI with tput and ansi color codes. I'm leaning towards rewriting this in java, at which point it'll be for my tech blog to give this more exposure. :D
     
    MoodyBlues likes this.
  7. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    Either that, or they can't keep up with demand!
     
  8. mikedt

    mikedt 你好

    Could be. :)

    Although it's shown as out of stock on Huawei's own vmall.com site, they seem to be available from tmall.com. I'm holding off buying for the moment, because my four year old Macbook Air is still working good. But later in the year I still might get a Linux Matebook 14, depending on finances.

    I have been running Deepin in Virtualbox on the Macbook, and it's a very nice distro, can't find any other issues with it at all. It's quite customisable, for changing looks and how it works etc.
     
    MoodyBlues likes this.
  9. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    I'm not familiar with Matebook. :thinking:

    If you're open to other brands, I really can't say enough about System76. It's not just their products' stellar quality, but the company's commitment to top-notch customer service that has me sold on them.
     
    mikedt likes this.
  10. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    I was only halfway paying attention during a 'Tech Smart' segment on the morning news today. Halfway, because its topic was Micro$oft's unveiling of some new products. But my ears perked up when I heard 'Android.' :)

    Apparently, in keeping with M$'s new strategy of embracing Linux, at least one of their new products will 'run any Android app.' :eek: Sorry, I don't know which product, and I don't know if Android will actually be its OS, or what. But it's further proof that M$ couldn't beat 'em, so they're joining 'em. :D
     
    mikedt and GameTheory like this.
  11. GameTheory

    GameTheory Android Expert

    Surface Duo which will run android and scheduled for end of 2020.
    https://www.cnet.com/news/surface-duo-no-microsoft-isnt-making-another-windows-phone/
     
    mikedt and MoodyBlues like this.
  12. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    GameTheory likes this.
  13. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

  14. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    This is a very quick read about Linus Torvalds and his take on anti-Micro$oft feelings.

    After you read it, how about sharing your thoughts? Are you on the die-hard anti-M$ side? Or do you get all warm and fuzzy thinking about all this? It shouldn't surprise anyone too much that I'm in the former group. I'm fully aware of how opinionated and passionate I am about this, but I got that way based on facts and personal experience. It'll take awhile to fully convince me that there's nothing nefarious going on in this 'new M$' world.
     
  15. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    Hey, sudo users! Apparently there was a flaw in sudo that could let an intruder wreak all kinds of havoc on *nix systems. Of course, first the intruder would have to get in, then get a CLI, then know how to exploit this vulnerability... But it is a serious flaw that now has a fix, which we should all get.
     
    GameTheory likes this.
  16. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    The author of this article about Ubuntu 19.10 is very happy about two of its features: "What makes 19.10 so special to me personally? ZFS and vastly improved hardware support." He explains both in some detail.

    You know...one of these days...I really ought to do some upgrading around here. My main computer, the System76 laptop, is still happily humming along on Kubuntu 14.04. :eek:
     
  17. lunatic59

    lunatic59 Moderati ergo sum
    Moderator

    You should.

    I just installed Mint 19.2 on an old Dell laptop and the thing is humming along just fine.
     
    MoodyBlues likes this.
  18. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    Oh, nice! Are there any specific new features you like and find that you're using a lot?

    One of these days... Yep...
     
  19. lunatic59

    lunatic59 Moderati ergo sum
    Moderator

    To tell you the truth, I just keep up to date for the kernel. As long as my CLI keeps working, fancy features don't really interest me that much.
     
  20. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    I found this pretty informative and hope you do, too: 14 Linux apps that will change how you work

    The article states: "(Note: many of them are also available for macOS and Windows, so if you have to hop between operating systems, you can keep at least a semblance of consistency.)"

    I think that's very good.

    It also brings up the GIMP, which was bashed around these parts recently as being something to be ashamed of, and not fit to be put on a resumé. The article's take on it?:

    "If you're willing to put a little effort into making the switch, you will love the free, open source GNU Image Manipulation Program (GIMP), which is just as powerful as Photoshop."

    A few of the programs are completely new to me; one in particular caught my eye and piqued my interest:

    "Here's one for the command-line jockeys: Xiki, a truly amazing and useful open-source enhancement for command shells (bash, zsh, etc.) that merges shell and GUI concepts and, as explained by Linux.com, "runs in a text editor, so everything is editable.” It will let you save Xiki sessions in a text editor."

    What do you think, my fellow CLI lovers? :D
     
  21. GameTheory

    GameTheory Android Expert

    Well since I'm the one that made that statement and still stand behind it...

    I'll say this: That article you linked made no actual comparison of the two products and "just as powerful as Photoshop" is just an opinion. Had he compared the two, he would see the difference favors photoshop.

    Here's a comparison of the two by Harry who actually does some graphic work...
    https://www.makeuseof.com/tag/can-photoshop-gimp-cant/

    How do you think a professional is gonna do "print" work without CMYK color mode which GIMP does not have? Photoshop has had this since I could remember. If you'd like to see for yourself, in gimp go to "Image > Mode".

    Since I use both, here are the color modes for the two...
    Gimp (latest version): RGB, Grayscale, Indexed
    Photoshop (old 2012 version): Bitmap, Grayscale, Duotone, Indexed, RGB, CMYK, Lab, Multichannel

    Now I haven't upgraded Photoshop from my old 2012 version, but I here the latest is leagues ahead.
     
  22. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    You left out the facts he stated, not opinion:

    "GIMP provides sophisticated color management, the ability to read and write all common graphics file formats, customization through scripting and support for input devices such as pressure and tilt sensitive tablets and USB and MIDI controllers. You can also load and save files using FTP, HTTP, SMB, and SFTP/SSH directly from GIMP. One of the most mature FOSS projects out there, GIMP is outstanding."

    I can't argue any of the other points you made, as I've never touched PS, only seen it on my daughter's [Mac] computers.
     
  23. GameTheory

    GameTheory Android Expert

    I didn't leave out facts, but simply touched on the opinion you highlighted in blue letters.

    The question that is always avoided by gimp die-hards...
    How does one think a professional is gonna do "print" work in gimp without CMYK color mode which GIMP does not have???

    How could one say gimp is "just as powerful as Photoshop" without CMYK color mode?
     
  24. GameTheory

    GameTheory Android Expert

    I'll add this for gimp users...
    Imagemagick comes pre-installed on *buntu distros.
    Just run this for your image from the command-line to get CMYK.
    Code (Text):
    1. convert input.jpg -colorspace cmyk -compress LZW output.tif
    Note: You shouldn't have to do workarounds like this in "professional software".
     
  25. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member Thread Starter

    What qualifies as 'print' as you mean it? I'm curious because I've been on CafePress since 2001, and sold hundreds of thousands of products with my designs 'printed' on them, and all I've ever used is GIMP. As I recall, CP -requires- that all images be in RGB format, specifically stating not to upload CMYK. The products range from shirts to bumper stickers, and everything in between. (I haven't worked on my shops since before I got sick, but I'm very sure about the RGB thing.) So what is that? I call it printing. So does CP. :)

    As for ImageMagick, I've used it for decades. My photography products require 14 different files from each image. Here's a snippet from an interactive shell script I wrote in 2012; it did the grunt work for me:

    Code (Text):
    1.  
    2. # This is for images from the Nikon D5100, 4928x3264
    3.  convert $INPUTFILE -resize 739x490 -verbose "$OUTPUTFILE"_input_15.jpg
    4.  convert $INPUTFILE -resize 1232x816 -verbose "$OUTPUTFILE"_input_25.jpg
    5.  convert $INPUTFILE -resize 1478x979 -verbose "$OUTPUTFILE"_input_30.jpg
    6.  convert $INPUTFILE -resize 1971x1306 -verbose "$OUTPUTFILE"_input_40.jpg
    7.  convert $INPUTFILE -resize 2464x1632 -verbose "$OUTPUTFILE"_input_50.jpg
    8.  convert $INPUTFILE -resize 3696x2448 -verbose "$OUTPUTFILE"_input_75.jpg
    9.  cp -v $INPUTFILE "$OUTPUTFILE"_input_100.jpg
    10.  convert $INPUTFILE -resize 6160x4080 -verbose "$OUTPUTFILE"_input_125.jpg
    11.  convert $INPUTFILE -resize 7392x4896 -verbose "$OUTPUTFILE"_input_150.jpg
    12.  convert $INPUTFILE -resize 8624x5712 -verbose "$OUTPUTFILE"_input_175.jpg
    13.  convert $INPUTFILE -resize 9856x6528 -verbose "$OUTPUTFILE"_input_200.jpg
    14.  convert $INPUTFILE -resize 12320x8160 -verbose "$OUTPUTFILE"_input_250.jpg
    15.  convert $INPUTFILE -resize 14784x9792 -verbose "$OUTPUTFILE"_input_300.jpg
    16.  convert $INPUTFILE -resize 17248x11424 -verbose "$OUTPUTFILE"_input_350.jpg
    17.  
    As noted, I've never needed CMYK, but it's good to know IM can easily do the conversion. Thanks for posting its command.
     
Loading...

Share This Page

Loading...