Skip to content

Instantly share code, notes, and snippets.

@tiegz
Last active October 13, 2020 00:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tiegz/4741547 to your computer and use it in GitHub Desktop.
Save tiegz/4741547 to your computer and use it in GitHub Desktop.
Import VUDU rental history into a CSV format readable by Letterboxd.
// Run this in the browser bar: var el = document.createElement("script"); el.src=URL; document.body.appendChild(el);
//
// 1. Login to http://my.vudu.com
// 2. Open the Inspector (cmd-ctrl-I on OSX), and un this script (if popups are blocked, temporarily unblock popups from Vudu in your browser)
// 3. Grab the downloaded CSV file (probably with a random name), and load at http://letterboxd.com/import
//
// How it works: this script is inserted into the Vudu page via a bookmarklet, grabs your session key, and
// makes a call to Vudu's api. Then it parses the response and creates a CSV, which it then opens in a page as a data-uri.
//
// Copyright 2013-2020. Code released under the MIT license.
// Authors: Tieg Zaharia, Tyrel Souza
var csv = [["LetterboxdURI", "tmdbID", "imdbID", "Title", "Year", "Directors", "WatchedDate", "CreatedDate", "Rating", "Rating10", "Tags", "Review"].join(",")];
var offset = 0;
const perPage = 100;
function buildCSV(data) {
if (data.fundTransactionGroup) {
for (var g = 0; g < data.fundTransactionGroup.length; g++) {
transactions = data.fundTransactionGroup[g].fundTransactions[0].fundTransaction;
for (var t = 0; t < transactions.length; t++) {
if (transactions[t].purchase) {
transaction = transactions[t];
content = transaction.purchase[0].content[0];
console.log(content.title[0], transaction, transactions)
csv.push([
"", // "LetterboxdURI"
"", // "tmdbID"
"", // "imdbID"
content.title[0].replace(/'/, "\\'"), // "Title"
content.releaseTime[0].substr(0, 4), // "Year"
"", // "Directors"
transaction.purchase[0].completedTime[0].substr(0, 10), // "WatchedDate"
transaction.purchase[0].purchaseTime[0].substr(0, 10), // "CreatedDate"
"", // "Rating"
"", // "Rating10"
"", // "Tags"
"", // "Review"
].join(","));
}
}
}
}
if (data.moreBelow[0] === 'true') {
offset = offset + perPage;
requestHistory()
} else {
csv = csv.join('\n');
var uri = 'data:application/csv;name=vudu_history.csv;charset=UTF-8,' + encodeURIComponent(csv);
var win = window.open(uri, "VUDUHistory", { "titlebar": "yes" });
win.title = "VUDU History";
alert("CSV opened, please allow popups for VUDU.com if your browswer is asking right now...");
win.alert = "Import the downloaded file into letterboxd.com/import";
win.focus();
}
}
var weakSessionKey;
var userId;
try {
for (i in localStorage) {
if (i.match(/weakSessionKey$/)) {
weakSessionKey = localStorage.getItem(i)
}
if (i.match(/userID$/)) {
userId = localStorage.getItem(i)
}
}
} catch (e) {}
function requestHistory () {
if (offset > 5000) {
alert("Something went wrong! Canceling. Offset is at ", offset);
return;
}
console.log('Getting ' + perPage + ' per page at offset ', offset);
if (weakSessionKey === undefined || userId === undefined) {
alert('Login and try again!');
} else {
var url = accountConfig.secureApi;
url += "?format=application/json";
url += "&callback=buildCSV";
url += "&_type=fundTransactionGroupSearch";
url += "&accountId=" + userId;
url += "&count=" + perPage;
url += "&followup=purchases";
url += "&followup=totalCount";
url += "&offset=" + offset;
url += "&sessionKey=" + weakSessionKey;
url += "&sortBy=-transactionTime";
url += "&transactionState=pending";
url += "&transactionState=reserved";
url += "&transactionState=accepted";
url += "&transactionState=canceledAfterClose";
}
var script_element = document.createElement('script');
script_element.type = 'text/javascript';
script_element.async = true;
script_element.src = url;
document.body.appendChild(script_element);
}
requestHistory();
@kemajor
Copy link

kemajor commented Oct 4, 2020

Thank you very much. I really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment