Skip to content

Commit 2b491ab

Browse files
committed
- adding recording.png to distribution; this file will be used as a
thumbnail for recorded files (when MKVToolNix is installed). User specified file: user-recording.png - The thumbnail and the propertie will be written to a recorded file even when no chapter data exists
1 parent e29b034 commit 2b491ab

File tree

5 files changed

+64
-57
lines changed

5 files changed

+64
-57
lines changed

devel/build_install_pyradio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ then
521521
fi
522522
mkdir -p ~/.config/pyradio/data
523523
cp devel/pyradio.png ~/.config/pyradio/data
524+
cp devel/recording.png ~/.config/pyradio/data
524525
[ -z $PIPX ] || create_installation_type_file
525526
else
526527
do_exit

devel/pyradio.png

-91.8 KB
Loading

pyradio/config.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,23 @@ def _copy_icon(self):
216216
copy it from the icons dir
217217
'''
218218
if not path.exists(path.join(self.data_dir, 'pyradio.png')):
219-
from_file = path.join(path.dirname(__file__), 'icons', 'pyradio.png')
220-
to_file = path.join(self.data_dir, 'pyradio.png')
221-
try:
222-
copyfile(from_file, to_file)
223-
except:
224-
pass
219+
for an_icon in ('pyradio.png', 'recording.png'):
220+
from_file = path.join(path.dirname(__file__), 'icons', an_icon)
221+
to_file = path.join(self.data_dir, an_icon)
222+
try:
223+
copyfile(from_file, to_file)
224+
except:
225+
pass
225226

226227
''' make sure that the icon is under ~/.config/pyradio/data
227228
(the previous section may install it to a different location,
228229
if --config-dir is used).
229230
'''
230231
default_icon_location = path.join(getenv('HOME', '~'), '.config', 'pyradio', 'data')
231232
if default_icon_location != self.data_dir:
232-
to_file = path.join(default_icon_location, 'pyradio.png')
233-
if not path.exists(to_file):
233+
for an_icon in ('pyradio.png', 'recording.png'):
234+
from_file = path.join(path.dirname(__file__), 'icons', an_icon)
235+
to_file = path.join(default_icon_location, an_icon)
234236
try:
235237
copyfile(from_file, to_file)
236238
except:

pyradio/icons/recording.png

304 KB
Loading

pyradio/player.py

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,75 +3677,80 @@ def clear(self):
36773677
self._chapters_file = None
36783678

36793679
def write_chapters_to_file(self, input_file):
3680-
if input_file:
3681-
logger.error('input_file = "{}"'.format(input_file))
3680+
logger.error('input_file: "{}"'.format(input_file))
3681+
if input_file is None or input_file == '':
3682+
if logger.isEnabledFor(logging.INFO):
3683+
logger.info('empty input file provided! Exiting!')
3684+
else:
36823685
if self.HAS_MKVTOOLNIX:
36833686
if logger.isEnabledFor(logging.INFO):
36843687
logger.info('starting mkvmerge!')
3688+
logger.info('input_file: "{}"'.format(input_file))
36853689
threading.Thread(
36863690
target=self.write_chapters_to_file_thread(input_file)
36873691
)
36883692
else:
36893693
if logger.isEnabledFor(logging.INFO):
36903694
logger.info('mkvmerge not found!')
3691-
else:
3692-
if logger.isEnabledFor(logging.INFO):
3693-
logger.info('empty input file provided! Exiting!')
36943695

36953696
def write_chapters_to_file_thread(self, input_file):
3696-
if not input_file:
3697-
return False
3697+
opts = []
3698+
self._tag_file = input_file[:-4] + '.xml'
3699+
opts = [self.mkvmerge,
3700+
'--global-tags', self._tag_file,
3701+
]
36983702
if self.create_chapter_file(input_file):
3699-
opts = [self.mkvmerge,
3700-
'--global-tags', self._tag_file,
3701-
]
37023703
if len(self._list) > 1:
37033704
opts.extend([
37043705
'--chapters', self._chapters_file,
37053706
])
3706-
t_dir_dir = os.path.dirname(self._output_file)
3707-
for n in (os.path.join(t_dir_dir, 'recording.png'), \
3708-
os.path.join(t_dir_dir, 'pyradio.png')):
3709-
logger.error('looking for: "{}"'.format(n))
3710-
if os.path.exists(n):
3711-
cover_file = n
3712-
break
3713-
if cover_file:
3714-
opts.extend([
3715-
'--attachment-mime-type', 'image/png',
3716-
'--attachment-name', 'cover',
3717-
'--attach-file', cover_file
3718-
])
3707+
t_dir_dir = os.path.dirname(self._tag_file)
3708+
cover_file = None
3709+
for n in (os.path.join(t_dir_dir, 'user-recording.png'), \
3710+
os.path.join(t_dir_dir, 'recording.png')):
3711+
if logger.isEnabledFor(logging.DEBUG):
3712+
logger.debug('cover file is: "{}"'.format(n))
3713+
if os.path.exists(n):
3714+
cover_file = n
3715+
break
3716+
if cover_file:
37193717
opts.extend([
3720-
'-o', self._output_file,
3721-
self._mkv_file
3718+
'--attachment-mime-type', 'image/png',
3719+
'--attachment-name', 'cover',
3720+
'--attach-file', cover_file
37223721
])
3723-
if logger.isEnabledFor(logging.DEBUG):
3724-
logger.debug('merge options = {}'.format(opts))
3725-
p = subprocess.Popen(
3726-
opts, shell=False,
3727-
stdout=subprocess.PIPE,
3728-
stdin=subprocess.PIPE,
3729-
stderr=subprocess.PIPE
3730-
)
3731-
outs, err = p.communicate()
3732-
# logger.error('outs = "{0}", err = "{1}"'.format(outs, err))
3733-
if p.returncode == 0:
3734-
if logger.isEnabledFor(logging.INFO):
3735-
logger.info('MKV merge successful!')
3736-
for n in self._chapters_file, self._tag_file, self._mkv_file:
3737-
try:
3738-
os.remove(n)
3739-
except:
3740-
pass
3741-
return True
3742-
else:
3743-
if logger.isEnabledFor(logging.ERROR):
3744-
logger.error('MKV merge failed!')
3745-
return False
3722+
opts.extend([
3723+
'-o', self._output_file,
3724+
self._mkv_file
3725+
])
3726+
if logger.isEnabledFor(logging.DEBUG):
3727+
logger.debug('merge options = {}'.format(opts))
3728+
p = subprocess.Popen(
3729+
opts, shell=False,
3730+
stdout=subprocess.PIPE,
3731+
stdin=subprocess.PIPE,
3732+
stderr=subprocess.PIPE
3733+
)
3734+
outs, err = p.communicate()
3735+
# logger.error('outs = "{0}", err = "{1}"'.format(outs, err))
3736+
if p.returncode == 0:
3737+
if logger.isEnabledFor(logging.INFO):
3738+
logger.info('MKV merge successful!')
3739+
for n in self._chapters_file, self._tag_file, self._mkv_file:
3740+
try:
3741+
os.remove(n)
3742+
except:
3743+
pass
3744+
return True
3745+
else:
3746+
if logger.isEnabledFor(logging.ERROR):
3747+
logger.error('MKV merge failed with error:\n{}'.format(err))
3748+
return False
37463749

37473750
def create_chapter_file(self, input_file):
37483751
if not input_file:
3752+
if logger.isEnabledFor(logging.ERROR):
3753+
logger.error('input file not found!!!')
37493754
return False
37503755
# logger.error('HAS_MKVTOOLNIX = {}'.format(self.HAS_MKVTOOLNIX))
37513756
# logger.error('input_file = "{}"'.format(input_file))
@@ -3754,7 +3759,6 @@ def create_chapter_file(self, input_file):
37543759
# input_file.endswith('.mkv'):
37553760
self._mkv_file = input_file
37563761
self._chapters_file = input_file[:-4] + '-chapters.txt'
3757-
self._tag_file = input_file[:-4] + '.xml'
37583762
self._output_file = os.path.join(
37593763
self._output_dir,
37603764
os.path.basename(self._mkv_file)

0 commit comments

Comments
 (0)