Move Movies of different Encodes to a common Folder with original Movie Title

前端 未结 2 932
挽巷
挽巷 2021-01-28 17:26

So I am having this situation... I have many files in my Folder which will look like this

Iron.Man.2008.1440p.UHD.US.BluRay.x265.HDR.DD5.1-Pahe.in
Iron Man 2008.7         


        
2条回答
  •  温柔的废话
    2021-01-28 17:56

    with bash using the regex pattern matching with BASH_REMATCH

    #!/usr/bin/env bash
    
    declare -A uniq
    
    ##: The script should be inside the directory where the video files are
    for files in *; do
      if [[ $files =~ ^(.*[[:digit:]]{4})\.(.+)$ ]]; then
        no_space=${BASH_REMATCH[1]// /.}
        uniq[$no_space]=1
        all_files+=("${BASH_REMATCH[0]}")
        first_part+=("${BASH_REMATCH[1]}")
      fi
    done
    
    for j in "${!uniq[@]}"; do
      mkdir -p "$j"
      dir+=("$j")
    done
    
    for i in "${!all_files[@]}"; do
      for k in "${dir[@]}"; do
        if [[ ${first_part[$i]// /.} == $k ]]; then
          mv -v  "${all_files[$i]}" "$k"
        fi
      done
    done
    

    Version 2.0 which try to match all the new file format/pattern.

    #!/usr/bin/env bash
    
    declare -A uniq
    
    for files in *; do
      if [[ $files =~ ^(.*\(?[[:digit:]]{4}\)?)[\.[[:blank:]]]?(.+)$ ]]; then
        no_space=${BASH_REMATCH[1]// /.}
        uniq[$no_space]=1
        all_files+=("${BASH_REMATCH[0]}")
        first_part+=("${BASH_REMATCH[1]}")
      fi
    done
    
    for j in "${!uniq[@]}"; do
      mkdir -p "${j//[)(]}"
      dir+=("$j")
    done
    
    for i in "${!all_files[@]}"; do
      for k in "${dir[@]}"; do
      if [[ ${first_part[$i]// /.} == $k ]]; then
        mv -v  "${all_files[$i]}" "${k//[)(]}"
      fi
      done
    done
    
    • Just try it out for a couple of sample files and not the whole 4k files like what you have now.

    • also make a backup of the files just in case.

提交回复
热议问题