import { AcceptedZipSources, ConstructibleArchives } from "./reading/StreamArchive"; import UserData from "./user/UserData"; import { DirectMessage } from "./types/GDPRDMs"; import { PartialTweet, PartialTweetMediaEntity } from "./types/ClassicTweets"; import { MediaGDPREntity } from "./types/GDPRTweets"; export type ArchiveDMImagesFormation = "none" | "inside" | "zipped"; type ExistingArchives = "dm_single" | "dm_group" | "tweet" | "moment" | "profile"; export declare enum MediaArchiveType { SingleDM = "single-dm", GroupDM = "group-dm", Moment = "moment", Tweet = "tweet", Profile = "profile" } export declare class MediaArchive { protected archive: ConstructibleArchives; /** * Contains associations with internal `typeName` to `SingleMediaArchive` instances. */ protected folders_to_archive: { [typeName: string]: SingleMediaArchive; }; /** * User defined media types, associated to folders. */ protected custom_folders: { [typeName: string]: string[]; }; protected static readonly DM_SINGLE_FOLDER: string[]; protected static readonly DM_GROUP_FOLDER: string[]; protected static readonly TWEET_FOLDER: string[]; protected static readonly PROFILE_FOLDER = "profile_media"; protected static readonly MOMENT_FOLDER = "moments_media"; protected _store_type: ArchiveDMImagesFormation; constructor(archive: ConstructibleArchives); /** * Get a media from a specific media type. * * @param from Media archive type * @param name Filename (exact filename required) * @param as_array_buffer True if return type is ArrayBuffer. Otherwise, Blob will be used. * By default, returns ArrayBuffer on Node.js and Blob when available. * * ```ts * // For parameter {from}, you can use `MediaArchiveType` enum. * import { MediaArchiveType } from 'twitter-archive-reader'; * * const my_media = archive.medias.get(MediaArchiveType.SingleDM, "xxx.jpg", true) as Promise; * ``` */ get(from: MediaArchiveType | string, name: string, as_array_buffer?: T): Promise; /** * List files available on a specific media archive. * * @param of_archive Media archive */ list(of_archive: MediaArchiveType | string): Promise; protected getArchiveType(archive: string): string; protected getFolderOfType(archive: string): string[] | "profile_media" | "moments_media"; /** * Return all the images of a direct message, as blob or array buffer. * * If the message does not exists or the DM archive is not loaded / available, * return an empty array. * * Otherwise, return a array of `Blob` / `ArrayBuffer` * * @param direct_message Direct message object * @param as_array_buffer Return an `ArrayBuffer` array, instead of a `Blob` array */ ofDm(direct_message: DirectMessage, as_array_buffer?: T): Promise; /** * Extract the related media file to a URL present in the `mediaUrls` array of a Direct Message. */ fromDmMediaUrl(url: string, is_group?: boolean, as_array_buffer?: T): Promise; /** * Get all the medias related to a tweet. */ ofTweet(tweet: PartialTweet, as_array_buffer?: T): Promise; /** * Extract related tweet video or picture from a media entity. * * ```ts * const tweet = archive.tweets.all[0]; * * if (tweet.extended_entities || tweet.entities) { * // Always try to use extended entities instead of classic entities * const m_entities = (tweet.extended_entities || tweet.entities).media; * * if (m_entities && m_entities.length) { * const media_file = archive.medias.fromTweetMediaEntity(m_entities[0]); * } * } * ``` * * @throws If not valid media found, promise is rejected. */ fromTweetMediaEntity(media_entity: MediaGDPREntity | PartialTweetMediaEntity, as_array_buffer?: T): Promise; /** * Get the profile banner of given user. * * The first parameter should generally be `archive.user`. * * If user has no banner, this method returns `Promise`. */ getProfileBannerOf(user: UserData, as_array_buffer?: T): Promise; /** * Get the profile picture of given user. * * The first parameter should generally be `archive.user`. * * If user has no profile picture, this method returns `Promise`. */ getProfilePictureOf(user: UserData, as_array_buffer?: T): Promise; /** * Extract a moment header image from GDPR archive (exact filename required). * * In order to have tweets medias inside the moments (duplicated by Twitter in the archive, use `.ofTweet(tweet)`). * * Shortcut of `.get(MediaArchiveType.Moment, name, as_array_buffer)`, prefer using this instead. * * @param name Media filename */ fromMomentDirectory(name: string, as_array_buffer?: T): Promise; get is_medias_zipped(): boolean; get has_medias(): boolean; get is_zip_loaded(): boolean; releaseZip(): void; /** * Manually set the archive used for a media type. * * The specified {mediaType} can be a reference to a `MediaArchiveType` enum, or a custom media type * registered with `.registerMediaFolder()` method. * * ```ts * import { MediaArchiveType } from 'twitter-archive-reader'; * * // Accepted types are the same as accepted for `TwitterArchive` constructor * const my_tweet_media_archive = "tweet_media.zip"; * * // Load this archive instead of base one * await archive.medias.loadArchive({ * [MediaArchiveType.Tweet]: my_tweet_media_archive * }); * ``` */ loadArchive(parts: { [mediaType: string]: AcceptedZipSources | Promise; }): Promise; protected initOrAwaitArchive(archive_type: ExistingArchives | string, init_folder: string | string[]): Promise; /** * If the archive has a custom media folder, you can specify it here. * * @param type_name Refers to used name to access this folder, take care of not using one of the `MediaArchiveType` enum. * When you use `.get()` and `.list()`, use this {type_name} as first parameter of those methods. * * @param folder Folder name in the archive. * @param alternative_names Alternate folder names if the {folder} does not exists in the archive. */ registerMediaFolder(type_name: string, folder: string, ...alternative_names: string[]): void; protected static autoDetectStoreType(archive: ConstructibleArchives): ArchiveDMImagesFormation; } export default MediaArchive; export declare class SingleMediaArchive { protected _archive: ConstructibleArchives | undefined; protected _ready: Promise; protected _ok: boolean; constructor(full_archive: ConstructibleArchives | null, dir_name: string | string[]); get archive(): ConstructibleArchives; get ok(): boolean; get ready(): Promise; get files(): string[]; file(name: string, as_array_buffer?: T): Promise; protected detectMimeType(name: string): "" | "text/html" | "video/mp4" | "image/jpeg" | "image/png" | "image/gif" | "video/webm" | "image/webp" | "image/bitmap" | "video/ogg" | "image/x-icon" | "audio/mp3" | "text/plain" | "application/json" | "text/javascript"; sideload(archive: ConstructibleArchives): Promise; protected static autoDetectIfArrayBuffer(): boolean; }