-
Notifications
You must be signed in to change notification settings - Fork 1
/
podfeedgen.py
executable file
·86 lines (79 loc) · 2.2 KB
/
podfeedgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import PyRSS2Gen as rss
import os
import sys
import datetime
import convert
from functools import reduce
from os import path
import urllib.parse
import random
port=3000+random.randint(0,10)
print(port)
esc=urllib.parse.quote
# def esc(s):
# sym = {
# # "%": '%25',
# " ": '%20',
# "<": '%3C',
# ">": '%3E',
# "#": '%23',
# "{": '%7B',
# "}": '%7D',
# '|': '%7C',
# '\\': '%5C',
# '^': '%5E',
# '~': '%7E',
# '[': '%5B',
# ']': '%5D',
# '`': '%60',
# ';': '%3B',
# '/': '%2F',
# '?': '%3F',
# ':': '%3A',
# '@': '%40',
# '=': '%3D',
# '&': '%26',
# '$': '%24',
# }
# for i in sym:
# s = s.replace(i, sym[i])
# return s
def _cmp(x):
import re
if len(re.findall(r'.*?(\d+).*(.mp3|.m4v|.M4V|.mp4|.MP4|.mov)$', x)) == 0:
return 0
else:
return int(re.findall(r'.*?(\d+).*(.mp3|.m4v|.M4V|.mp4|.MP4|.mov)$', x)[0][0])
dir = sys.argv[1]
print(os.listdir(dir))
url = sys.argv[2]
myDir = os.path.abspath('.')
os.chdir(dir)
convert.main(dir)
listDir = list(filter(lambda x: path.isdir(x), os.listdir(dir)))
if listDir:
print(listDir)
lm = list(map(lambda x: list(map(lambda k: x + '/' + k, os.listdir(x))), listDir))
print("lm:{}\n *********************".format(lm))
listDir = reduce(lambda x, y: x + y, lm)
files = list(filter(lambda x: path.splitext(x)[1] in [".MP3",".mp3",".M4V", ".m4v", '.mp4',".MP4", ".mov"], listDir + os.listdir(dir)))
files.sort(key=_cmp)
myItems = [(rss.RSSItem(
title=n,
description='',
enclosure=rss.Enclosure(url+':'+str(port) + '/' + esc(n), 0, "audio/mpeg")
)) for n in files]
myItems.reverse()
feed = rss.RSS2(
title=path.basename(path.abspath(dir)),
link="http://unnotigkeit.ya.ru",
description="",
lastBuildDate=datetime.datetime.now(),
items=myItems
)
feed.write_xml(open((dir + '/' + path.basename(path.abspath(dir)) + ".xml"), "w"), "utf-8")
print(url+':'+str(port)+ '/' + esc(path.basename(path.abspath(dir))) + ".xml")
import http.server
os.system('python3 -m http.server {}'.format(port))