Grayjay

0 readers
0 users here now

Another unofficial community for the media aggregator Grayjay.

Not related to !grayjay@lemm.ee

founded 4 months ago
MODERATORS
1
 
 

Grayjay itself:

Desktop version:

Sources for Grayjay - both FUTO and third parties' plugins:

PeerTube instances plugin generator:

Script for converting desktop playlist files into sharable playlist files (for importing playlists on Android), courtesy of Grok:

import sys
import copy
import re
import os

def clean_video_data(video):
    # Create a deep copy to avoid modifying the original
    video_copy = copy.deepcopy(video)
    # Remove unwanted fields from video
    video_copy.pop("ContentType", None)
    video_copy.pop("IsLive", None)
    video_copy.pop("IsDetailObject", None)
    # Remove unwanted fields from ID and Author.ID
    video_copy["ID"].pop("ClaimType", None)
    video_copy["ID"].pop("ClaimFieldType", None)
    video_copy["Author"]["ID"].pop("ClaimType", None)
    video_copy["Author"]["ID"].pop("ClaimFieldType", None)
    return video_copy

def sanitize_filename(name):
    # Remove or replace invalid filename characters
    return re.sub(r'[^\w\-_\.]', '_', name)

def convert_json(input_json_str):
    try:
        # Parse JSON string
        data = json.loads(input_json_str)
        
        # Extract playlist name for filename
        playlist_name = data.get('Name', 'default_playlist')
        
        # Initialize output array
        output = ["@/Playlist", f"{data['Name']}
{data['Id']}"] # Add video URLs output.extend(video["Url"] for video in data["Videos"]) # Clean video data for cache cleaned_videos = [clean_video_data(video) for video in data["Videos"]] # Create cache string cache_str = f"__CACHE:{json.dumps({'Videos': cleaned_videos}, separators=(',', ':'))}" output.append(cache_str) return playlist_name, output except json.JSONDecodeError: print("Error: Invalid JSON input") return None, None except KeyError as e: print(f"Error: Missing key {e}") return None, None def main(): # Check if input file is provided if len(sys.argv) != 2: print("Usage: python3 script.py input_file.txt") sys.exit(1) input_file = sys.argv[1] try: # Read JSON from input file with open(input_file, 'r', encoding='utf-8') as f: input_json_str = f.read() # Convert JSON playlist_name, result = convert_json(input_json_str) if result is None: sys.exit(1) # Sanitize playlist name for filename safe_playlist_name = sanitize_filename(playlist_name) output_file = f"{safe_playlist_name}.json" # Write output to file with open(output_file, 'w', encoding='utf-8') as f: json.dump(result, f, indent=2, ensure_ascii=False) print(f"Output written to {output_file}") except FileNotFoundError: print(f"Error: Input file '{input_file}' not found") sys.exit(1) except PermissionError: print(f"Error: Unable to write to output file '{output_file}'") sys.exit(1) except Exception as e: print(f"Unexpected error: {e}") sys.exit(1) if __name__ == "__main__": main() :::
Script usage: - Save the script above; name doesn't matter much, but for the sake of explanation, I'll consider the name as `grayjay_script.py` - Go to where you extracted Grayjay and inside the playlists folder, e.g.: $HOME/Grayjay/Grayjay.Desktop-linux-x64-v9/playlists/ - [Optional] Make a backup of the playlist - If more than one file is present, open each in a text editor of your choice and look for the name field to confirm wether it's the file you need or not. - [Optional] Copy the script and the playlist file into a same folder - Run the script, e.g. on Linux/Mingwin/WSL/Termux: `python3 /path/to/grayjay_script.py /path/to/the/playlist/file` - Or if the files are in the same folder: `python3 grayjay_script.py playlist_file` Where `playlist_file` is to be changed for the playlist file's name (including extension, though it shouldn't have). - A .json file will be generated. Send it to the Android device where your Grayjay install is. - Some programs on Android can open the file straight to Grayjay. If yours can't, try using options such as the "Open With..." browsers usually have, or try other programs if possible. - Grayjay will ask if you want to import the playlist. It doesn't seem to have visual updates on progress, so wait until it's done.