Exemple #1
0
 def prepare_filename(self, info_dict):
     filename = sanitize_path(info_dict["title"])
     filename = filename.replace(u'\u3010', u'[').replace(u'\u3011', u']')
     for char in filename[:]:
         if char not in allowed_chars:
             filename = filename.replace(char, u'')
     return compat_str(filename)
Exemple #2
0
    def test_sanitize_path(self):
        if sys.platform != 'win32':
            return

        self.assertEqual(sanitize_path('abc'), 'abc')
        self.assertEqual(sanitize_path('abc/def'), 'abc\\def')
        self.assertEqual(sanitize_path('abc\\def'), 'abc\\def')
        self.assertEqual(sanitize_path('abc|def'), 'abc#def')
        self.assertEqual(sanitize_path('<>:"|?*'), '#######')
        self.assertEqual(sanitize_path('C:/abc/def'), 'C:\\abc\\def')
        self.assertEqual(sanitize_path('C?:/abc/def'), 'C##\\abc\\def')

        self.assertEqual(sanitize_path('\\\\?\\UNC\\ComputerName\\abc'), '\\\\?\\UNC\\ComputerName\\abc')
        self.assertEqual(sanitize_path('\\\\?\\UNC/ComputerName/abc'), '\\\\?\\UNC\\ComputerName\\abc')

        self.assertEqual(sanitize_path('\\\\?\\C:\\abc'), '\\\\?\\C:\\abc')
        self.assertEqual(sanitize_path('\\\\?\\C:/abc'), '\\\\?\\C:\\abc')
        self.assertEqual(sanitize_path('\\\\?\\C:\\ab?c\\de:f'), '\\\\?\\C:\\ab#c\\de#f')
        self.assertEqual(sanitize_path('\\\\?\\C:\\abc'), '\\\\?\\C:\\abc')

        self.assertEqual(
            sanitize_path('youtube/%(uploader)s/%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s'),
            'youtube\\%(uploader)s\\%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s')

        self.assertEqual(
            sanitize_path('youtube/TheWreckingYard ./00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part'),
            'youtube\\TheWreckingYard #\\00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part')
        self.assertEqual(sanitize_path('abc/def...'), 'abc\\def..#')
        self.assertEqual(sanitize_path('abc.../def'), 'abc..#\\def')
        self.assertEqual(sanitize_path('abc.../def...'), 'abc..#\\def..#')

        self.assertEqual(sanitize_path('../abc'), '..\\abc')
        self.assertEqual(sanitize_path('../../abc'), '..\\..\\abc')
        self.assertEqual(sanitize_path('./abc'), 'abc')
        self.assertEqual(sanitize_path('./../abc'), '..\\abc')
    def test_sanitize_path(self):
        if sys.platform != 'win32':
            return

        self.assertEqual(sanitize_path('abc'), 'abc')
        self.assertEqual(sanitize_path('abc/def'), 'abc\\def')
        self.assertEqual(sanitize_path('abc\\def'), 'abc\\def')
        self.assertEqual(sanitize_path('abc|def'), 'abc#def')
        self.assertEqual(sanitize_path('<>:"|?*'), '#######')
        self.assertEqual(sanitize_path('C:/abc/def'), 'C:\\abc\\def')
        self.assertEqual(sanitize_path('C?:/abc/def'), 'C##\\abc\\def')

        self.assertEqual(sanitize_path('\\\\?\\UNC\\ComputerName\\abc'),
                         '\\\\?\\UNC\\ComputerName\\abc')
        self.assertEqual(sanitize_path('\\\\?\\UNC/ComputerName/abc'),
                         '\\\\?\\UNC\\ComputerName\\abc')

        self.assertEqual(sanitize_path('\\\\?\\C:\\abc'), '\\\\?\\C:\\abc')
        self.assertEqual(sanitize_path('\\\\?\\C:/abc'), '\\\\?\\C:\\abc')
        self.assertEqual(sanitize_path('\\\\?\\C:\\ab?c\\de:f'),
                         '\\\\?\\C:\\ab#c\\de#f')
        self.assertEqual(sanitize_path('\\\\?\\C:\\abc'), '\\\\?\\C:\\abc')

        self.assertEqual(
            sanitize_path(
                'youtube/%(uploader)s/%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s'
            ),
            'youtube\\%(uploader)s\\%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s'
        )

        self.assertEqual(
            sanitize_path(
                'youtube/TheWreckingYard ./00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part'
            ),
            'youtube\\TheWreckingYard #\\00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part'
        )
        self.assertEqual(sanitize_path('abc/def...'), 'abc\\def..#')
        self.assertEqual(sanitize_path('abc.../def'), 'abc..#\\def')
        self.assertEqual(sanitize_path('abc.../def...'), 'abc..#\\def..#')

        self.assertEqual(sanitize_path('../abc'), '..\\abc')
        self.assertEqual(sanitize_path('../../abc'), '..\\..\\abc')
        self.assertEqual(sanitize_path('./abc'), 'abc')
        self.assertEqual(sanitize_path('./../abc'), '..\\abc')
Exemple #4
0
    def test_sanitize_path(self):
        if sys.platform != "win32":
            return

        self.assertEqual(sanitize_path("abc"), "abc")
        self.assertEqual(sanitize_path("abc/def"), "abc\\def")
        self.assertEqual(sanitize_path("abc\\def"), "abc\\def")
        self.assertEqual(sanitize_path("abc|def"), "abc#def")
        self.assertEqual(sanitize_path('<>:"|?*'), "#######")
        self.assertEqual(sanitize_path("C:/abc/def"), "C:\\abc\\def")
        self.assertEqual(sanitize_path("C?:/abc/def"), "C##\\abc\\def")

        self.assertEqual(sanitize_path("\\\\?\\UNC\\ComputerName\\abc"), "\\\\?\\UNC\\ComputerName\\abc")
        self.assertEqual(sanitize_path("\\\\?\\UNC/ComputerName/abc"), "\\\\?\\UNC\\ComputerName\\abc")

        self.assertEqual(sanitize_path("\\\\?\\C:\\abc"), "\\\\?\\C:\\abc")
        self.assertEqual(sanitize_path("\\\\?\\C:/abc"), "\\\\?\\C:\\abc")
        self.assertEqual(sanitize_path("\\\\?\\C:\\ab?c\\de:f"), "\\\\?\\C:\\ab#c\\de#f")
        self.assertEqual(sanitize_path("\\\\?\\C:\\abc"), "\\\\?\\C:\\abc")

        self.assertEqual(
            sanitize_path("youtube/%(uploader)s/%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s"),
            "youtube\\%(uploader)s\\%(autonumber)s-%(title)s-%(upload_date)s.%(ext)s",
        )

        self.assertEqual(
            sanitize_path(
                "youtube/TheWreckingYard ./00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part"
            ),
            "youtube\\TheWreckingYard #\\00001-Not bad, Especially for Free! (1987 Yamaha 700)-20141116.mp4.part",
        )
        self.assertEqual(sanitize_path("abc/def..."), "abc\\def..#")
        self.assertEqual(sanitize_path("abc.../def"), "abc..#\\def")
        self.assertEqual(sanitize_path("abc.../def..."), "abc..#\\def..#")

        self.assertEqual(sanitize_path("../abc"), "..\\abc")
        self.assertEqual(sanitize_path("../../abc"), "..\\..\\abc")
        self.assertEqual(sanitize_path("./abc"), "abc")
        self.assertEqual(sanitize_path("./../abc"), "..\\abc")