Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CRITICAL] All history lost #18

Closed
biggestsonicfan opened this issue Nov 2, 2022 · 4 comments
Closed

[CRITICAL] All history lost #18

biggestsonicfan opened this issue Nov 2, 2022 · 4 comments
Labels
question Further information is requested

Comments

@biggestsonicfan
Copy link

biggestsonicfan commented Nov 2, 2022

I rely on the history to go back in time to see where I last left off when saving my images... my history somehow was erased... I don't know what to do...

EDIT: Oh my god I think I was having problems with Firefox not displaying images so I cleared cookies and data... fuck I didn't think that would clear the twitter-click-and-save data... shit...

EDIT2: Can a python script run through files saved that match the filename save type to recreate an import file?! This is really important!

@biggestsonicfan
Copy link
Author

biggestsonicfan commented Nov 2, 2022

I wrote a script which can recreate an import json file from existing filenames:

import os
import shutil
import json

def parse_vid_tweet(path):
    startid = path.find("—", path.find("—")+1)+1
    endid = path.find("—", startid)
    return path[startid:endid]

def parse_img_tweet(path):
    startid = path.rfind("—")+1
    endid = path.rfind(".")
    return path[startid:endid]
        

image_dirs = ['put your directories here']

#if you have an existing backup, import it
with open('location of old json', 'r') as openfile:
    json_object = json.load(openfile)
    images = json_object['ujs-twitter-downloaded-images-names'].replace("\"", "").replace("[", "").replace("]", "").split(",")
    videos = json_object['ujs-twitter-downloaded-video-tweet-ids'].replace("\"", "").replace("[", "").replace("]", "").split(",")
    
    for directory in image_dirs:
        scan_dirs = os.listdir(directory)
        for path in scan_dirs:
            if "[twitter]" in path:
                if path.endswith('.mp4'):
                    temp_vid = parse_vid_tweet(path)
                    if temp_vid not in videos:
                        videos.append(temp_vid)
                else:
                    temp_img = parse_img_tweet(path)
                    if temp_img not in images:
                        images.append(temp_img)
                        
    image_list = "["
    for img in images:
        if img != images[-1]:
            image_list += '"' + img + '",'
        else:
            image_list += '"' + img + '"]'

    json_object.update({'ujs-twitter-downloaded-images-names':image_list})

    video_list = "["
    for vid in videos:
        if vid != videos[-1]:
            video_list += '"' + vid + '",'
        else:
            video_list += '"' + vid + '"]'
            
    json_object.update({'ujs-twitter-downloaded-video-tweet-ids':video_list})

    with open('output of new json file', "w") as outfile:
        json.dump(json_object, outfile)
        

@biggestsonicfan
Copy link
Author

I guess this just wraps around back to #12

@AlttiRi
Copy link
Owner

AlttiRi commented Nov 2, 2022

It's possible to do if you did not change filenames.
Since filenames include the all almost all necessary information (except a video number — it's required if a tweet includes multiple videos #15).

@AlttiRi
Copy link
Owner

AlttiRi commented Nov 3, 2022

Here is my script for it

let imageNames = [];
let videoTweetIds = [];

let twFiles = folder.flat().filter(entry => {
    if (entry.type !== "folder" && entry.name.startsWith("[twitter] ")) { // [note] background images start with "[twitter][bg]"
        return true;
    }
});
for (const item of twFiles) {
    // skip .html files produced by gallery-dl
    if (!item.name.match(/\.(jpg|mp4|png)/)) {
        continue;
    }
    const {author, id, filename, ext} = (item.name.match(/\[twitter\] (?<author>.+)(?<date>\d{4}\.\d\d\.\d\d)(?<id>\d+)(?<filename>.+)\.(?<ext>.+)/)?.groups || console.log(item.name));

    // skip images downloaded by gallery-dl
    if (item.parent.name === `[twitter] ${author}` /* && item.parent.parent.name === "[gallery-dl]" */) {
        continue;
    }

    if (ext === "mp4") {
        videoTweetIds.push(id);
    } else {
        imageNames.push(filename);
    }
}

let exportObject = {
    "ujs-twitter-downloaded-images-names": [...new Set(imageNames)],
    "ujs-twitter-downloaded-video-tweet-ids": [...new Set(videoTweetIds)],
};
downloadBlob(new Blob([JSON.stringify(exportObject)]), "ujs-tw-cas-recreated-history-export.json");
function downloadBlob(blob, name, url) {
    const anchor = document.createElement("a");
    anchor.setAttribute("download", name || "");
    const blobUrl = URL.createObjectURL(blob);
    anchor.href = blobUrl + (url ? ("#" + url) : "");
    anchor.click();
    setTimeout(() => URL.revokeObjectURL(blobUrl), 8000);
}

to run in the console on https://alttiri.github.io/file-manager-snapshot-explorer/.

But first you need to create a snapshot(s) of your download/archive directory(-ies) with the scanner (zz-dir-scanner.mjs):
See: https://github.com/AlttiRi/file-manager-snapshot-explorer#how-to-use

and drag'n'drop it/them in the site.

See also: https://github.com/AlttiRi/file-manager-snapshot-explorer#static-site


Then use the import code from here #12 (comment)


BTW, you can highlight the code with ```python


Note: the script was update 2022.11.25 a bit (new JSON output format).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants