Add debug info
This commit is contained in:
parent
41c24a9d60
commit
69622aff6a
1 changed files with 45 additions and 8 deletions
|
@ -54,34 +54,71 @@ class GetPeertubeVideos:
|
||||||
self._process_item(item)
|
self._process_item(item)
|
||||||
|
|
||||||
def _process_item(self, item):
|
def _process_item(self, item):
|
||||||
|
self._log.debug(
|
||||||
|
"Processing item: %s",
|
||||||
|
item
|
||||||
|
)
|
||||||
if item['id'] not in self.downloaded_items:
|
if item['id'] not in self.downloaded_items:
|
||||||
selected={
|
selected={
|
||||||
'size_in_bytes': 0,
|
'size_in_bytes': 0,
|
||||||
}
|
}
|
||||||
|
self._log.debug(
|
||||||
|
"%s attachments (videos) for this item",
|
||||||
|
len(item['attachments'])
|
||||||
|
)
|
||||||
for attachment in item['attachments']:
|
for attachment in item['attachments']:
|
||||||
if attachment['size_in_bytes'] > selected['size_in_bytes']:
|
if attachment['size_in_bytes'] > selected['size_in_bytes']:
|
||||||
selected = attachment
|
selected = attachment
|
||||||
print(
|
if 'url' not in selected:
|
||||||
f"Adding torrent '{selected['url']}' for video '{selected['title']}'..."
|
self._log.error(
|
||||||
|
"No attachments with size bigger than 0. No torrent to add."
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
self._log.info(
|
||||||
|
"Adding torrent '%s' for video '%s'...",
|
||||||
|
selected['url'],
|
||||||
|
selected['title']
|
||||||
)
|
)
|
||||||
result_torrent = self.session.get(selected['url'])
|
result_torrent = self.session.get(selected['url'])
|
||||||
torrent_bytes = result_torrent.content
|
torrent_bytes = result_torrent.content
|
||||||
self.trans.add_torrent(
|
self._log.debug(
|
||||||
|
"Torrent file downloaded with %s bytes of data",
|
||||||
|
len(torrent_bytes)
|
||||||
|
)
|
||||||
|
result_add = self.trans.add_torrent(
|
||||||
torrent_bytes,
|
torrent_bytes,
|
||||||
download_dir=self.config['download_dir'], labels=item['tags']
|
download_dir=self.config['download_dir'], labels=item['tags']
|
||||||
)
|
)
|
||||||
|
self._log.debug(
|
||||||
|
"Torrent added to Transmission with result: %s",
|
||||||
|
result_add
|
||||||
|
)
|
||||||
self.downloaded_items.append(item['id'])
|
self.downloaded_items.append(item['id'])
|
||||||
with open(self.config['downloaded_database'], 'w', encoding='utf-8') as db_file:
|
self._write_downloaded_items()
|
||||||
for item in self.downloaded_items:
|
else:
|
||||||
db_file.write(f"{item}\n")
|
self._log.debug(
|
||||||
|
"Item already downloaded, skipping."
|
||||||
|
)
|
||||||
|
|
||||||
|
def _write_downloaded_items(self):
|
||||||
|
with open(self.config['downloaded_database'], 'w', encoding='utf-8') as db_file:
|
||||||
|
for download_item in self.downloaded_items:
|
||||||
|
db_file.write(f"{download_item}\n")
|
||||||
|
|
||||||
def _get_downloaded_items(self):
|
def _get_downloaded_items(self):
|
||||||
if os.path.exists(self.config['downloaded_database']):
|
if os.path.exists(self.config['downloaded_database']):
|
||||||
|
self._log.debug(
|
||||||
|
"Reading already downloaded items from '%s'...",
|
||||||
|
self.config['downloaded_database']
|
||||||
|
)
|
||||||
with open(self.config['downloaded_database'], 'r', encoding='utf-8') as db_file:
|
with open(self.config['downloaded_database'], 'r', encoding='utf-8') as db_file:
|
||||||
self.downloaded_items = db_file.read().split('\n')
|
self.downloaded_items = db_file.read().split('\n')
|
||||||
else:
|
else:
|
||||||
with open(self.config['downloaded_database'], 'w', encoding='utf-8') as db_file:
|
self._log.debug(
|
||||||
db_file.write(self.downloaded_items)
|
"Initializing downloaded items database '%s'...",
|
||||||
|
self.config['downloaded_database']
|
||||||
|
)
|
||||||
|
self._write_downloaded_items()
|
||||||
|
|
||||||
def _init_log(self):
|
def _init_log(self):
|
||||||
''' Initialize log object '''
|
''' Initialize log object '''
|
||||||
|
|
Loading…
Reference in a new issue