2019-01-31 18:32:52 +01:00
|
|
|
import os
|
|
|
|
import binascii
|
|
|
|
import sqlite3
|
2019-06-21 03:02:58 +02:00
|
|
|
from lbry.conf import Config
|
2019-01-31 18:32:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
conf = Config()
|
|
|
|
db = sqlite3.connect(os.path.join(conf.data_dir, 'lbrynet.sqlite'))
|
|
|
|
cur = db.cursor()
|
|
|
|
files = cur.execute("select stream_hash, file_name, download_directory from file").fetchall()
|
|
|
|
update = {}
|
|
|
|
for stream_hash, file_name, download_directory in files:
|
|
|
|
try:
|
|
|
|
binascii.unhexlify(file_name)
|
|
|
|
except binascii.Error:
|
|
|
|
try:
|
|
|
|
binascii.unhexlify(download_directory)
|
|
|
|
except binascii.Error:
|
|
|
|
update[stream_hash] = (
|
|
|
|
binascii.hexlify(file_name.encode()).decode(), binascii.hexlify(download_directory.encode()).decode()
|
|
|
|
)
|
|
|
|
if update:
|
|
|
|
print(f"repair {len(update)} streams")
|
|
|
|
for stream_hash, (file_name, download_directory) in update.items():
|
|
|
|
cur.execute('update file set file_name=?, download_directory=? where stream_hash=?',
|
|
|
|
(file_name, download_directory, stream_hash))
|
|
|
|
db.commit()
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|