Skip to content

Commit

Permalink
Handle initial renames where there is nothing there to discern a temp…
Browse files Browse the repository at this point in the history
…late.
  • Loading branch information
Raynes committed Sep 4, 2011
1 parent ac2ff27 commit 9329b11
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/mkvrename/core.clj
Expand Up @@ -7,15 +7,27 @@

(defn rename [template n f]
(let [new-file (file cd (str template n ".mkv"))]
(println (str "Renaming " f " to " new-file))
(println (str "Renaming " (.getName f) " to " (.getName new-file)))
(.renameTo f new-file)))

(defn prompt-read [& strs]
(map (fn [s]
(print s)
(flush)
(read-line))
strs))

(defn template [f]
(if f
(re-find #".*- S\d+E" (.getName f))
(apply format "%s - S%sE" (prompt-read "Show Title: " "This Season: "))))

(defn -main [& args]
(let [[new done] (separate #(.startsWith (.getName %) "title")
(filter (comp (partial re-find #".*\.mkv") str)
(file-seq (file cd))))
done-count (inc (count done))
template (re-find #".*- S\d+E" (.getName (first done)))]
template (template (first done))]
(doall
(map (partial rename template)
(range done-count (+ (count new) done-count))
Expand Down

0 comments on commit 9329b11

Please sign in to comment.