== Nächstes Treffen der Study Group für Anfängerinnen und Anfänger: Dienstag 14. 8. 2019 ==
* https://www.meetup.com/PYUGAT/events/263607422/
* Datum und Zeit: Dienstag, 14. August 2019, 17:30 Uhr ([[https://metalab.at/calendar/event/5572/icalendar/|.ics]])
* Ort: '''Metalab, Rathausstraße 6, 1010 Wien''' (MetalabWiki:Lage, [[http://maps.google.at/maps?q=metalab,+rathausstraße+6,+wien|Google Maps]])
Python gilt als leicht verständich, gut zu erlernen und eine ausgezeichnete Sprache zum Einstieg ins Programmieren.
Im Mittelpunkt dieser Gruppe sollen Learning-by-Doing, gemeinsames Ausarbeiten von Problemen und gegenseitiges Helfen stehen.
Herzlich eingeladen sind alle, die gerade angefangen haben oder anfangen möchten, sich mit Python oder dem Programmieren zu beschäftigen
Die Treffen werden auch auf [[Treffen/Ankündigungen|diversen Webseiten und Mailinglisten angekündigt]].
'''Aufgabe für dieses mal''';
last python study group we did a theoretical lesson - so we will do a coding session this time. During next lesson on 14th of August I have an optional project for you (this is the project I am working on at the moment) - if you want, you can code something for this project or otherwise we would ask you to work at your own project in python - we will surely have the time to look at your project or what you've learned together surely everyone will have the opportunity to ask their questions to the senior python-team.
Find my example here: https://bitbucket.org/stormtrooper02/dvd-backup/src/master/
The project is around ripping dvd's... I want to store my dvd's at my homeserver - so watching DVD's is possible without DVD-Player - I would like to ask you to think about the best way to realize it until next week - you also can start implementing at home.
Prerequisite you have:<
> OUTPUTFILE.chapters
* mplayer printing the metadata of a dvd into the shell
* in the line CHAPTERS you find all chapter timestamps in seconds
* line 'ID_LENGTH=' is the total length of the movie in seconds
metadata.txt <
>
* I am ripping with the cli-tool ffmpeg. For chapter-separations you have to prepare the chapter information (from OUTPUTFILE.chapters) into the metadata-file.
* chapter titles should be "chapter \#1" to "chapter \#30"
This is Adi's solution:
{{{#!highlight python
dir = '/home/adi/Videos/'
chaptersfile = 'Red_Heat.chapters'
film_title = 'Red Heat'
outputfile = chaptersfile.rsplit('.', 1)[0] + '.metadata'
time_offset = 36 # if you want to cut the first 36 seconds of the video away the chapter marks have to be earlier
'''
This program prepares you a metadata file for ripping DVD's with ffmpeg.
You need to extract the chapter information in the DVD with the command 'mplayer -identify dvd://1' before processing the data.
'''
def read_chapterfile():
chaptermarks = ''
total_secs = ''
with open(dir + chaptersfile, 'r', encoding='utf-8') as originalfile:
content = originalfile.readlines()
for line in content:
if line.startswith('CHAPTERS: '):
chaptermarks = line[10:-2].split(',')
if line.startswith('ID_LENGTH'):
total_secs = float(line[10:])
end_time = "{0:02d}:{1:02d}:{2:06.3f}".format(int(total_secs / 3600), int(total_secs % 3600 / 60),
total_secs % 3600 % 60)
chaptermarks.append(end_time)
return chaptermarks
if __name__ == '__main__':
chaptermarks = read_chapterfile()
oldtime = None
newtime = None
with open(dir + outputfile, 'w') as mytxtfile:
mytxtfile.write(";FFMETADATA1\n")
mytxtfile.write("title={0}\n".format(film_title))
mytxtfile.write(";begin film encoding at second {0} with 'ffmpeg -ss 00:00:{0:02d}'\n".format(time_offset))
mytxtfile.close()
for i in range(len(chaptermarks)):
oldtime = newtime
if oldtime == None:
timelist_str = chaptermarks[i].split(':')
timelist_float = [float(i) for i in timelist_str]
hours, minutes, seconds = timelist_float
newtime = hours * 60 * 60 + minutes * 60 + seconds
continue
timelist_str = chaptermarks[i].split(':')
timelist_float = [float(i) for i in timelist_str]
hours, minutes, seconds = timelist_float
newtime = hours * 60 * 60 + minutes * 60 + seconds - time_offset
# print('{0} -> {1:06.3f}'.format(oldtime,newtime))
with open(dir + outputfile, 'a') as mytxtfile:
string = '\n[CHAPTER]\n' \
'TIMEBASE=1/1\n' \
'START={0}\n' \
'END={1}\n' \
'title= {2} / chapter {3:02d}\n'.format(oldtime, newtime, chaptermarks[i - 1].rsplit('.', 1)[0], i)
mytxtfile.write(string)
}}}
This is Wayne's solution:
{{{#!highlight python
with open("chapters.txt") as f:
content = f.readlines ()
allTimes = []
MaxLength = 0
for index,line in enumerate(content):
if line.startswith('ID_LENGTH'):
MaxLength = float(line[10:-2])
if line.startswith('CHAPTER'):
chapters = line[10:-2].split(',')
for chapterTime in chapters:
hours, minutes, seconds = [float(i) for i in chapterTime.split(':')]
seconds = seconds + minutes * 60 + hours * 60 * 60
allTimes.append(seconds)
allTimes.append(MaxLength)
FileString = ';FFMETADATA1\n\n'
for idx in range(len(allTimes)-1):
FileString += f'''
[CHAPTER]
TIMEBASE=1/1
START={allTimes[idx]:.2f}
END={allTimes[idx+1]:.2f}
title=chapter #{idx+1}
'''
with open("meta.txt",'w') as metafile:
metafile.write(FileString)
# TLDR;
# camelCase
# PascalCase // class
# snake_case // variable ,function
# kebab-case
}}}
----
CategoryShownotes