-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed_itunes.py
executable file
·73 lines (62 loc) · 2.47 KB
/
feed_itunes.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from feedgen.feed import FeedGenerator
import datetime
import os
import time
from os import listdir
from os.path import isfile, isdir, join, islink
from eyed3.id3 import Tag
import platform
from mutagen.mp3 import MP3
import time
def creation_date(path_to_file):
if platform.system() == 'Windows':
return os.path.getctime(path_to_file)
else:
stat = os.stat(path_to_file)
try:
return stat.st_birthtime
except AttributeError:
return stat.st_mtime
fg = FeedGenerator()
fg.load_extension('podcast')
fg.title(u'Weszło FM')
fg.podcast.itunes_author(u'Weszło FM')
fg.link(href='http://weszlo.fm/', rel='alternate')
fg.subtitle(u'Nieoficjalny podcast WeszłoFM')
fg.language('pl')
fg.copyright('cc-by-Weszlo')
fg.podcast.itunes_summary(u'Podcast WeszłoFM')
fg.podcast.itunes_owner('Krzysztof Stanowski', 'krzysztof.stanowski@weszlo.com')
fg.link(href='https://www.simx.mobi/weszlo/', rel='self')
fg.podcast.itunes_explicit('no')
fg.image('https://i1.sndcdn.com/avatars-000421118988-38c4cq-t200x200.jpg')
fg.podcast.itunes_image('https://i1.sndcdn.com/avatars-000421118988-38c4cq-t200x200.jpg')
fg.podcast.itunes_category('Sport', 'Sport News')
root_path = os.getcwd() + "/"
only_folders_from_root_path = [f for f in listdir(
root_path) if isdir(join(root_path, f))]
items = []
for path_folder in only_folders_from_root_path:
path_files = root_path + path_folder
only_files = [f for f in listdir(
path_files) if isfile(join(path_files, f)) and not islink(join(path_files, f))]
for p in only_files:
path = p.decode('utf-8')
tag = Tag()
tag.parse(path_files + "/" + path)
item = fg.add_entry()
item.id(u"https://www.simx.mobi/weszlo/" + path_folder + "/" + path)
item.title(tag.title)
item.podcast.itunes_summary(tag.artist + " " + tag.title)
item.podcast.itunes_subtitle(tag.artist)
item.podcast.itunes_author(tag.artist)
item.enclosure(u"https://www.simx.mobi/weszlo/" + path_folder + "/" + path, 0, 'audio/mpeg')
audio = MP3(path_files + "/" + path)
normTime = time.strftime('%H:%M:%S', time.gmtime(audio.info.length))
item.podcast.itunes_duration(normTime)
dat = creation_date(path_files + "/" + path)
item.pubdate(str(datetime.datetime.fromtimestamp(dat)) + time.strftime("%z"))
items.append(item)
fg.rss_file('./feed.xml', pretty=True)