Skip to content

Commit

Permalink
Restructure repo
Browse files Browse the repository at this point in the history
  • Loading branch information
amsehili committed Dec 1, 2024
1 parent 295dfe0 commit a8d7851
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 55 deletions.
47 changes: 23 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
[build-system]
requires = ["setuptools", "wheel"]

[project]
name = "generss"
dynamic = ["version"]

authors = [
{name = "Amine Sehili", email = "amine.sehili@gmail.com"},
]

This comment has been minimized.

Copy link
@denilsonsa

denilsonsa Dec 1, 2024

Contributor

Shouldn't authors be under [project]?

This comment has been minimized.

Copy link
@denilsonsa

denilsonsa Dec 2, 2024

Contributor

Fixed in 54b9cad


[project]
name = "generss"
dynamic = ["version"]
description = "Generate RSS feeds from media files in a directory"
readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">=3.4"
keywords = ["RSS", "podcast"]
license = {text = "MIT License"}
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Communications :: File Sharing",
"Topic :: Utilities",
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Communications :: File Sharing",
"Topic :: Utilities",
]
dependencies = ["mutagen==1.47.0", "eyed3==0.9.7"]


[project.scripts]
genRSS = "genRSS:main"

[tool.setuptools.dynamic]
version = {attr = "genRSS.__version__"}

[tool.setuptools.dynamic]
version = {attr = "genRSS.__version__"}
43 changes: 18 additions & 25 deletions src/genRSS.py → src/genRSS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
genRSS -- generate an RSS 2.0 feed from media files in a directory.
@author: Amine SEHILI
@copyright: 2014-2023 Amine SEHILI
@copyright: 2014-2024 Amine SEHILI
@license: MIT
@contact: amine.sehili <AT> gmail.com
@deffield updated: September 13th 2023
@deffield updated: December 1st 2024
"""

import sys
Expand All @@ -19,12 +19,12 @@
import argparse
from xml.sax import saxutils

import util
from genRSS import util

__all__ = []
__version__ = "0.3.0"
__version__ = "0.3.1"
__date__ = "2014-11-01"
__updated__ = "2023-09-13"
__updated__ = "2024-12-01"

DEBUG = 0
TESTRUN = 0
Expand All @@ -44,9 +44,7 @@ def main(argv=None):
description=program_longdesc,
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
"--version", "-v", action="version", version=__version__
)
parser.add_argument("--version", "-v", action="version", version=__version__)
parser.add_argument(
"-d",
"--dirname",
Expand Down Expand Up @@ -184,9 +182,9 @@ def main(argv=None):
if host[-1] != "/":
host += "/"

if not host.lower().startswith(
"http://"
) and not host.lower().startswith("https://"):
if not host.lower().startswith("http://") and not host.lower().startswith(
"https://"
):
host = "http://" + host

title = ""
Expand All @@ -210,24 +208,23 @@ def main(argv=None):
if opts.extensions is not None:
opts.extensions = [e for e in opts.extensions.split(",") if e != ""]
file_names = util.get_files(
dirname, extensions=opts.extensions, recursive=opts.recursive, followlinks=opts.followlinks
dirname,
extensions=opts.extensions,
recursive=opts.recursive,
followlinks=opts.followlinks,
)
if len(file_names) == 0:
sys.stderr.write(
"No media files on directory '%s'\n" % (opts.dirname)
)
sys.stderr.write("No media files on directory '%s'\n" % (opts.dirname))
sys.exit(0)

if opts.sort_creation:
# sort files by date of creation if required
# get files date of creation in seconds
pub_dates = [os.path.getmtime(f) for f in file_names]
# most feed readers will use pubDate to sort items even if they are
# not sorted in the output file for readability, we also sort fileNames
# not sorted in the output file for readability, we also sort file_names
# according to pubDates in the feed.
sorted_files = sorted(
zip(file_names, pub_dates), key=lambda f: -f[1]
)
sorted_files = sorted(zip(file_names, pub_dates), key=lambda f: -f[1])

else:
# In order to have feed items sorted by name, we give them artificial
Expand Down Expand Up @@ -272,9 +269,7 @@ def main(argv=None):
)
)
outfp.write(" <title>{0}</title>\n".format(saxutils.escape(title)))
outfp.write(
" <description>{0}</description>\n".format(description)
)
outfp.write(" <description>{0}</description>\n".format(description))
outfp.write(" <link>{0}</link>\n".format(link))

if opts.image is not None:
Expand All @@ -287,9 +282,7 @@ def main(argv=None):

outfp.write(" <image>\n")
outfp.write(" <url>{0}</url>\n".format(imgurl))
outfp.write(
" <title>{0}</title>\n".format(saxutils.escape(title))
)
outfp.write(" <title>{0}</title>\n".format(saxutils.escape(title)))
outfp.write(" <link>{0}</link>\n".format(link))
outfp.write(" </image>\n")
outfp.write(f" <itunes:image href={saxutils.escape(title)}/>\n")
Expand Down
12 changes: 6 additions & 6 deletions src/util.py → src/genRSS/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def get_title(filename, use_metadata=False):
title (str): Item title.
Examples:
>>> media_dir = os.path.join("test", "media")
>>> media_dir = os.path.join("../../test", "media")
>>> flac_file = os.path.join(media_dir, 'flac_with_tags.flac')
>>> mp3_file = os.path.join(media_dir, 'mp3_with_tags.mp3')
Expand Down Expand Up @@ -296,13 +296,13 @@ def get_duration(filename):
duration (int): The duration as the number of seconds or None.
Examples:
>>> get_duration("test/silence/silence_7.14_seconds.ogg")
>>> get_duration("../../test/silence/silence_7.14_seconds.ogg")
7
>>> get_duration("test/silence/silence_2.5_seconds.wav")
>>> get_duration("../../test/silence/silence_2.5_seconds.wav")
2
>>> get_duration("test/media/flac_with_tags.flac") # empty file
>>> get_duration("../../test/media/flac_with_tags.flac") # empty file
0
>>> get_duration("test/media/1.mp3") is None # invalid file
>>> get_duration("../../test/media/1.mp3") is None # invalid file
True
"""
duration = get_duration_mutagen(filename)
Expand Down Expand Up @@ -487,7 +487,7 @@ def get_files(dirname, extensions=None, recursive=False, followlinks=False):
Examples:
>>> import os
>>> media_dir = os.path.join("test", "media")
>>> media_dir = os.path.join("../../test", "media")
>>> files = ['1.mp3', '1.mp4', '1.ogg', '2.MP3', 'flac_with_tags.flac', 'mp3_with_tags.mp3']
>>> expected = [os.path.join(media_dir, f) for f in files]
>>> get_files(media_dir) == expected
Expand Down

0 comments on commit a8d7851

Please sign in to comment.