forked from Github/guess-filename.py
added patterns for xfce screenshot tool
This commit is contained in:
parent
83bdf8d62a
commit
02860695ab
2 changed files with 29 additions and 2 deletions
22
guessfilename.py
Normal file → Executable file
22
guessfilename.py
Normal file → Executable file
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
PROG_VERSION = u"Time-stamp: <2017-11-29 19:13:06 vk>"
|
||||
PROG_VERSION = u"Time-stamp: <2017-12-02 13:27:40 vk>"
|
||||
|
||||
|
||||
# TODO:
|
||||
|
|
@ -111,6 +111,7 @@ class GuessFilename(object):
|
|||
# ( (date(time)?)?(--date(time)?)? )? filename (tags)? (extension)?
|
||||
DAY_REGEX = '[12]\d{3}-?[01]\d-?[0123]\d' # note: I made the dashes between optional to match simpler format as well
|
||||
TIME_REGEX = 'T[012]\d.[012345]\d(.[012345]\d)?'
|
||||
TIME_FUZZY_REGEX = '([012]\d)[-._:]?([012345]\d)([-._:]?([012345]\d))?' # a bit less restrictive than TIME_REGEX
|
||||
|
||||
DAYTIME_REGEX = '(' + DAY_REGEX + '(' + TIME_REGEX + ')?)'
|
||||
DAYTIME_DURATION_REGEX = DAYTIME_REGEX + '(--?' + DAYTIME_REGEX + ')?'
|
||||
|
|
@ -160,6 +161,12 @@ class GuessFilename(object):
|
|||
|
||||
RECORDER_REGEX = re.compile('rec_([12]\d{3})([01]\d)([0123]\d)-([012]\d)([012345]\d)(.+)?.(wav|mp3)')
|
||||
|
||||
# Screenshot_2017-11-29_10-32-12.png
|
||||
# Screenshot_2017-11-07_07-52-59 my description.png
|
||||
SCREENSHOT1_REGEX = re.compile('Screenshot_(' + DAY_REGEX + ')_' + TIME_FUZZY_REGEX + '(.*).png')
|
||||
|
||||
|
||||
|
||||
logger = None
|
||||
config = None
|
||||
|
||||
|
|
@ -508,6 +515,7 @@ class GuessFilename(object):
|
|||
if regex_match:
|
||||
return self.build_string_via_indexgroups(regex_match, self.VID_INDEXGROUPS)
|
||||
|
||||
# 2017-11-30:
|
||||
# rec_20171129-0902 A nice recording .wav -> 2017-11-29T09.02 A nice recording.wav
|
||||
# rec_20171129-0902 A nice recording.wav -> 2017-11-29T09.02 A nice recording.wav
|
||||
# rec_20171129-0902.wav -> 2017-11-29T09.02.wav
|
||||
|
|
@ -579,6 +587,18 @@ class GuessFilename(object):
|
|||
if datetimestr and self.contains_one_of(oldfilename, ["hipster", "Hipster"]):
|
||||
return datetimestr + ' Hipster-PDA vollgeschrieben -- scan notes.' + extension
|
||||
|
||||
# 2017-12-02: Files from screenshots from xfce-tool "Screenshot"
|
||||
# example: Screenshot_2017-11-07_07-52-59 my description.png
|
||||
regex_match = re.match(self.SCREENSHOT1_REGEX, oldfilename)
|
||||
if regex_match:
|
||||
if regex_match.group(6):
|
||||
# there is a description with a leading space after the time
|
||||
my_description = regex_match.group(6)
|
||||
else:
|
||||
my_description = ''
|
||||
return self.build_string_via_indexgroups(regex_match, [1, 'T', 2, '.', 3, '.', 5, my_description, ' -- screenshots.png'])
|
||||
|
||||
|
||||
# FIXXME: more cases!
|
||||
|
||||
return False # no new filename found
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8; mode: python; -*-
|
||||
# Time-stamp: <2017-11-29 19:07:42 vk>
|
||||
# Time-stamp: <2017-12-02 12:58:51 vk>
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
|
|
@ -131,6 +131,13 @@ class TestGuessFilename(unittest.TestCase):
|
|||
self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename("rec_20171129-0902.mp3"),
|
||||
"2017-11-29T09.02.mp3")
|
||||
|
||||
# Screenshot_2017-11-29_10-32-12.png
|
||||
self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename("Screenshot_2017-11-29_10-32-12.png"),
|
||||
"2017-11-29T10.32.12 -- screenshots.png")
|
||||
# Screenshot_2017-11-07_07-52-59 my description.png
|
||||
self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename("Screenshot_2017-11-29_10-32-12 my description.png"),
|
||||
"2017-11-29T10.32.12 my description -- screenshots.png")
|
||||
|
||||
def test_contains_one_of(self):
|
||||
|
||||
self.assertTrue(self.guess_filename.contains_one_of("foo bar baz", ['foo']))
|
||||
|
|
|
|||
Loading…
Reference in a new issue