Skip to content

Commit

Permalink
Video sort ignores punctuation #611
Browse files Browse the repository at this point in the history
  • Loading branch information
A S Lewis committed Jan 8, 2024
1 parent 8fba420 commit 43d074b
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Problems can be reported at `our GitHub page <https://github.com/axcore/tartube/

Stable release: **v2.5.0 (3 Jan 2024)**

Development release: **v2.5.0 (3 Jan 2024)**
Development release: **v2.5.003 (8 Jan 2024)**

Official packages (also available from the `Github release page <https://github.com/axcore/tartube/releases>`__):

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.0
2.5.003
6 changes: 3 additions & 3 deletions nsis/tartube_install_64bit.nsi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Tartube v2.5.0 installer script for MS Windows
# Tartube v2.5.003 installer script for MS Windows
#
# Copyright (C) 2019-2024 A S Lewis
#
Expand Down Expand Up @@ -294,7 +294,7 @@

;Name and file
Name "Tartube"
OutFile "install-tartube-2.5.0-64bit.exe"
OutFile "install-tartube-2.5.003-64bit.exe"

;Default installation folder
InstallDir "$LOCALAPPDATA\Tartube"
Expand Down Expand Up @@ -397,7 +397,7 @@ Section "Tartube" SecClient
# "Publisher" "A S Lewis"
# WriteRegStr HKLM \
# "Software\Microsoft\Windows\CurrentVersion\Uninstall\Tartube" \
# "DisplayVersion" "2.5.0"
# "DisplayVersion" "2.5.003"

# Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
Expand Down
4 changes: 2 additions & 2 deletions pack/bin/no_download/tartube
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import mainapp

# 'Global' variables
__packagename__ = 'tartube'
__version__ = '2.5.0'
__date__ = '3 Jan 2024'
__version__ = '2.5.003'
__date__ = '8 Jan 2024'
__copyright__ = 'Copyright \xa9 2019-2024 A S Lewis'
__license__ = """
Copyright \xa9 2019-2024 A S Lewis.
Expand Down
4 changes: 2 additions & 2 deletions pack/bin/pkg/tartube
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import mainapp

# 'Global' variables
__packagename__ = 'tartube'
__version__ = '2.5.0'
__date__ = '3 Jan 2024'
__version__ = '2.5.003'
__date__ = '8 Jan 2024'
__copyright__ = 'Copyright \xa9 2019-2024 A S Lewis'
__license__ = """
Copyright \xa9 2019-2024 A S Lewis.
Expand Down
4 changes: 2 additions & 2 deletions pack/bin/strict/tartube
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import mainapp

# 'Global' variables
__packagename__ = 'tartube'
__version__ = '2.5.0'
__date__ = '3 Jan 2024'
__version__ = '2.5.003'
__date__ = '8 Jan 2024'
__copyright__ = 'Copyright \xa9 2019-2024 A S Lewis'
__license__ = """
Copyright \xa9 2019-2024 A S Lewis.
Expand Down
2 changes: 1 addition & 1 deletion pack/tartube.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH man 1 "3 Jan 2024" "2.5.0" "tartube man page"
.TH man 1 "8 Jan 2024" "2.5.003" "tartube man page"
.SH NAME
tartube \- GUI front-end for youtube-dl and yt-dlp
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
# Setup
setuptools.setup(
name = 'tartube',
version = '2.5.0',
version = '2.5.003',
description = 'GUI front-end for youtube-dl and yt-dlp',
long_description = long_description,
long_description_content_type = 'text/plain',
Expand Down
17 changes: 17 additions & 0 deletions tartube/mainapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import platform
import re
import shutil
import string
import sys
import threading
import time
Expand Down Expand Up @@ -8267,6 +8268,22 @@ def update_db(self, version):
for options_obj in self.ffmpeg_reg_dict.values():
options_obj.options_dict['extra_override_flag'] = False

if version < 2005002: # v2.5.002

# This version updates each media.Video's .natname, to remove
# punctuation and leading/trailing zeroes
for media_data_obj in self.media_reg_dict.values():
if isinstance(media_data_obj, media.Video):

natname = media_data_obj.natname
natname = natname.translate(
str.maketrans('', '', string.punctuation)
)
natname = natname.strip()
natname = re.sub(r'^[\s]+', ' ', natname)

media_data_obj.natname = natname

# --- Do this last, or the call to .check_integrity_db() fails -------
# --------------------------------------------------------------------

Expand Down
22 changes: 16 additions & 6 deletions tartube/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import functools
import os
import re
import string
import time


Expand All @@ -55,8 +56,9 @@ class GenericMedia(object):
def get_natural_name(self, name):

"""Converts the specified name so it is suitable for so-called
'natural' sorting, adding leading zeroes and reducing to all-lower
case.
'natural' sorting, removing leading/trailing whitespace, remove
punctuation, adding leading zeroes to numbers, and reducing to
all-lower case.
Based on the algorithm by Stephen Quan:
https://stackoverflow.com/questions/4836710/
Expand All @@ -67,6 +69,10 @@ def get_natural_name(self, name):
"""

name = name.translate(str.maketrans('', '', string.punctuation))
name = name.strip()
name = re.sub(r'^[\s]+', ' ', name)

return re.sub(
r'\d+',
lambda m: m.group(0).rjust(10, '0'), name
Expand Down Expand Up @@ -1892,7 +1898,8 @@ def __init__(self, app_obj, dbid, name, parent_obj=None, options_obj=None,
# If the video's JSON data has not been fetched, self.name and
# self.nickname are the same
self.nickname = name
# Modified version of self.nickname, padded with leading zeroes and
# Modified version of self.nickname, with leading/trailing whitespace
# removed, punctuation removed, padded with leading zeroes and
# reduced to lower case; used in so-called 'natural' sorting of names
self.natname = name
# Download source (a URL)
Expand Down Expand Up @@ -3457,7 +3464,8 @@ def __init__(self, app_obj, dbid, name, parent_obj=None, options_obj=None):
# Channel nickname (displayed in the Video Index; the same as .name,
# unless the user changes it)
self.nickname = name
# Modified version of self.nickname, padded with leading zeroes and
# Modified version of self.nickname, with leading/trailing whitespace
# removed, punctuation removed, padded with leading zeroes and
# reduced to lower case; used in so-called 'natural' sorting of names
self.natname = name
# Download source (a URL)
Expand Down Expand Up @@ -3802,7 +3810,8 @@ def __init__(self, app_obj, dbid, name, parent_obj=None, options_obj=None):
# Playlist nickname (displayed in the Video Index; the same as .name,
# unless the user changes it)
self.nickname = name
# Modified version of self.nickname, padded with leading zeroes and
# Modified version of self.nickname, with leading/trailing whitespace
# removed, punctuation removed, padded with leading zeroes and
# reduced to lower case; used in so-called 'natural' sorting of names
self.natname = name
# Download source (a URL)
Expand Down Expand Up @@ -4167,7 +4176,8 @@ def __init__(self, app_obj, dbid, name, parent_obj=None, options_obj=None,
# unless the user changes it). Note that the nickname of a fixed
# folder can't be changed
self.nickname = name
# Modified version of self.nickname, padded with leading zeroes and
# Modified version of self.nickname, with leading/trailing whitespace
# removed, punctuation removed, padded with leading zeroes and
# reduced to lower case; used in so-called 'natural' sorting of names
self.natname = name

Expand Down
4 changes: 2 additions & 2 deletions tartube/tartube
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import mainapp

# 'Global' variables
__packagename__ = 'tartube'
__version__ = '2.5.0'
__date__ = '3 Jan 2024'
__version__ = '2.5.003'
__date__ = '8 Jan 2024'
__copyright__ = 'Copyright \xa9 2019-2024 A S Lewis'
__license__ = """
Copyright \xa9 2019-2024 A S Lewis.
Expand Down
9 changes: 6 additions & 3 deletions tartube/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import re
import requests
import shutil
import string
import subprocess
import sys
import time
Expand Down Expand Up @@ -2008,9 +2009,11 @@ def extract_timestamps_from_descrip(app_obj, descrip):
# Remove punctuation in the title, such as the hyphen in a line
# like 'Intro - 15.52', and strip leading/trailing whitespace
if title != '':
# !!! DEBUG This is not yet tested on other alphabets
title = re.sub(r'\s\W+\s', ' ', title)
title = strip_whitespace(title)
title = title.translate(
str.maketrans('', '', string.punctuation),
)
title = title.strip()
title = re.sub(r'^[\s]+', ' ', title)

# Use None as the title, rather than an empty string
if title == '':
Expand Down

0 comments on commit 43d074b

Please sign in to comment.